Skip to content

Commit

Permalink
Adds example for service create with annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
navidshaikh committed Oct 4, 2019
1 parent fa5001b commit 74a0167
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
3 changes: 3 additions & 0 deletions docs/cmd/kn_service_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions pkg/kn/commands/service/configuration_edit_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,20 +267,17 @@ func (p *ConfigurationEditFlags) Apply(
if err != nil {
return errors.Wrap(err, "Invalid --annotation")
}

annotationsToRemove := []string{}
for key := range annotationsMap {
if strings.HasSuffix(key, "-") {
annotationsToRemove = append(annotationsToRemove, key[:len(key)-1])
delete(annotationsMap, key)
}
}

err = servinglib.UpdateAnnotations(service, template, annotationsMap, annotationsToRemove)
if err != nil {
return err
}

}

if cmd.Flags().Changed("service-account") {
Expand Down
22 changes: 13 additions & 9 deletions pkg/kn/commands/service/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
20 changes: 11 additions & 9 deletions pkg/kn/commands/service/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.")
Expand Down

0 comments on commit 74a0167

Please sign in to comment.