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
This commit is contained in:
Murugappan Chetty 2021-07-13 13:32:31 -07:00 committed by GitHub
parent 536d1f13c1
commit 0c3e236006
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 27 additions and 16 deletions

View File

@ -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%"]
|===

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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-.

View File

@ -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-.

View File

@ -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) {

View File

@ -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{

View File

@ -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{},

View File

@ -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
}

View File

@ -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) {

View File

@ -36,6 +36,7 @@ func TestPodSpecFlags(t *testing.T) {
Mount: []string{},
Volume: []string{},
Arg: []string{},
Command: []string{},
}
flags := &PodSpecFlags{}
testCmd := &cobra.Command{