From 06f26189f0584d7a96812519e88bb32025db21ae Mon Sep 17 00:00:00 2001 From: derekwaynecarr Date: Wed, 27 Jan 2016 16:18:35 -0500 Subject: [PATCH] Update kubectl create subcommand to use printer flags --- contrib/completions/bash/kubectl | 21 +++++++++++++++++++ docs/man/man1/kubectl-create-namespace.1 | 21 +++++++++++++++++++ .../kubectl-create-secret-docker-registry.1 | 21 +++++++++++++++++++ docs/man/man1/kubectl-create-secret-generic.1 | 21 +++++++++++++++++++ .../kubectl/kubectl_create_namespace.md | 7 ++++++- .../kubectl_create_secret_docker-registry.md | 7 ++++++- .../kubectl/kubectl_create_secret_generic.md | 7 ++++++- hack/test-cmd.sh | 8 +++++++ pkg/kubectl/cmd/create_namespace.go | 1 + pkg/kubectl/cmd/create_secret.go | 2 ++ pkg/kubectl/cmd/util/helpers.go | 2 -- 11 files changed, 113 insertions(+), 5 deletions(-) diff --git a/contrib/completions/bash/kubectl b/contrib/completions/bash/kubectl index 2d6683ceac9..4448f5c298a 100644 --- a/contrib/completions/bash/kubectl +++ b/contrib/completions/bash/kubectl @@ -420,11 +420,18 @@ _kubectl_create_namespace() flags+=("--dry-run") flags+=("--generator=") + flags+=("--no-headers") flags+=("--output=") two_word_flags+=("-o") flags+=("--output-version=") flags+=("--save-config") flags+=("--schema-cache-dir=") + flags+=("--show-all") + flags+=("-a") + flags+=("--show-labels") + flags+=("--sort-by=") + flags+=("--template=") + two_word_flags+=("-t") flags+=("--validate") flags+=("--alsologtostderr") flags+=("--api-version=") @@ -471,11 +478,18 @@ _kubectl_create_secret_docker-registry() flags+=("--docker-username=") flags+=("--dry-run") flags+=("--generator=") + flags+=("--no-headers") flags+=("--output=") two_word_flags+=("-o") flags+=("--output-version=") flags+=("--save-config") flags+=("--schema-cache-dir=") + flags+=("--show-all") + flags+=("-a") + flags+=("--show-labels") + flags+=("--sort-by=") + flags+=("--template=") + two_word_flags+=("-t") flags+=("--validate") flags+=("--alsologtostderr") flags+=("--api-version=") @@ -523,11 +537,18 @@ _kubectl_create_secret_generic() flags+=("--from-file=") flags+=("--from-literal=") flags+=("--generator=") + flags+=("--no-headers") flags+=("--output=") two_word_flags+=("-o") flags+=("--output-version=") flags+=("--save-config") flags+=("--schema-cache-dir=") + flags+=("--show-all") + flags+=("-a") + flags+=("--show-labels") + flags+=("--sort-by=") + flags+=("--template=") + two_word_flags+=("-t") flags+=("--type=") flags+=("--validate") flags+=("--alsologtostderr") diff --git a/docs/man/man1/kubectl-create-namespace.1 b/docs/man/man1/kubectl-create-namespace.1 index 8b5f788bbfd..1617cd72bc5 100644 --- a/docs/man/man1/kubectl-create-namespace.1 +++ b/docs/man/man1/kubectl-create-namespace.1 @@ -25,6 +25,10 @@ Create a namespace with the specified name. \fB\-\-generator\fP="namespace/v1" The name of the API generator to use. +.PP +\fB\-\-no\-headers\fP=false + When using the default output, don't print headers. + .PP \fB\-o\fP, \fB\-\-output\fP="" Output format. One of: json|yaml|wide|name|go\-template=...|go\-template\-file=...|jsonpath=...|jsonpath\-file=... See golang template [ @@ -43,6 +47,23 @@ Create a namespace with the specified name. \fB\-\-schema\-cache\-dir\fP="\~/.kube/schema" If non\-empty, load/store cached API schemas in this directory, default is '$HOME/.kube/schema' +.PP +\fB\-a\fP, \fB\-\-show\-all\fP=false + When printing, show all resources (default hide terminated pods.) + +.PP +\fB\-\-show\-labels\fP=false + When printing, show all labels as the last column (default hide labels column) + +.PP +\fB\-\-sort\-by\fP="" + If non\-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. 'ObjectMeta.Name'). The field in the API resource specified by this JSONPath expression must be an integer or a string. + +.PP +\fB\-\-template\fP="" + Template string or path to template file to use when \-o=go\-template, \-o=go\-template\-file. The template format is golang templates [ +\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]]. + .PP \fB\-\-validate\fP=true If true, use a schema to validate the input before sending it diff --git a/docs/man/man1/kubectl-create-secret-docker-registry.1 b/docs/man/man1/kubectl-create-secret-docker-registry.1 index 7565a64264f..bac5ee75050 100644 --- a/docs/man/man1/kubectl-create-secret-docker-registry.1 +++ b/docs/man/man1/kubectl-create-secret-docker-registry.1 @@ -56,6 +56,10 @@ by creating a dockercfg secret and attaching it to your service account. \fB\-\-generator\fP="secret\-for\-docker\-registry/v1" The name of the API generator to use. +.PP +\fB\-\-no\-headers\fP=false + When using the default output, don't print headers. + .PP \fB\-o\fP, \fB\-\-output\fP="" Output format. One of: json|yaml|wide|name|go\-template=...|go\-template\-file=...|jsonpath=...|jsonpath\-file=... See golang template [ @@ -74,6 +78,23 @@ by creating a dockercfg secret and attaching it to your service account. \fB\-\-schema\-cache\-dir\fP="\~/.kube/schema" If non\-empty, load/store cached API schemas in this directory, default is '$HOME/.kube/schema' +.PP +\fB\-a\fP, \fB\-\-show\-all\fP=false + When printing, show all resources (default hide terminated pods.) + +.PP +\fB\-\-show\-labels\fP=false + When printing, show all labels as the last column (default hide labels column) + +.PP +\fB\-\-sort\-by\fP="" + If non\-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. 'ObjectMeta.Name'). The field in the API resource specified by this JSONPath expression must be an integer or a string. + +.PP +\fB\-\-template\fP="" + Template string or path to template file to use when \-o=go\-template, \-o=go\-template\-file. The template format is golang templates [ +\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]]. + .PP \fB\-\-validate\fP=true If true, use a schema to validate the input before sending it diff --git a/docs/man/man1/kubectl-create-secret-generic.1 b/docs/man/man1/kubectl-create-secret-generic.1 index 48f7ad046c5..7acbc6e0400 100644 --- a/docs/man/man1/kubectl-create-secret-generic.1 +++ b/docs/man/man1/kubectl-create-secret-generic.1 @@ -45,6 +45,10 @@ symlinks, devices, pipes, etc). \fB\-\-generator\fP="secret/v1" The name of the API generator to use. +.PP +\fB\-\-no\-headers\fP=false + When using the default output, don't print headers. + .PP \fB\-o\fP, \fB\-\-output\fP="" Output format. One of: json|yaml|wide|name|go\-template=...|go\-template\-file=...|jsonpath=...|jsonpath\-file=... See golang template [ @@ -63,6 +67,23 @@ symlinks, devices, pipes, etc). \fB\-\-schema\-cache\-dir\fP="\~/.kube/schema" If non\-empty, load/store cached API schemas in this directory, default is '$HOME/.kube/schema' +.PP +\fB\-a\fP, \fB\-\-show\-all\fP=false + When printing, show all resources (default hide terminated pods.) + +.PP +\fB\-\-show\-labels\fP=false + When printing, show all labels as the last column (default hide labels column) + +.PP +\fB\-\-sort\-by\fP="" + If non\-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. 'ObjectMeta.Name'). The field in the API resource specified by this JSONPath expression must be an integer or a string. + +.PP +\fB\-\-template\fP="" + Template string or path to template file to use when \-o=go\-template, \-o=go\-template\-file. The template format is golang templates [ +\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]]. + .PP \fB\-\-type\fP="" The type of secret to create diff --git a/docs/user-guide/kubectl/kubectl_create_namespace.md b/docs/user-guide/kubectl/kubectl_create_namespace.md index 45f7416c26e..f05657198a3 100644 --- a/docs/user-guide/kubectl/kubectl_create_namespace.md +++ b/docs/user-guide/kubectl/kubectl_create_namespace.md @@ -53,10 +53,15 @@ kubectl create namespace NAME [--dry-run] ``` --dry-run[=false]: If true, only print the object that would be sent, without sending it. --generator="namespace/v1": The name of the API generator to use. + --no-headers[=false]: When using the default output, don't print headers. -o, --output="": Output format. One of: json|yaml|wide|name|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md]. --output-version="": Output the formatted object with the given version (default api-version). --save-config[=false]: If true, the configuration of current object will be saved in its annotation. This is useful when you want to perform kubectl apply on this object in the future. --schema-cache-dir="~/.kube/schema": If non-empty, load/store cached API schemas in this directory, default is '$HOME/.kube/schema' + -a, --show-all[=false]: When printing, show all resources (default hide terminated pods.) + --show-labels[=false]: When printing, show all labels as the last column (default hide labels column) + --sort-by="": If non-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. 'ObjectMeta.Name'). The field in the API resource specified by this JSONPath expression must be an integer or a string. + --template="": Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. --validate[=true]: If true, use a schema to validate the input before sending it ``` @@ -92,7 +97,7 @@ kubectl create namespace NAME [--dry-run] * [kubectl create](kubectl_create.md) - Create a resource by filename or stdin -###### Auto generated by spf13/cobra on 14-Dec-2015 +###### Auto generated by spf13/cobra on 10-Feb-2016 [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_create_namespace.md?pixel)]() diff --git a/docs/user-guide/kubectl/kubectl_create_secret_docker-registry.md b/docs/user-guide/kubectl/kubectl_create_secret_docker-registry.md index 2d446b54bdf..7aea75088d6 100644 --- a/docs/user-guide/kubectl/kubectl_create_secret_docker-registry.md +++ b/docs/user-guide/kubectl/kubectl_create_secret_docker-registry.md @@ -68,10 +68,15 @@ kubectl create secret docker-registry NAME --docker-username=user --docker-passw --docker-username="": Username for Docker registry authentication --dry-run[=false]: If true, only print the object that would be sent, without sending it. --generator="secret-for-docker-registry/v1": The name of the API generator to use. + --no-headers[=false]: When using the default output, don't print headers. -o, --output="": Output format. One of: json|yaml|wide|name|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md]. --output-version="": Output the formatted object with the given version (default api-version). --save-config[=false]: If true, the configuration of current object will be saved in its annotation. This is useful when you want to perform kubectl apply on this object in the future. --schema-cache-dir="~/.kube/schema": If non-empty, load/store cached API schemas in this directory, default is '$HOME/.kube/schema' + -a, --show-all[=false]: When printing, show all resources (default hide terminated pods.) + --show-labels[=false]: When printing, show all labels as the last column (default hide labels column) + --sort-by="": If non-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. 'ObjectMeta.Name'). The field in the API resource specified by this JSONPath expression must be an integer or a string. + --template="": Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. --validate[=true]: If true, use a schema to validate the input before sending it ``` @@ -107,7 +112,7 @@ kubectl create secret docker-registry NAME --docker-username=user --docker-passw * [kubectl create secret](kubectl_create_secret.md) - Create a secret using specified subcommand. -###### Auto generated by spf13/cobra on 14-Dec-2015 +###### Auto generated by spf13/cobra on 10-Feb-2016 [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_create_secret_docker-registry.md?pixel)]() diff --git a/docs/user-guide/kubectl/kubectl_create_secret_generic.md b/docs/user-guide/kubectl/kubectl_create_secret_generic.md index c26b0332ff8..50ed538a95a 100644 --- a/docs/user-guide/kubectl/kubectl_create_secret_generic.md +++ b/docs/user-guide/kubectl/kubectl_create_secret_generic.md @@ -71,10 +71,15 @@ kubectl create secret generic NAME [--type=string] [--from-file=[key=]source] [- --from-file=[]: Key files can be specified using their file path, in which case a default name will be given to them, or optionally with a name and file path, in which case the given name will be used. Specifying a directory will iterate each named file in the directory that is a valid secret key. --from-literal=[]: Specify a key and literal value to insert in secret (i.e. mykey=somevalue) --generator="secret/v1": The name of the API generator to use. + --no-headers[=false]: When using the default output, don't print headers. -o, --output="": Output format. One of: json|yaml|wide|name|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md]. --output-version="": Output the formatted object with the given version (default api-version). --save-config[=false]: If true, the configuration of current object will be saved in its annotation. This is useful when you want to perform kubectl apply on this object in the future. --schema-cache-dir="~/.kube/schema": If non-empty, load/store cached API schemas in this directory, default is '$HOME/.kube/schema' + -a, --show-all[=false]: When printing, show all resources (default hide terminated pods.) + --show-labels[=false]: When printing, show all labels as the last column (default hide labels column) + --sort-by="": If non-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. 'ObjectMeta.Name'). The field in the API resource specified by this JSONPath expression must be an integer or a string. + --template="": Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. --type="": The type of secret to create --validate[=true]: If true, use a schema to validate the input before sending it ``` @@ -111,7 +116,7 @@ kubectl create secret generic NAME [--type=string] [--from-file=[key=]source] [- * [kubectl create secret](kubectl_create_secret.md) - Create a secret using specified subcommand. -###### Auto generated by spf13/cobra on 14-Dec-2015 +###### Auto generated by spf13/cobra on 10-Feb-2016 [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_create_secret_generic.md?pixel)]() diff --git a/hack/test-cmd.sh b/hack/test-cmd.sh index cf54cb04e27..64acf9cf944 100755 --- a/hack/test-cmd.sh +++ b/hack/test-cmd.sh @@ -760,6 +760,14 @@ runTests() { [[ "$(kubectl get secret/test-secret --namespace=test-secrets -o yaml "${kube_flags[@]}" | grep '.dockercfg:')" ]] # Clean-up kubectl delete secret test-secret --namespace=test-secrets + + ### Create a secret using output flags + # Pre-condition: no secret exists + kube::test::get_object_assert 'secrets --namespace=test-secrets' "{{range.items}}{{$id_field}}:{{end}}" '' + # Command + [[ "$(kubectl create secret generic test-secret --namespace=test-secrets --from-literal=key1=value1 --output=go-template --template=\"{{.metadata.name}}:\" | grep 'test-secret:')" ]] + ## Clean-up + kubectl delete secret test-secret --namespace=test-secrets # Clean up kubectl delete namespace test-secrets diff --git a/pkg/kubectl/cmd/create_namespace.go b/pkg/kubectl/cmd/create_namespace.go index f9e5c888539..a66055fb193 100644 --- a/pkg/kubectl/cmd/create_namespace.go +++ b/pkg/kubectl/cmd/create_namespace.go @@ -49,6 +49,7 @@ func NewCmdCreateNamespace(f *cmdutil.Factory, cmdOut io.Writer) *cobra.Command } cmdutil.AddApplyAnnotationFlags(cmd) cmdutil.AddValidateFlags(cmd) + cmdutil.AddPrinterFlags(cmd) cmdutil.AddGeneratorFlags(cmd, cmdutil.NamespaceV1GeneratorName) return cmd } diff --git a/pkg/kubectl/cmd/create_secret.go b/pkg/kubectl/cmd/create_secret.go index e8894a276ad..0a4c66b18a0 100644 --- a/pkg/kubectl/cmd/create_secret.go +++ b/pkg/kubectl/cmd/create_secret.go @@ -79,6 +79,7 @@ func NewCmdCreateSecretGeneric(f *cmdutil.Factory, cmdOut io.Writer) *cobra.Comm } cmdutil.AddApplyAnnotationFlags(cmd) cmdutil.AddValidateFlags(cmd) + cmdutil.AddPrinterFlags(cmd) cmdutil.AddGeneratorFlags(cmd, cmdutil.SecretV1GeneratorName) cmd.Flags().StringSlice("from-file", []string{}, "Key files can be specified using their file path, in which case a default name will be given to them, or optionally with a name and file path, in which case the given name will be used. Specifying a directory will iterate each named file in the directory that is a valid secret key.") cmd.Flags().StringSlice("from-literal", []string{}, "Specify a key and literal value to insert in secret (i.e. mykey=somevalue)") @@ -145,6 +146,7 @@ func NewCmdCreateSecretDockerRegistry(f *cmdutil.Factory, cmdOut io.Writer) *cob } cmdutil.AddApplyAnnotationFlags(cmd) cmdutil.AddValidateFlags(cmd) + cmdutil.AddPrinterFlags(cmd) cmdutil.AddGeneratorFlags(cmd, cmdutil.SecretForDockerRegistryV1GeneratorName) cmd.Flags().String("docker-username", "", "Username for Docker registry authentication") cmd.MarkFlagRequired("docker-username") diff --git a/pkg/kubectl/cmd/util/helpers.go b/pkg/kubectl/cmd/util/helpers.go index 19cc401e7d0..f4364964fc7 100644 --- a/pkg/kubectl/cmd/util/helpers.go +++ b/pkg/kubectl/cmd/util/helpers.go @@ -318,8 +318,6 @@ func AddApplyAnnotationFlags(cmd *cobra.Command) { func AddGeneratorFlags(cmd *cobra.Command, defaultGenerator string) { cmd.Flags().String("generator", defaultGenerator, "The name of the API generator to use.") cmd.Flags().Bool("dry-run", false, "If true, only print the object that would be sent, without sending it.") - cmd.Flags().StringP("output", "o", "", "Output format. One of: json|yaml|wide|name|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md].") - cmd.Flags().String("output-version", "", "Output the formatted object with the given version (default api-version).") } func ReadConfigDataFromReader(reader io.Reader, source string) ([]byte, error) {