Skip to content

Commit

Permalink
make command as array instead of string (#1380)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
itsmurugappan authored Jul 13, 2021
1 parent 536d1f1 commit 0c3e236
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 16 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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%"]
|===
Expand Down
2 changes: 1 addition & 1 deletion docs/cmd/kn_service_apply.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/cmd/kn_service_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/cmd/kn_service_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/cmd/kn_source_container_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-.
Expand Down
2 changes: 1 addition & 1 deletion docs/cmd/kn_source_container_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-.
Expand Down
4 changes: 2 additions & 2 deletions pkg/kn/commands/service/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kn/commands/service/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
6 changes: 3 additions & 3 deletions pkg/kn/flags/podspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type PodSpecFlags struct {
Mount []string
Volume []string

Command string
Command []string
Arg []string

Resources ResourceOptions
Expand Down Expand Up @@ -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{},
Expand Down
4 changes: 2 additions & 2 deletions pkg/kn/flags/podspec_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/kn/flags/podspec_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions pkg/kn/flags/podspec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestPodSpecFlags(t *testing.T) {
Mount: []string{},
Volume: []string{},
Arg: []string{},
Command: []string{},
}
flags := &PodSpecFlags{}
testCmd := &cobra.Command{
Expand Down

0 comments on commit 0c3e236

Please sign in to comment.