From db3bcbc6b04dfa336b6c78d50e5f4b38ffcb46dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Hu=C3=9F?= Date: Mon, 1 Nov 2021 12:39:22 +0100 Subject: [PATCH] Rename `--extra-containers` to `--containers` (#1499) and make `--extra-containers deprecated` --- docs/cmd/kn_container_add.md | 5 +++-- docs/cmd/kn_service_apply.md | 3 ++- docs/cmd/kn_service_create.md | 3 ++- docs/cmd/kn_service_update.md | 3 ++- docs/cmd/kn_source_container_create.md | 3 ++- docs/cmd/kn_source_container_update.md | 3 ++- pkg/kn/commands/container/add.go | 2 +- pkg/kn/commands/container/add_test.go | 27 ++++++++++++++------------ pkg/kn/flags/podspec.go | 9 +++++++-- pkg/kn/flags/podspec_test.go | 2 +- test/e2e/extra_containers_test.go | 4 ++-- 11 files changed, 39 insertions(+), 25 deletions(-) diff --git a/docs/cmd/kn_container_add.md b/docs/cmd/kn_container_add.md index 808983ee0..36e33a11a 100644 --- a/docs/cmd/kn_container_add.md +++ b/docs/cmd/kn_container_add.md @@ -22,7 +22,7 @@ kn container add NAME # Add command can be chained by standard Unix pipe symbol '|' and passed to 'service add|update|apply' commands kn container add sidecar --image docker.io/example/sidecar:first | \ kn container add second --image docker.io/example/sidecar:second | \ - kn service create myksvc --image docker.io/example/my-app:latest --extra-containers - + kn service create myksvc --image docker.io/example/my-app:latest --containers - ``` ### Options @@ -30,11 +30,12 @@ kn container add NAME ``` --arg stringArray Add argument to the container command. Example: --arg myArg1 --arg --myArg2 --arg myArg3=3. You can use this flag multiple times. --cmd stringArray Specify command to be used as entrypoint instead of default one. Example: --cmd /app/start or --cmd sh --cmd /app/start.sh or --cmd /app/start --arg myArg to pass additional arguments. + --containers string Specify path to file including definition for additional containers, alternatively use '-' to read from stdin. Example: --containers ./containers.yaml or --containers -. -e, --env stringArray 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-). --env-file string Path to a file containing environment variables (e.g. --env-file=/home/knative/service1/env). --env-from stringArray 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-. --env-value-from stringArray Add environment variable from a value of key in ConfigMap (prefix cm: or config-map:) or a Secret (prefix sc: or secret:). Example: --env-value-from NAME=cm:myconfigmap:key or --env-value-from NAME=secret:mysecret:key. You can use this flag multiple times. To unset a value from a ConfigMap/Secret key reference, append "-" to the key, e.g. --env-value-from ENV-. - --extra-containers string Specify path to file including definition for additional containers, alternatively use '-' to read from stdin. Example: --extra-containers ./containers.yaml or --extra-containers -. + --extra-containers string Deprecated, use --containers instead. -h, --help help for add --image string Image to run. --limit strings 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-'. diff --git a/docs/cmd/kn_service_apply.md b/docs/cmd/kn_service_apply.md index 32ae2f819..a1187a588 100644 --- a/docs/cmd/kn_service_apply.md +++ b/docs/cmd/kn_service_apply.md @@ -39,11 +39,12 @@ kn service apply s0 --filename my-svc.yml --concurrency-limit int Hard Limit of concurrent requests to be processed by a single replica. --concurrency-target int Deprecated, use --scale-target instead. --concurrency-utilization int Deprecated, use --scale-utilization instead. (default 70) + --containers string Specify path to file including definition for additional containers, alternatively use '-' to read from stdin. Example: --containers ./containers.yaml or --containers -. -e, --env stringArray 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-). --env-file string Path to a file containing environment variables (e.g. --env-file=/home/knative/service1/env). --env-from stringArray 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-. --env-value-from stringArray Add environment variable from a value of key in ConfigMap (prefix cm: or config-map:) or a Secret (prefix sc: or secret:). Example: --env-value-from NAME=cm:myconfigmap:key or --env-value-from NAME=secret:mysecret:key. You can use this flag multiple times. To unset a value from a ConfigMap/Secret key reference, append "-" to the key, e.g. --env-value-from ENV-. - --extra-containers string Specify path to file including definition for additional containers, alternatively use '-' to read from stdin. Example: --extra-containers ./containers.yaml or --extra-containers -. + --extra-containers string Deprecated, use --containers instead. -f, --filename string Create a service from file. The created service can be further modified by combining with other options. For example, -f /path/to/file --env NAME=value adds also an environment variable. --force Create service forcefully, replaces existing service if any. -h, --help help for apply diff --git a/docs/cmd/kn_service_create.md b/docs/cmd/kn_service_create.md index 6daf2066e..596e5dde8 100644 --- a/docs/cmd/kn_service_create.md +++ b/docs/cmd/kn_service_create.md @@ -64,11 +64,12 @@ kn service create NAME --image IMAGE --concurrency-limit int Hard Limit of concurrent requests to be processed by a single replica. --concurrency-target int Deprecated, use --scale-target instead. --concurrency-utilization int Deprecated, use --scale-utilization instead. (default 70) + --containers string Specify path to file including definition for additional containers, alternatively use '-' to read from stdin. Example: --containers ./containers.yaml or --containers -. -e, --env stringArray 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-). --env-file string Path to a file containing environment variables (e.g. --env-file=/home/knative/service1/env). --env-from stringArray 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-. --env-value-from stringArray Add environment variable from a value of key in ConfigMap (prefix cm: or config-map:) or a Secret (prefix sc: or secret:). Example: --env-value-from NAME=cm:myconfigmap:key or --env-value-from NAME=secret:mysecret:key. You can use this flag multiple times. To unset a value from a ConfigMap/Secret key reference, append "-" to the key, e.g. --env-value-from ENV-. - --extra-containers string Specify path to file including definition for additional containers, alternatively use '-' to read from stdin. Example: --extra-containers ./containers.yaml or --extra-containers -. + --extra-containers string Deprecated, use --containers instead. -f, --filename string Create a service from file. The created service can be further modified by combining with other options. For example, -f /path/to/file --env NAME=value adds also an environment variable. --force Create service forcefully, replaces existing service if any. -h, --help help for create diff --git a/docs/cmd/kn_service_update.md b/docs/cmd/kn_service_update.md index 7aef6756c..07313c1d4 100644 --- a/docs/cmd/kn_service_update.md +++ b/docs/cmd/kn_service_update.md @@ -53,11 +53,12 @@ kn service update NAME --concurrency-limit int Hard Limit of concurrent requests to be processed by a single replica. --concurrency-target int Deprecated, use --scale-target instead. --concurrency-utilization int Deprecated, use --scale-utilization instead. (default 70) + --containers string Specify path to file including definition for additional containers, alternatively use '-' to read from stdin. Example: --containers ./containers.yaml or --containers -. -e, --env stringArray 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-). --env-file string Path to a file containing environment variables (e.g. --env-file=/home/knative/service1/env). --env-from stringArray 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-. --env-value-from stringArray Add environment variable from a value of key in ConfigMap (prefix cm: or config-map:) or a Secret (prefix sc: or secret:). Example: --env-value-from NAME=cm:myconfigmap:key or --env-value-from NAME=secret:mysecret:key. You can use this flag multiple times. To unset a value from a ConfigMap/Secret key reference, append "-" to the key, e.g. --env-value-from ENV-. - --extra-containers string Specify path to file including definition for additional containers, alternatively use '-' to read from stdin. Example: --extra-containers ./containers.yaml or --extra-containers -. + --extra-containers string Deprecated, use --containers instead. -h, --help help for update --image string Image to run. -l, --label stringArray Labels to set for both Service and Revision. name=value; you may provide this flag any number of times to set multiple labels. To unset, specify the label name followed by a "-" (e.g., name-). diff --git a/docs/cmd/kn_source_container_create.md b/docs/cmd/kn_source_container_create.md index 71a2054b2..a7cd5ac57 100644 --- a/docs/cmd/kn_source_container_create.md +++ b/docs/cmd/kn_source_container_create.md @@ -19,11 +19,12 @@ kn source container create NAME --image IMAGE --sink SINK ``` --arg stringArray Add argument to the container command. Example: --arg myArg1 --arg --myArg2 --arg myArg3=3. You can use this flag multiple times. --cmd stringArray Specify command to be used as entrypoint instead of default one. Example: --cmd /app/start or --cmd sh --cmd /app/start.sh or --cmd /app/start --arg myArg to pass additional arguments. + --containers string Specify path to file including definition for additional containers, alternatively use '-' to read from stdin. Example: --containers ./containers.yaml or --containers -. -e, --env stringArray 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-). --env-file string Path to a file containing environment variables (e.g. --env-file=/home/knative/service1/env). --env-from stringArray 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-. --env-value-from stringArray Add environment variable from a value of key in ConfigMap (prefix cm: or config-map:) or a Secret (prefix sc: or secret:). Example: --env-value-from NAME=cm:myconfigmap:key or --env-value-from NAME=secret:mysecret:key. You can use this flag multiple times. To unset a value from a ConfigMap/Secret key reference, append "-" to the key, e.g. --env-value-from ENV-. - --extra-containers string Specify path to file including definition for additional containers, alternatively use '-' to read from stdin. Example: --extra-containers ./containers.yaml or --extra-containers -. + --extra-containers string Deprecated, use --containers instead. -h, --help help for create --image string Image to run. --limit strings 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-'. diff --git a/docs/cmd/kn_source_container_update.md b/docs/cmd/kn_source_container_update.md index e86dc4145..672eb5a39 100644 --- a/docs/cmd/kn_source_container_update.md +++ b/docs/cmd/kn_source_container_update.md @@ -19,11 +19,12 @@ kn source container update NAME --image IMAGE ``` --arg stringArray Add argument to the container command. Example: --arg myArg1 --arg --myArg2 --arg myArg3=3. You can use this flag multiple times. --cmd stringArray Specify command to be used as entrypoint instead of default one. Example: --cmd /app/start or --cmd sh --cmd /app/start.sh or --cmd /app/start --arg myArg to pass additional arguments. + --containers string Specify path to file including definition for additional containers, alternatively use '-' to read from stdin. Example: --containers ./containers.yaml or --containers -. -e, --env stringArray 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-). --env-file string Path to a file containing environment variables (e.g. --env-file=/home/knative/service1/env). --env-from stringArray 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-. --env-value-from stringArray Add environment variable from a value of key in ConfigMap (prefix cm: or config-map:) or a Secret (prefix sc: or secret:). Example: --env-value-from NAME=cm:myconfigmap:key or --env-value-from NAME=secret:mysecret:key. You can use this flag multiple times. To unset a value from a ConfigMap/Secret key reference, append "-" to the key, e.g. --env-value-from ENV-. - --extra-containers string Specify path to file including definition for additional containers, alternatively use '-' to read from stdin. Example: --extra-containers ./containers.yaml or --extra-containers -. + --extra-containers string Deprecated, use --containers instead. -h, --help help for update --image string Image to run. --limit strings 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-'. diff --git a/pkg/kn/commands/container/add.go b/pkg/kn/commands/container/add.go index 593be3a05..fb0b061be 100644 --- a/pkg/kn/commands/container/add.go +++ b/pkg/kn/commands/container/add.go @@ -45,7 +45,7 @@ func NewContainerAddCommand(p *commands.KnParams) *cobra.Command { # Add command can be chained by standard Unix pipe symbol '|' and passed to 'service add|update|apply' commands kn container add sidecar --image docker.io/example/sidecar:first | \ kn container add second --image docker.io/example/sidecar:second | \ - kn service create myksvc --image docker.io/example/my-app:latest --extra-containers -`, + kn service create myksvc --image docker.io/example/my-app:latest --containers -`, RunE: func(cmd *cobra.Command, args []string) (err error) { if len(args) != 1 { return errors.New("'container add' requires the container name given as single argument") diff --git a/pkg/kn/commands/container/add_test.go b/pkg/kn/commands/container/add_test.go index 0ce108b6c..ed2cbd8df 100644 --- a/pkg/kn/commands/container/add_test.go +++ b/pkg/kn/commands/container/add_test.go @@ -37,21 +37,24 @@ containers: name: bar resources: {}` - stdinReader, stdinWriter, err := os.Pipe() - assert.NilError(t, err) - stdinWriter.Chmod(os.ModeCharDevice) - _, err = stdinWriter.Write([]byte(rawInput)) - assert.NilError(t, err) - stdinWriter.Close() - origStdin := os.Stdin - os.Stdin = stdinReader defer func() { os.Stdin = origStdin }() - output, err := executeContainerCommand("add", "foo", "--image", "registry.foo:bar", "--extra-containers", "-") - assert.NilError(t, err) - assert.Assert(t, len(output) > 0) - assert.Assert(t, util.ContainsAllIgnoreCase(output, "containers", "image", "foo", "registry.foo:bar", "bar", "bar:bar")) + for _, command := range []string{"containers", "extra-containers"} { + stdinReader, stdinWriter, err := os.Pipe() + assert.NilError(t, err) + stdinWriter.Chmod(os.ModeCharDevice) + _, err = stdinWriter.Write([]byte(rawInput)) + assert.NilError(t, err) + stdinWriter.Close() + + os.Stdin = stdinReader + + output, err := executeContainerCommand("add", "foo", "--image", "registry.foo:bar", "--"+command, "-") + assert.NilError(t, err) + assert.Assert(t, len(output) > 0) + assert.Assert(t, util.ContainsAllIgnoreCase(output, "containers", "image", "foo", "registry.foo:bar", "bar", "bar:bar")) + } } func TestContainerAddError(t *testing.T) { diff --git a/pkg/kn/flags/podspec.go b/pkg/kn/flags/podspec.go index 071ae0eab..9dd3d5ef0 100644 --- a/pkg/kn/flags/podspec.go +++ b/pkg/kn/flags/podspec.go @@ -129,9 +129,14 @@ func (p *PodSpecFlags) AddFlags(flagset *pflag.FlagSet) []string { "You can use this flag multiple times.") flagNames = append(flagNames, "arg") + // DEPRECATED since 1.0 flagset.StringVarP(&p.ExtraContainers, "extra-containers", "", "", + "Deprecated, use --containers instead.") + flagNames = append(flagNames, "containers") + + flagset.StringVarP(&p.ExtraContainers, "containers", "", "", "Specify path to file including definition for additional containers, alternatively use '-' to read from stdin. "+ - "Example: --extra-containers ./containers.yaml or --extra-containers -.") + "Example: --containers ./containers.yaml or --containers -.") flagNames = append(flagNames, "containers") flagset.StringSliceVar(&p.Resources.Limits, @@ -296,7 +301,7 @@ func (p *PodSpecFlags) ResolvePodSpec(podSpec *corev1.PodSpec, flags *pflag.Flag } } - if flags.Changed("extra-containers") || p.ExtraContainers == "-" { + if flags.Changed("containers") || flags.Changed("extra-containers") || p.ExtraContainers == "-" { var fromFile *corev1.PodSpec fromFile, err = decodeContainersFromFile(p.ExtraContainers) if err != nil { diff --git a/pkg/kn/flags/podspec_test.go b/pkg/kn/flags/podspec_test.go index 69f09ff11..42b1aea11 100644 --- a/pkg/kn/flags/podspec_test.go +++ b/pkg/kn/flags/podspec_test.go @@ -233,7 +233,7 @@ containers: defer os.RemoveAll(fileName) } - inputArgs := []string{"--image", "repo/user/imageID:tag", "--extra-containers", fileName} + inputArgs := []string{"--image", "repo/user/imageID:tag", "--containers", fileName} flags := &PodSpecFlags{} testCmd := &cobra.Command{ diff --git a/test/e2e/extra_containers_test.go b/test/e2e/extra_containers_test.go index 8d57abd3a..8872676ea 100644 --- a/test/e2e/extra_containers_test.go +++ b/test/e2e/extra_containers_test.go @@ -102,7 +102,7 @@ func createServiceWithSidecar(r *test.KnRunResultCollector, serviceName, file st args := []string{"service", "create", serviceName, "--image", pkgtest.ImagePath("servingcontainer"), "--port", "8881", - "--extra-containers", file, + "--containers", file, } out := r.KnTest().Kn().Run(args...) @@ -117,7 +117,7 @@ func createServiceWithPipeInput(r *test.KnRunResultCollector, serviceName, sideC args := []string{"service", "create", serviceName, "--image", pkgtest.ImagePath("servingcontainer"), "--port", "8881", - "--extra-containers", "-", + "--containers", "-", "--namespace", r.KnTest().Kn().Namespace(), }