@@ -15,6 +15,7 @@ import (
1515 "github.com/spf13/cobra"
1616 "k8s.io/apimachinery/pkg/api/resource"
1717 "knative.dev/client/pkg/util"
18+ "knative.dev/func/pkg/deployer"
1819
1920 "knative.dev/func/pkg/builders"
2021 "knative.dev/func/pkg/config"
@@ -131,7 +132,7 @@ EXAMPLES
131132 PreRunE : bindEnv ("build" , "build-timestamp" , "builder" , "builder-image" ,
132133 "base-image" , "confirm" , "domain" , "env" , "git-branch" , "git-dir" ,
133134 "git-url" , "image" , "namespace" , "path" , "platform" , "push" , "pvc-size" ,
134- "service-account" , "registry" , "registry-insecure" , "remote" ,
135+ "service-account" , "deploy-type" , " registry" , "registry-insecure" , "remote" ,
135136 "username" , "password" , "token" , "verbose" , "remote-storage-class" ),
136137 RunE : func (cmd * cobra.Command , args []string ) error {
137138 return runDeploy (cmd , newClient )
@@ -192,6 +193,8 @@ EXAMPLES
192193 "When triggering a remote deployment, set a custom volume size to allocate for the build operation ($FUNC_PVC_SIZE)" )
193194 cmd .Flags ().String ("service-account" , f .Deploy .ServiceAccountName ,
194195 "Service account to be used in the deployed function ($FUNC_SERVICE_ACCOUNT)" )
196+ cmd .Flags ().String ("deploy-type" , f .Deploy .DeployType ,
197+ fmt .Sprintf ("Type of deployment to use: '%s' for Knative Service (default) or '%s' for Kubernetes Deployment ($FUNC_DEPLOY_TYPE)" , deployer .KnativeDeployerName , deployer .KubernetesDeployerName ))
195198 // Static Flags:
196199 // Options which have static defaults only (not globally configurable nor
197200 // persisted with the function)
@@ -567,6 +570,9 @@ type deployConfig struct {
567570 //Service account to be used in deployed function
568571 ServiceAccountName string
569572
573+ // DeployType specifies the type of deployment: "knative" or "deployment"
574+ DeployType string
575+
570576 // Remote indicates the deployment (and possibly build) process are to
571577 // be triggered in a remote environment rather than run locally.
572578 Remote bool
@@ -600,6 +606,7 @@ func newDeployConfig(cmd *cobra.Command) deployConfig {
600606 PVCSize : viper .GetString ("pvc-size" ),
601607 Timestamp : viper .GetBool ("build-timestamp" ),
602608 ServiceAccountName : viper .GetString ("service-account" ),
609+ DeployType : viper .GetString ("deploy-type" ),
603610 }
604611 // NOTE: .Env should be viper.GetStringSlice, but this returns unparsed
605612 // results and appears to be an open issue since 2017:
@@ -634,6 +641,7 @@ func (c deployConfig) Configure(f fn.Function) (fn.Function, error) {
634641 f .Build .Git .Revision = c .GitBranch // TODO: should match; perhaps "refSpec"
635642 f .Build .RemoteStorageClass = c .RemoteStorageClass
636643 f .Deploy .ServiceAccountName = c .ServiceAccountName
644+ f .Deploy .DeployType = c .DeployType
637645 f .Local .Remote = c .Remote
638646
639647 // PVCSize
@@ -791,6 +799,34 @@ func (c deployConfig) Validate(cmd *cobra.Command) (err error) {
791799 return
792800}
793801
802+ // clientOptions returns client options specific to deploy, including the appropriate deployer
803+ func (c deployConfig ) clientOptions () ([]fn.Option , error ) {
804+ // Start with build config options
805+ o , err := c .buildConfig .clientOptions ()
806+ if err != nil {
807+ return o , err
808+ }
809+
810+ // Add the appropriate deployer based on deploy type
811+ deployType := c .DeployType
812+ if deployType == "" {
813+ deployType = deployer .KnativeDeployerName // default to knative for backwards compatibility
814+ }
815+
816+ var d fn.Deployer
817+ switch deployType {
818+ case deployer .KnativeDeployerName :
819+ d = newKnativeDeployer (c .Verbose )
820+ case deployer .KubernetesDeployerName :
821+ d = newK8sDeployer (c .Verbose )
822+ default :
823+ return o , fmt .Errorf ("unsupported deploy type: %s (supported: %s, %s)" , deployType , deployer .KnativeDeployerName , deployer .KubernetesDeployerName )
824+ }
825+
826+ o = append (o , fn .WithDeployer (d ))
827+ return o , nil
828+ }
829+
794830// printDeployMessages to the output. Non-error deployment messages.
795831func printDeployMessages (out io.Writer , f fn.Function ) {
796832 digest , err := isDigested (f .Image )
0 commit comments