From 74a016754f611d4c10f125a3a0299c42c4281932 Mon Sep 17 00:00:00 2001 From: Navid Shaikh Date: Tue, 1 Oct 2019 13:05:15 +0530 Subject: [PATCH] Adds example for service create with annotation --- docs/cmd/kn_service_create.md | 3 +++ .../service/configuration_edit_flags.go | 3 --- pkg/kn/commands/service/create.go | 22 +++++++++++-------- pkg/kn/commands/service/update.go | 20 +++++++++-------- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/docs/cmd/kn_service_create.md b/docs/cmd/kn_service_create.md index 88e4bffc72..e4e5bb865c 100644 --- a/docs/cmd/kn_service_create.md +++ b/docs/cmd/kn_service_create.md @@ -34,6 +34,9 @@ kn service create NAME --image IMAGE [flags] # (earlier configured resource requests and limits will be replaced with default) # (earlier configured environment variables will be cleared too if any) kn service create --force s1 --image dev.local/ns/image:v1 + + # Create a service with annotation + kn service create s1 --image dev.local/ns/image:v3 --annotation sidecar.istio.io/inject=false ``` ### Options diff --git a/pkg/kn/commands/service/configuration_edit_flags.go b/pkg/kn/commands/service/configuration_edit_flags.go index 45416d296c..72a3881cba 100644 --- a/pkg/kn/commands/service/configuration_edit_flags.go +++ b/pkg/kn/commands/service/configuration_edit_flags.go @@ -267,7 +267,6 @@ func (p *ConfigurationEditFlags) Apply( if err != nil { return errors.Wrap(err, "Invalid --annotation") } - annotationsToRemove := []string{} for key := range annotationsMap { if strings.HasSuffix(key, "-") { @@ -275,12 +274,10 @@ func (p *ConfigurationEditFlags) Apply( delete(annotationsMap, key) } } - err = servinglib.UpdateAnnotations(service, template, annotationsMap, annotationsToRemove) if err != nil { return err } - } if cmd.Flags().Changed("service-account") { diff --git a/pkg/kn/commands/service/create.go b/pkg/kn/commands/service/create.go index a04f7cd2e1..2cc010a630 100644 --- a/pkg/kn/commands/service/create.go +++ b/pkg/kn/commands/service/create.go @@ -33,14 +33,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func NewServiceCreateCommand(p *commands.KnParams) *cobra.Command { - var editFlags ConfigurationEditFlags - var waitFlags commands.WaitFlags - - serviceCreateCommand := &cobra.Command{ - Use: "create NAME --image IMAGE", - Short: "Create a service.", - Example: ` +var create_example = ` # Create a service 'mysvc' using image at dev.local/ns/image:latest kn service create mysvc --image dev.local/ns/image:latest @@ -60,8 +53,19 @@ func NewServiceCreateCommand(p *commands.KnParams) *cobra.Command { # Create or replace default resources of a service 's1' using --force flag # (earlier configured resource requests and limits will be replaced with default) # (earlier configured environment variables will be cleared too if any) - kn service create --force s1 --image dev.local/ns/image:v1`, + kn service create --force s1 --image dev.local/ns/image:v1 + + # Create a service with annotation + kn service create s1 --image dev.local/ns/image:v3 --annotation sidecar.istio.io/inject=false` +func NewServiceCreateCommand(p *commands.KnParams) *cobra.Command { + var editFlags ConfigurationEditFlags + var waitFlags commands.WaitFlags + + serviceCreateCommand := &cobra.Command{ + Use: "create NAME --image IMAGE", + Short: "Create a service.", + Example: create_example, RunE: func(cmd *cobra.Command, args []string) (err error) { if len(args) != 1 { return errors.New("'service create' requires the service name given as single argument") diff --git a/pkg/kn/commands/service/update.go b/pkg/kn/commands/service/update.go index 8922d8b64b..090c4f18b1 100644 --- a/pkg/kn/commands/service/update.go +++ b/pkg/kn/commands/service/update.go @@ -28,14 +28,7 @@ import ( "knative.dev/serving/pkg/apis/serving/v1alpha1" ) -func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command { - var editFlags ConfigurationEditFlags - var waitFlags commands.WaitFlags - var trafficFlags flags.Traffic - serviceUpdateCommand := &cobra.Command{ - Use: "update NAME [flags]", - Short: "Update a service.", - Example: ` +var update_example = ` # Updates a service 'svc' with new environment variables kn service update svc --env KEY1=VALUE1 --env KEY2=VALUE2 @@ -54,7 +47,16 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command { kn service update svc --untag testing --tag @latest=staging # Add tag 'test' to echo-v3 revision with 10% traffic and rest to latest ready revision of service - kn service update svc --tag echo-v3=test --traffic test=10,@latest=90`, + kn service update svc --tag echo-v3=test --traffic test=10,@latest=90` + +func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command { + var editFlags ConfigurationEditFlags + var waitFlags commands.WaitFlags + var trafficFlags flags.Traffic + serviceUpdateCommand := &cobra.Command{ + Use: "update NAME [flags]", + Short: "Update a service.", + Example: update_example, RunE: func(cmd *cobra.Command, args []string) (err error) { if len(args) != 1 { return errors.New("requires the service name.")