Rename `--extra-containers` to `--containers` (#1499)

and make `--extra-containers deprecated`
This commit is contained in:
Roland Huß 2021-11-01 12:39:22 +01:00 committed by GitHub
parent d8d0ee1e6e
commit db3bcbc6b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 39 additions and 25 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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(),
}