Skip to content

Commit f0fa249

Browse files
committed
Add kubernetes deployment deployer
1 parent 5c51aa7 commit f0fa249

File tree

13 files changed

+1564
-1219
lines changed

13 files changed

+1564
-1219
lines changed

cmd/client.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"knative.dev/func/pkg/builders/buildpacks"
1010
"knative.dev/func/pkg/config"
1111
"knative.dev/func/pkg/creds"
12+
k8sdeployer "knative.dev/func/pkg/deployer/k8s"
13+
knativedeployer "knative.dev/func/pkg/deployer/knative"
1214
"knative.dev/func/pkg/docker"
1315
fn "knative.dev/func/pkg/functions"
1416
fnhttp "knative.dev/func/pkg/http"
@@ -58,7 +60,7 @@ func NewClient(cfg ClientConfig, options ...fn.Option) (*fn.Client, func()) {
5860
var (
5961
t = newTransport(cfg.InsecureSkipVerify) // may provide a custom impl which proxies
6062
c = newCredentialsProvider(config.Dir(), t) // for accessing registries
61-
d = newKnativeDeployer(cfg.Verbose)
63+
d = newKnativeDeployer(cfg.Verbose) // default deployer (can be overridden via options)
6264
pp = newTektonPipelinesProvider(c, cfg.Verbose)
6365
o = []fn.Option{ // standard (shared) options for all commands
6466
fn.WithVerbose(cfg.Verbose),
@@ -127,12 +129,21 @@ func newTektonPipelinesProvider(creds oci.CredentialsProvider, verbose bool) *te
127129
}
128130

129131
func newKnativeDeployer(verbose bool) fn.Deployer {
130-
options := []knative.DeployerOpt{
131-
knative.WithDeployerVerbose(verbose),
132-
knative.WithDeployerDecorator(deployDecorator{}),
132+
options := []knativedeployer.DeployerOpt{
133+
knativedeployer.WithDeployerVerbose(verbose),
134+
knativedeployer.WithDeployerDecorator(deployDecorator{}),
133135
}
134136

135-
return knative.NewDeployer(options...)
137+
return knativedeployer.NewDeployer(options...)
138+
}
139+
140+
func newK8sDeployer(verbose bool) fn.Deployer {
141+
options := []k8sdeployer.DeployerOpt{
142+
k8sdeployer.WithDeployerVerbose(verbose),
143+
k8sdeployer.WithDeployerDecorator(deployDecorator{}),
144+
}
145+
146+
return k8sdeployer.NewDeployer(options...)
136147
}
137148

138149
type deployDecorator struct {

cmd/deploy.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.
795831
func printDeployMessages(out io.Writer, f fn.Function) {
796832
digest, err := isDigested(f.Image)

0 commit comments

Comments
 (0)