From 0c3e2360061a9c26b7e71370a3dc4b6badb1a2eb Mon Sep 17 00:00:00 2001 From: Murugappan Chetty Date: Tue, 13 Jul 2021 13:32:31 -0700 Subject: [PATCH] make command as array instead of string (#1380) * make command as array instead of string * make command as array instead of string * make command as array instead of string * make command as array instead of string * make command as array instead of string * make command as array instead of string --- CHANGELOG.adoc | 10 ++++++++++ docs/cmd/kn_service_apply.md | 2 +- docs/cmd/kn_service_create.md | 2 +- docs/cmd/kn_service_update.md | 2 +- docs/cmd/kn_source_container_create.md | 2 +- docs/cmd/kn_source_container_update.md | 2 +- pkg/kn/commands/service/create_test.go | 4 ++-- pkg/kn/commands/service/update_test.go | 2 +- pkg/kn/flags/podspec.go | 6 +++--- pkg/kn/flags/podspec_helper.go | 4 ++-- pkg/kn/flags/podspec_helper_test.go | 6 +++--- pkg/kn/flags/podspec_test.go | 1 + 12 files changed, 27 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 30b4269811..03e1886411 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -12,6 +12,16 @@ | https://github.com/knative/client/pull/[#] //// +## Unreleased +[cols="1,10,3", options="header", width="100%"] +|=== +| | Description | PR + +| ✨ +| make --cmd flag as an array instead of string +| https://github.com/knative/client/pull/1380[#1380] +|=== + ## v0.24.0 (2021-06-29) [cols="1,10,3", options="header", width="100%"] |=== diff --git a/docs/cmd/kn_service_apply.md b/docs/cmd/kn_service_apply.md index 8bd125da8f..c967c7ca22 100644 --- a/docs/cmd/kn_service_apply.md +++ b/docs/cmd/kn_service_apply.md @@ -35,7 +35,7 @@ kn service apply s0 --filename my-svc.yml --arg stringArray Add argument to the container command. Example: --arg myArg1 --arg --myArg2 --arg myArg3=3. You can use this flag multiple times. --autoscale-window string Duration to look back for making auto-scaling decisions. The service is scaled to zero if no request was received in during that time. (eg: 10s) --cluster-local Specify that the service be private. (--no-cluster-local will make the service publicly available) - --cmd string Specify command to be used as entrypoint instead of default one. Example: --cmd /app/start or --cmd /app/start --arg myArg to pass additional arguments. + --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. --concurrency-limit int Hard Limit of concurrent requests to be processed by a single replica. --concurrency-target int Recommendation for when to scale up based on the concurrent number of incoming request. Defaults to --concurrency-limit when given. --concurrency-utilization int Percentage of concurrent requests utilization before scaling up. (default 70) diff --git a/docs/cmd/kn_service_create.md b/docs/cmd/kn_service_create.md index 71c44b8ae7..e5f696c25a 100644 --- a/docs/cmd/kn_service_create.md +++ b/docs/cmd/kn_service_create.md @@ -60,7 +60,7 @@ kn service create 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. --autoscale-window string Duration to look back for making auto-scaling decisions. The service is scaled to zero if no request was received in during that time. (eg: 10s) --cluster-local Specify that the service be private. (--no-cluster-local will make the service publicly available) - --cmd string Specify command to be used as entrypoint instead of default one. Example: --cmd /app/start or --cmd /app/start --arg myArg to pass additional arguments. + --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. --concurrency-limit int Hard Limit of concurrent requests to be processed by a single replica. --concurrency-target int Recommendation for when to scale up based on the concurrent number of incoming request. Defaults to --concurrency-limit when given. --concurrency-utilization int Percentage of concurrent requests utilization before scaling up. (default 70) diff --git a/docs/cmd/kn_service_update.md b/docs/cmd/kn_service_update.md index f0f31cfb43..df270fc76b 100644 --- a/docs/cmd/kn_service_update.md +++ b/docs/cmd/kn_service_update.md @@ -45,7 +45,7 @@ kn service update NAME --arg stringArray Add argument to the container command. Example: --arg myArg1 --arg --myArg2 --arg myArg3=3. You can use this flag multiple times. --autoscale-window string Duration to look back for making auto-scaling decisions. The service is scaled to zero if no request was received in during that time. (eg: 10s) --cluster-local Specify that the service be private. (--no-cluster-local will make the service publicly available) - --cmd string Specify command to be used as entrypoint instead of default one. Example: --cmd /app/start or --cmd /app/start --arg myArg to pass additional arguments. + --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. --concurrency-limit int Hard Limit of concurrent requests to be processed by a single replica. --concurrency-target int Recommendation for when to scale up based on the concurrent number of incoming request. Defaults to --concurrency-limit when given. --concurrency-utilization int Percentage of concurrent requests utilization before scaling up. (default 70) diff --git a/docs/cmd/kn_source_container_create.md b/docs/cmd/kn_source_container_create.md index 10043dfd70..0414518a10 100644 --- a/docs/cmd/kn_source_container_create.md +++ b/docs/cmd/kn_source_container_create.md @@ -18,7 +18,7 @@ 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 string Specify command to be used as entrypoint instead of default one. Example: --cmd /app/start or --cmd /app/start --arg myArg to pass additional arguments. + --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. -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-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-. diff --git a/docs/cmd/kn_source_container_update.md b/docs/cmd/kn_source_container_update.md index d3c43bff5e..d893a17b3b 100644 --- a/docs/cmd/kn_source_container_update.md +++ b/docs/cmd/kn_source_container_update.md @@ -18,7 +18,7 @@ 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 string Specify command to be used as entrypoint instead of default one. Example: --cmd /app/start or --cmd /app/start --arg myArg to pass additional arguments. + --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. -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-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-. diff --git a/pkg/kn/commands/service/create_test.go b/pkg/kn/commands/service/create_test.go index d1690edcaa..afc14a2e15 100644 --- a/pkg/kn/commands/service/create_test.go +++ b/pkg/kn/commands/service/create_test.go @@ -182,13 +182,13 @@ func TestServiceCreateImageSync(t *testing.T) { func TestServiceCreateCommand(t *testing.T) { action, created, _, err := fakeServiceCreate([]string{ - "service", "create", "foo", "--image", "gcr.io/foo/bar:baz", "--cmd", "/app/start", "--no-wait"}, false) + "service", "create", "foo", "--image", "gcr.io/foo/bar:baz", "--cmd", "sh", "--cmd", "/app/start.sh", "--no-wait"}, false) assert.NilError(t, err) assert.Assert(t, action.Matches("create", "services")) template := &created.Spec.Template assert.NilError(t, err) - assert.DeepEqual(t, template.Spec.Containers[0].Command, []string{"/app/start"}) + assert.DeepEqual(t, template.Spec.Containers[0].Command, []string{"sh", "/app/start.sh"}) } func TestServiceCreateArg(t *testing.T) { diff --git a/pkg/kn/commands/service/update_test.go b/pkg/kn/commands/service/update_test.go index 1aa83e23a9..57bad96f96 100644 --- a/pkg/kn/commands/service/update_test.go +++ b/pkg/kn/commands/service/update_test.go @@ -219,7 +219,7 @@ func TestServiceUpdateCommand(t *testing.T) { origTemplate := &orig.Spec.Template - err := flags.UpdateContainerCommand(&origTemplate.Spec.PodSpec, "./start") + err := flags.UpdateContainerCommand(&origTemplate.Spec.PodSpec, []string{"./start"}) assert.NilError(t, err) action, updated, _, err := fakeServiceUpdate(orig, []string{ diff --git a/pkg/kn/flags/podspec.go b/pkg/kn/flags/podspec.go index 401b1a8ab7..e9048aa94d 100644 --- a/pkg/kn/flags/podspec.go +++ b/pkg/kn/flags/podspec.go @@ -35,7 +35,7 @@ type PodSpecFlags struct { Mount []string Volume []string - Command string + Command []string Arg []string Resources ResourceOptions @@ -112,9 +112,9 @@ func (p *PodSpecFlags) AddFlags(flagset *pflag.FlagSet) []string { "To unset a ConfigMap/Secret reference, append \"-\" to the name, e.g. --volume myvolume-.") flagNames = append(flagNames, "volume") - flagset.StringVarP(&p.Command, "cmd", "", "", + flagset.StringArrayVarP(&p.Command, "cmd", "", []string{}, "Specify command to be used as entrypoint instead of default one. "+ - "Example: --cmd /app/start or --cmd /app/start --arg myArg to pass additional arguments.") + "Example: --cmd /app/start or --cmd sh --cmd /app/start.sh or --cmd /app/start --arg myArg to pass additional arguments.") flagNames = append(flagNames, "cmd") flagset.StringArrayVarP(&p.Arg, "arg", "", []string{}, diff --git a/pkg/kn/flags/podspec_helper.go b/pkg/kn/flags/podspec_helper.go index 985c2a2738..065aa1d42a 100644 --- a/pkg/kn/flags/podspec_helper.go +++ b/pkg/kn/flags/podspec_helper.go @@ -154,9 +154,9 @@ func UpdateImage(spec *corev1.PodSpec, image string) error { } // UpdateContainerCommand updates container with a given argument -func UpdateContainerCommand(spec *corev1.PodSpec, command string) error { +func UpdateContainerCommand(spec *corev1.PodSpec, command []string) error { container := containerOfPodSpec(spec) - container.Command = []string{command} + container.Command = command return nil } diff --git a/pkg/kn/flags/podspec_helper_test.go b/pkg/kn/flags/podspec_helper_test.go index 5dd0fd9a86..39cb9ff252 100644 --- a/pkg/kn/flags/podspec_helper_test.go +++ b/pkg/kn/flags/podspec_helper_test.go @@ -352,13 +352,13 @@ func checkContainerImage(t *testing.T, spec *corev1.PodSpec, image string) { func TestUpdateContainerCommand(t *testing.T) { spec, _ := getPodSpec() - err := UpdateContainerCommand(spec, "/app/start") + err := UpdateContainerCommand(spec, []string{"/app/start"}) assert.NilError(t, err) assert.DeepEqual(t, spec.Containers[0].Command, []string{"/app/start"}) - err = UpdateContainerCommand(spec, "/app/latest") + err = UpdateContainerCommand(spec, []string{"sh", "/app/latest.sh"}) assert.NilError(t, err) - assert.DeepEqual(t, spec.Containers[0].Command, []string{"/app/latest"}) + assert.DeepEqual(t, spec.Containers[0].Command, []string{"sh", "/app/latest.sh"}) } func TestUpdateContainerArg(t *testing.T) { diff --git a/pkg/kn/flags/podspec_test.go b/pkg/kn/flags/podspec_test.go index 1dc427bff5..118401719c 100644 --- a/pkg/kn/flags/podspec_test.go +++ b/pkg/kn/flags/podspec_test.go @@ -36,6 +36,7 @@ func TestPodSpecFlags(t *testing.T) { Mount: []string{}, Volume: []string{}, Arg: []string{}, + Command: []string{}, } flags := &PodSpecFlags{} testCmd := &cobra.Command{