Skip to content

Commit

Permalink
loop over flag names
Browse files Browse the repository at this point in the history
  • Loading branch information
Daisy Guo committed Jul 23, 2020
1 parent 2066486 commit d564f49
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
39 changes: 21 additions & 18 deletions pkg/kn/commands/service/configuration_edit_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,27 @@ func (p *ConfigurationEditFlags) markFlagMakesRevision(f string) {

// addSharedFlags adds the flags common between create & update.
func (p *ConfigurationEditFlags) addSharedFlags(command *cobra.Command) {
p.PodSpecFlags.AddFlags(command.Flags())
p.markFlagMakesRevision("image")
p.markFlagMakesRevision("env")
p.markFlagMakesRevision("env-from")
p.markFlagMakesRevision("mount")
p.markFlagMakesRevision("volume")
p.markFlagMakesRevision("cmd")
p.markFlagMakesRevision("arg")
p.markFlagMakesRevision("limit")
p.markFlagMakesRevision("request")
p.markFlagMakesRevision("requests-cpu")
p.markFlagMakesRevision("requests-memory")
p.markFlagMakesRevision("limits-cpu")
p.markFlagMakesRevision("limits-memory")
p.markFlagMakesRevision("port")
p.markFlagMakesRevision("service-account")
p.markFlagMakesRevision("pull-secret")
p.markFlagMakesRevision("user")
flagNames := p.PodSpecFlags.AddFlags(command.Flags())
for _, name := range flagNames {
p.markFlagMakesRevision(name)
}
// p.markFlagMakesRevision("image")
// p.markFlagMakesRevision("env")
// p.markFlagMakesRevision("env-from")
// p.markFlagMakesRevision("mount")
// p.markFlagMakesRevision("volume")
// p.markFlagMakesRevision("cmd")
// p.markFlagMakesRevision("arg")
// p.markFlagMakesRevision("limit")
// p.markFlagMakesRevision("request")
// p.markFlagMakesRevision("requests-cpu")
// p.markFlagMakesRevision("requests-memory")
// p.markFlagMakesRevision("limits-cpu")
// p.markFlagMakesRevision("limits-memory")
// p.markFlagMakesRevision("port")
// p.markFlagMakesRevision("service-account")
// p.markFlagMakesRevision("pull-secret")
// p.markFlagMakesRevision("user")

command.Flags().IntVar(&p.MinScale, "min-scale", 0, "Minimal number of replicas.")
p.markFlagMakesRevision("min-scale")
Expand Down
23 changes: 22 additions & 1 deletion pkg/kn/flags/podspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,80 +65,101 @@ func (s *uniqueStringArg) Type() string {
func (s *uniqueStringArg) String() string { return string(*s) }

//AddFlags will add PodSpec related flags to FlagSet
func (p *PodSpecFlags) AddFlags(flagset *pflag.FlagSet) {
func (p *PodSpecFlags) AddFlags(flagset *pflag.FlagSet) []string {

flagNames := []string{}

flagset.VarP(&p.Image, "image", "", "Image to run.")
flagNames = append(flagNames, "image")

flagset.StringArrayVarP(&p.Env, "env", "e", []string{},
"Environment variable to set. NAME=value; you may provide this flag "+
"any number of times to set multiple environment variables. "+
"To unset, specify the environment variable name followed by a \"-\" (e.g., NAME-).")
flagNames = append(flagNames, "env")

flagset.StringArrayVarP(&p.EnvFrom, "env-from", "", []string{},
"Add environment variables from a ConfigMap (prefix cm: or config-map:) or a Secret (prefix secret:). "+
"Example: --env-from cm:myconfigmap or --env-from secret:mysecret. "+
"You can use this flag multiple times. "+
"To unset a ConfigMap/Secret reference, append \"-\" to the name, e.g. --env-from cm:myconfigmap-.")
flagNames = append(flagNames, "env-from")

flagset.StringArrayVarP(&p.Mount, "mount", "", []string{},
"Mount a ConfigMap (prefix cm: or config-map:), a Secret (prefix secret: or sc:), or an existing Volume (without any prefix) on the specified directory. "+
"Example: --mount /mydir=cm:myconfigmap, --mount /mydir=secret:mysecret, or --mount /mydir=myvolume. "+
"When a configmap or a secret is specified, a corresponding volume is automatically generated. "+
"You can use this flag multiple times. "+
"For unmounting a directory, append \"-\", e.g. --mount /mydir-, which also removes any auto-generated volume.")
flagNames = append(flagNames, "mount")

flagset.StringArrayVarP(&p.Volume, "volume", "", []string{},
"Add a volume from a ConfigMap (prefix cm: or config-map:) or a Secret (prefix secret: or sc:). "+
"Example: --volume myvolume=cm:myconfigmap or --volume myvolume=secret:mysecret. "+
"You can use this flag multiple times. "+
"To unset a ConfigMap/Secret reference, append \"-\" to the name, e.g. --volume myvolume-.")
flagNames = append(flagNames, "volume")

flagset.StringVarP(&p.Command, "cmd", "", "",
"Specify command to be used as entrypoint instead of default one. "+
"Example: --cmd /app/start or --cmd /app/start --arg myArg to pass aditional arguments.")
flagNames = append(flagNames, "cmd")

flagset.StringArrayVarP(&p.Arg, "arg", "", []string{},
"Add argument to the container command. "+
"Example: --arg myArg1 --arg --myArg2 --arg myArg3=3. "+
"You can use this flag multiple times.")
flagNames = append(flagNames, "arg")

flagset.StringSliceVar(&p.Resources.Limits,
"limit",
nil,
"The resource requirement limits for this Service. For example, 'cpu=100m,memory=256Mi'. "+
"You can use this flag multiple times. "+
"To unset a resource limit, append \"-\" to the resource name, e.g. '--limit memory-'.")
flagNames = append(flagNames, "limit")

flagset.StringSliceVar(&p.Resources.Requests,
"request",
nil,
"The resource requirement requests for this Service. For example, 'cpu=100m,memory=256Mi'. "+
"You can use this flag multiple times. "+
"To unset a resource request, append \"-\" to the resource name, e.g. '--request cpu-'.")
flagNames = append(flagNames, "request")

flagset.StringVar(&p.RequestsFlags.CPU, "requests-cpu", "",
"DEPRECATED: please use --request instead. The requested CPU (e.g., 250m).")
flagNames = append(flagNames, "requests-cpu")

flagset.StringVar(&p.RequestsFlags.Memory, "requests-memory", "",
"DEPRECATED: please use --request instead. The requested memory (e.g., 64Mi).")
flagNames = append(flagNames, "requests-memory")

// TODO: Flag marked deprecated in release v0.15.0, remove in release v0.18.0
flagset.StringVar(&p.LimitsFlags.CPU, "limits-cpu", "",
"DEPRECATED: please use --limit instead. The limits on the requested CPU (e.g., 1000m).")
flagNames = append(flagNames, "limits-cpu")

// TODO: Flag marked deprecated in release v0.15.0, remove in release v0.18.0
flagset.StringVar(&p.LimitsFlags.Memory, "limits-memory", "",
"DEPRECATED: please use --limit instead. The limits on the requested memory (e.g., 1024Mi).")
flagNames = append(flagNames, "limits-memory")

flagset.StringVarP(&p.Port, "port", "p", "", "The port where application listens on, in the format 'NAME:PORT', where 'NAME' is optional. Examples: '--port h2c:8080' , '--port 8080'.")
flagNames = append(flagNames, "port")

flagset.StringVar(&p.ServiceAccountName,
"service-account",
"",
"Service account name to set. An empty argument (\"\") clears the service account. The referenced service account must exist in the service's namespace.")
flagNames = append(flagNames, "service-account")

flagset.StringVar(&p.ImagePullSecrets,
"pull-secret",
"",
"Image pull secret to set. An empty argument (\"\") clears the pull secret. The referenced secret must exist in the service's namespace.")
flagNames = append(flagNames, "pull-secret")
flagset.Int64VarP(&p.User, "user", "", 0, "The user ID to run the container (e.g., 1001).")
flagNames = append(flagNames, "user")
return flagNames
}

0 comments on commit d564f49

Please sign in to comment.