From 5cc540fec1b6f06bb4611b6c2a1dcc0dc66ef35e Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Sun, 3 Apr 2016 15:48:24 +0900 Subject: [PATCH 1/4] Update bashcompletion codes for kubectl edit --- contrib/completions/bash/kubectl | 67 ++++++++++++++++++++++++++++++++ pkg/kubectl/cmd/cmd.go | 2 +- pkg/kubectl/cmd/edit.go | 11 ++++++ 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/contrib/completions/bash/kubectl b/contrib/completions/bash/kubectl index bf31f29158d..8944f93bacc 100644 --- a/contrib/completions/bash/kubectl +++ b/contrib/completions/bash/kubectl @@ -1328,7 +1328,74 @@ _kubectl_edit() must_have_one_flag=() must_have_one_noun=() + must_have_one_noun+=("componentstatus") + must_have_one_noun+=("configmap") + must_have_one_noun+=("daemonset") + must_have_one_noun+=("deployment") + must_have_one_noun+=("endpoints") + must_have_one_noun+=("event") + must_have_one_noun+=("horizontalpodautoscaler") + must_have_one_noun+=("ingress") + must_have_one_noun+=("job") + must_have_one_noun+=("limitrange") + must_have_one_noun+=("namespace") + must_have_one_noun+=("node") + must_have_one_noun+=("persistentvolume") + must_have_one_noun+=("persistentvolumeclaim") + must_have_one_noun+=("pod") + must_have_one_noun+=("podsecuritypolicy") + must_have_one_noun+=("podtemplate") + must_have_one_noun+=("replicaset") + must_have_one_noun+=("replicationcontroller") + must_have_one_noun+=("resourcequota") + must_have_one_noun+=("secret") + must_have_one_noun+=("service") + must_have_one_noun+=("serviceaccount") + must_have_one_noun+=("thirdpartyresource") + must_have_one_noun+=("thirdpartyresourcedata") noun_aliases=() + noun_aliases+=("componentstatuses") + noun_aliases+=("configmaps") + noun_aliases+=("cs") + noun_aliases+=("daemonsets") + noun_aliases+=("deployments") + noun_aliases+=("ds") + noun_aliases+=("endpoints") + noun_aliases+=("ep") + noun_aliases+=("ev") + noun_aliases+=("events") + noun_aliases+=("horizontalpodautoscalers") + noun_aliases+=("hpa") + noun_aliases+=("ing") + noun_aliases+=("ingresses") + noun_aliases+=("jobs") + noun_aliases+=("limitranges") + noun_aliases+=("limits") + noun_aliases+=("namespaces") + noun_aliases+=("no") + noun_aliases+=("nodes") + noun_aliases+=("ns") + noun_aliases+=("persistentvolumeclaims") + noun_aliases+=("persistentvolumes") + noun_aliases+=("po") + noun_aliases+=("pods") + noun_aliases+=("podsecuritypolicies") + noun_aliases+=("podtemplates") + noun_aliases+=("pv") + noun_aliases+=("pvc") + noun_aliases+=("quota") + noun_aliases+=("rc") + noun_aliases+=("replicasets") + noun_aliases+=("replicationcontrollers") + noun_aliases+=("resourcequotas") + noun_aliases+=("rs") + noun_aliases+=("sa") + noun_aliases+=("secrets") + noun_aliases+=("serviceaccounts") + noun_aliases+=("services") + noun_aliases+=("svc") + noun_aliases+=("thirdpartyresourcedatas") + noun_aliases+=("thirdpartyresources") } _kubectl_apply() diff --git a/pkg/kubectl/cmd/cmd.go b/pkg/kubectl/cmd/cmd.go index 3b716f2be98..477ac6112d3 100644 --- a/pkg/kubectl/cmd/cmd.go +++ b/pkg/kubectl/cmd/cmd.go @@ -124,7 +124,7 @@ __kubectl_require_pod_and_container() __custom_func() { case ${last_command} in - kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop) + kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop | kubectl_edit) __kubectl_get_resource return ;; diff --git a/pkg/kubectl/cmd/edit.go b/pkg/kubectl/cmd/edit.go index abfa32b00b8..e9fe583658a 100644 --- a/pkg/kubectl/cmd/edit.go +++ b/pkg/kubectl/cmd/edit.go @@ -86,6 +86,15 @@ var errExit = fmt.Errorf("exit directly") func NewCmdEdit(f *cmdutil.Factory, out, errOut io.Writer) *cobra.Command { options := &EditOptions{} + // retrieve a list of handled resources from printer as valid args + validArgs, argAliases := []string{}, []string{} + p, err := f.Printer(nil, false, false, false, false, false, false, []string{}) + cmdutil.CheckErr(err) + if p != nil { + validArgs = p.HandledResources() + argAliases = kubectl.ResourceAliases(validArgs) + } + cmd := &cobra.Command{ Use: "edit (RESOURCE/NAME | -f FILENAME)", Short: "Edit a resource on the server", @@ -98,6 +107,8 @@ func NewCmdEdit(f *cmdutil.Factory, out, errOut io.Writer) *cobra.Command { } cmdutil.CheckErr(err) }, + ValidArgs: validArgs, + ArgAliases: argAliases, } usage := "Filename, directory, or URL to file to use to edit the resource" kubectl.AddJsonFilenameFlag(cmd, &options.Filenames, usage) From 910b6bce3399c27ecb477a351d2e5bfc5b3ef3ed Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Sun, 3 Apr 2016 15:57:51 +0900 Subject: [PATCH 2/4] Update bashcompletion codes for kubectl patch --- contrib/completions/bash/kubectl | 69 +++++++++++++++++++++++++++++++- pkg/kubectl/cmd/cmd.go | 2 +- pkg/kubectl/cmd/patch.go | 11 +++++ 3 files changed, 80 insertions(+), 2 deletions(-) diff --git a/contrib/completions/bash/kubectl b/contrib/completions/bash/kubectl index 8944f93bacc..af557c43a6c 100644 --- a/contrib/completions/bash/kubectl +++ b/contrib/completions/bash/kubectl @@ -313,7 +313,7 @@ __kubectl_require_pod_and_container() __custom_func() { case ${last_command} in - kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop) + kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop | kubectl_edit | kubectl_patch) __kubectl_get_resource return ;; @@ -1144,7 +1144,74 @@ _kubectl_patch() must_have_one_flag+=("--patch=") must_have_one_flag+=("-p") must_have_one_noun=() + must_have_one_noun+=("componentstatus") + must_have_one_noun+=("configmap") + must_have_one_noun+=("daemonset") + must_have_one_noun+=("deployment") + must_have_one_noun+=("endpoints") + must_have_one_noun+=("event") + must_have_one_noun+=("horizontalpodautoscaler") + must_have_one_noun+=("ingress") + must_have_one_noun+=("job") + must_have_one_noun+=("limitrange") + must_have_one_noun+=("namespace") + must_have_one_noun+=("node") + must_have_one_noun+=("persistentvolume") + must_have_one_noun+=("persistentvolumeclaim") + must_have_one_noun+=("pod") + must_have_one_noun+=("podsecuritypolicy") + must_have_one_noun+=("podtemplate") + must_have_one_noun+=("replicaset") + must_have_one_noun+=("replicationcontroller") + must_have_one_noun+=("resourcequota") + must_have_one_noun+=("secret") + must_have_one_noun+=("service") + must_have_one_noun+=("serviceaccount") + must_have_one_noun+=("thirdpartyresource") + must_have_one_noun+=("thirdpartyresourcedata") noun_aliases=() + noun_aliases+=("componentstatuses") + noun_aliases+=("configmaps") + noun_aliases+=("cs") + noun_aliases+=("daemonsets") + noun_aliases+=("deployments") + noun_aliases+=("ds") + noun_aliases+=("endpoints") + noun_aliases+=("ep") + noun_aliases+=("ev") + noun_aliases+=("events") + noun_aliases+=("horizontalpodautoscalers") + noun_aliases+=("hpa") + noun_aliases+=("ing") + noun_aliases+=("ingresses") + noun_aliases+=("jobs") + noun_aliases+=("limitranges") + noun_aliases+=("limits") + noun_aliases+=("namespaces") + noun_aliases+=("no") + noun_aliases+=("nodes") + noun_aliases+=("ns") + noun_aliases+=("persistentvolumeclaims") + noun_aliases+=("persistentvolumes") + noun_aliases+=("po") + noun_aliases+=("pods") + noun_aliases+=("podsecuritypolicies") + noun_aliases+=("podtemplates") + noun_aliases+=("pv") + noun_aliases+=("pvc") + noun_aliases+=("quota") + noun_aliases+=("rc") + noun_aliases+=("replicasets") + noun_aliases+=("replicationcontrollers") + noun_aliases+=("resourcequotas") + noun_aliases+=("rs") + noun_aliases+=("sa") + noun_aliases+=("secrets") + noun_aliases+=("serviceaccounts") + noun_aliases+=("services") + noun_aliases+=("svc") + noun_aliases+=("thirdpartyresourcedatas") + noun_aliases+=("thirdpartyresources") } _kubectl_delete() diff --git a/pkg/kubectl/cmd/cmd.go b/pkg/kubectl/cmd/cmd.go index 477ac6112d3..df358a73f6d 100644 --- a/pkg/kubectl/cmd/cmd.go +++ b/pkg/kubectl/cmd/cmd.go @@ -124,7 +124,7 @@ __kubectl_require_pod_and_container() __custom_func() { case ${last_command} in - kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop | kubectl_edit) + kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop | kubectl_edit | kubectl_patch) __kubectl_get_resource return ;; diff --git a/pkg/kubectl/cmd/patch.go b/pkg/kubectl/cmd/patch.go index 093a82543ff..ad07ecac137 100644 --- a/pkg/kubectl/cmd/patch.go +++ b/pkg/kubectl/cmd/patch.go @@ -63,6 +63,15 @@ kubectl patch pod valid-pod -type='json' -p='[{"op": "replace", "path": "/spec/c func NewCmdPatch(f *cmdutil.Factory, out io.Writer) *cobra.Command { options := &PatchOptions{} + // retrieve a list of handled resources from printer as valid args + validArgs, argAliases := []string{}, []string{} + p, err := f.Printer(nil, false, false, false, false, false, false, []string{}) + cmdutil.CheckErr(err) + if p != nil { + validArgs = p.HandledResources() + argAliases = kubectl.ResourceAliases(validArgs) + } + cmd := &cobra.Command{ Use: "patch (-f FILENAME | TYPE NAME) -p PATCH", Short: "Update field(s) of a resource using strategic merge patch.", @@ -74,6 +83,8 @@ func NewCmdPatch(f *cmdutil.Factory, out io.Writer) *cobra.Command { err := RunPatch(f, out, cmd, args, shortOutput, options) cmdutil.CheckErr(err) }, + ValidArgs: validArgs, + ArgAliases: argAliases, } cmd.Flags().StringP("patch", "p", "", "The patch to be applied to the resource JSON file.") cmd.MarkFlagRequired("patch") From 84e3ee8ec49fb38505a75e4a9d47a87724b52988 Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Sun, 3 Apr 2016 19:13:51 +0900 Subject: [PATCH 3/4] Update bashcompletion codes for kubectl annotate --- contrib/completions/bash/kubectl | 38 ++++++++++++++++++++- docs/man/man1/kubectl-annotate.1 | 9 ++--- docs/user-guide/kubectl/kubectl_annotate.md | 12 ++++--- pkg/kubectl/cmd/annotate.go | 23 ++++++++++--- pkg/kubectl/cmd/cmd.go | 3 +- 5 files changed, 70 insertions(+), 15 deletions(-) diff --git a/contrib/completions/bash/kubectl b/contrib/completions/bash/kubectl index af557c43a6c..c2b5a9fce0a 100644 --- a/contrib/completions/bash/kubectl +++ b/contrib/completions/bash/kubectl @@ -313,7 +313,8 @@ __kubectl_require_pod_and_container() __custom_func() { case ${last_command} in - kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop | kubectl_edit | kubectl_patch) + kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop | kubectl_edit | kubectl_patch |\ + kubectl_annotate) __kubectl_get_resource return ;; @@ -2782,7 +2783,42 @@ _kubectl_annotate() must_have_one_flag=() must_have_one_noun=() + must_have_one_noun+=("componentstatuse") + must_have_one_noun+=("event") + must_have_one_noun+=("horizontalpodautoscaler") + must_have_one_noun+=("limitrange") + must_have_one_noun+=("node") + must_have_one_noun+=("persistentvolume") + must_have_one_noun+=("persistentvolumeclaim") + must_have_one_noun+=("pod") + must_have_one_noun+=("replicationcontroller") + must_have_one_noun+=("resourcequota") + must_have_one_noun+=("secret") + must_have_one_noun+=("service") noun_aliases=() + noun_aliases+=("componentstatuses") + noun_aliases+=("cs") + noun_aliases+=("ev") + noun_aliases+=("events") + noun_aliases+=("horizontalpodautoscalers") + noun_aliases+=("hpa") + noun_aliases+=("limitranges") + noun_aliases+=("limits") + noun_aliases+=("no") + noun_aliases+=("nodes") + noun_aliases+=("persistentvolumeclaims") + noun_aliases+=("persistentvolumes") + noun_aliases+=("po") + noun_aliases+=("pods") + noun_aliases+=("pv") + noun_aliases+=("pvc") + noun_aliases+=("quota") + noun_aliases+=("rc") + noun_aliases+=("replicationcontrollers") + noun_aliases+=("resourcequotas") + noun_aliases+=("secrets") + noun_aliases+=("services") + noun_aliases+=("svc") } _kubectl_config_view() diff --git a/docs/man/man1/kubectl-annotate.1 b/docs/man/man1/kubectl-annotate.1 index 0cf2dd3d055..29c2347f68a 100644 --- a/docs/man/man1/kubectl-annotate.1 +++ b/docs/man/man1/kubectl-annotate.1 @@ -22,10 +22,11 @@ If \-\-overwrite is true, then existing annotations can be overwritten, otherwis If \-\-resource\-version is specified, then updates will use this resource version, otherwise the existing resource\-version will be used. .PP -Possible resources include (case insensitive): pods (po), services (svc), -replicationcontrollers (rc), nodes (no), events (ev), componentstatuses (cs), -limitranges (limits), persistentvolumes (pv), persistentvolumeclaims (pvc), -horizontalpodautoscalers (hpa), resourcequotas (quota) or secrets. +Possible resources include (case insensitive): + pod (po), service (svc), replicationcontroller (rc), + node (no), event (ev), componentstatuse (cs), + limitrange (limits), persistentvolume (pv), persistentvolumeclaim (pvc), + horizontalpodautoscaler (hpa), resourcequota (quota), secret .SH OPTIONS diff --git a/docs/user-guide/kubectl/kubectl_annotate.md b/docs/user-guide/kubectl/kubectl_annotate.md index 31398b92359..9ebafe833c3 100644 --- a/docs/user-guide/kubectl/kubectl_annotate.md +++ b/docs/user-guide/kubectl/kubectl_annotate.md @@ -46,10 +46,12 @@ It is intended to store non-identifying auxiliary data, especially data manipula If --overwrite is true, then existing annotations can be overwritten, otherwise attempting to overwrite an annotation will result in an error. If --resource-version is specified, then updates will use this resource version, otherwise the existing resource-version will be used. -Possible resources include (case insensitive): pods (po), services (svc), -replicationcontrollers (rc), nodes (no), events (ev), componentstatuses (cs), -limitranges (limits), persistentvolumes (pv), persistentvolumeclaims (pvc), -horizontalpodautoscalers (hpa), resourcequotas (quota) or secrets. +Possible resources include (case insensitive): + pod (po), service (svc), replicationcontroller (rc), + node (no), event (ev), componentstatuse (cs), + limitrange (limits), persistentvolume (pv), persistentvolumeclaim (pvc), + horizontalpodautoscaler (hpa), resourcequota (quota), secret + ``` kubectl annotate [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version] @@ -130,7 +132,7 @@ kubectl annotate pods foo description- * [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager -###### Auto generated by spf13/cobra on 30-Mar-2016 +###### Auto generated by spf13/cobra on 10-Apr-2016 [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_annotate.md?pixel)]() diff --git a/pkg/kubectl/cmd/annotate.go b/pkg/kubectl/cmd/annotate.go index 9177559b32b..3a081ad2d43 100644 --- a/pkg/kubectl/cmd/annotate.go +++ b/pkg/kubectl/cmd/annotate.go @@ -21,6 +21,7 @@ import ( "encoding/json" "fmt" "io" + "regexp" "strings" "github.com/golang/glog" @@ -58,6 +59,13 @@ type AnnotateOptions struct { } const ( + annotate_resources = ` + pod (po), service (svc), replicationcontroller (rc), + node (no), event (ev), componentstatuse (cs), + limitrange (limits), persistentvolume (pv), persistentvolumeclaim (pvc), + horizontalpodautoscaler (hpa), resourcequota (quota), secret +` + annotate_long = `Update the annotations on one or more resources. An annotation is a key/value pair that can hold larger (compared to a label), and possibly not human-readable, data. @@ -65,10 +73,8 @@ It is intended to store non-identifying auxiliary data, especially data manipula If --overwrite is true, then existing annotations can be overwritten, otherwise attempting to overwrite an annotation will result in an error. If --resource-version is specified, then updates will use this resource version, otherwise the existing resource-version will be used. -Possible resources include (case insensitive): pods (po), services (svc), -replicationcontrollers (rc), nodes (no), events (ev), componentstatuses (cs), -limitranges (limits), persistentvolumes (pv), persistentvolumeclaims (pvc), -horizontalpodautoscalers (hpa), resourcequotas (quota) or secrets.` +Possible resources include (case insensitive):` + annotate_resources + annotate_example = `# Update pod 'foo' with the annotation 'description' and the value 'my frontend'. # If the same annotation is set multiple times, only the last value will be applied kubectl annotate pods foo description='my frontend' @@ -93,6 +99,13 @@ kubectl annotate pods foo description-` func NewCmdAnnotate(f *cmdutil.Factory, out io.Writer) *cobra.Command { options := &AnnotateOptions{} + validArgs, argAliases := []string{}, []string{} + resources := regexp.MustCompile(`\s*,`).Split(annotate_resources, -1) + for _, r := range resources { + validArgs = append(validArgs, strings.Fields(r)[0]) + argAliases = kubectl.ResourceAliases(validArgs) + } + cmd := &cobra.Command{ Use: "annotate [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]", Short: "Update the annotations on a resource", @@ -109,6 +122,8 @@ func NewCmdAnnotate(f *cmdutil.Factory, out io.Writer) *cobra.Command { cmdutil.CheckErr(err) } }, + ValidArgs: validArgs, + ArgAliases: argAliases, } cmdutil.AddPrinterFlags(cmd) cmdutil.AddInclude3rdPartyFlags(cmd) diff --git a/pkg/kubectl/cmd/cmd.go b/pkg/kubectl/cmd/cmd.go index df358a73f6d..68003be44e9 100644 --- a/pkg/kubectl/cmd/cmd.go +++ b/pkg/kubectl/cmd/cmd.go @@ -124,7 +124,8 @@ __kubectl_require_pod_and_container() __custom_func() { case ${last_command} in - kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop | kubectl_edit | kubectl_patch) + kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop | kubectl_edit | kubectl_patch |\ + kubectl_annotate) __kubectl_get_resource return ;; From c9d34870ed8970fe5c9f5a58562a3a67f758cfef Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Sun, 3 Apr 2016 19:44:35 +0900 Subject: [PATCH 4/4] Update bashcompletion codes for kubectl expose --- contrib/completions/bash/kubectl | 16 +++++++++++++++- docs/man/man1/kubectl-expose.1 | 7 ++++++- docs/user-guide/kubectl/kubectl_expose.md | 9 +++++++-- pkg/kubectl/cmd/cmd.go | 2 +- pkg/kubectl/cmd/expose.go | 21 +++++++++++++++++++-- 5 files changed, 48 insertions(+), 7 deletions(-) diff --git a/contrib/completions/bash/kubectl b/contrib/completions/bash/kubectl index c2b5a9fce0a..241f7a2c85a 100644 --- a/contrib/completions/bash/kubectl +++ b/contrib/completions/bash/kubectl @@ -314,7 +314,7 @@ __kubectl_require_pod_and_container() __custom_func() { case ${last_command} in kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop | kubectl_edit | kubectl_patch |\ - kubectl_annotate) + kubectl_annotate | kubectl_expose) __kubectl_get_resource return ;; @@ -2251,7 +2251,21 @@ _kubectl_expose() must_have_one_flag=() must_have_one_noun=() + must_have_one_noun+=("deployment") + must_have_one_noun+=("pod") + must_have_one_noun+=("replicaset") + must_have_one_noun+=("replicationcontroller") + must_have_one_noun+=("service") noun_aliases=() + noun_aliases+=("deployments") + noun_aliases+=("po") + noun_aliases+=("pods") + noun_aliases+=("rc") + noun_aliases+=("replicasets") + noun_aliases+=("replicationcontrollers") + noun_aliases+=("rs") + noun_aliases+=("services") + noun_aliases+=("svc") } _kubectl_autoscale() diff --git a/docs/man/man1/kubectl-expose.1 b/docs/man/man1/kubectl-expose.1 index 6c3a3df40bf..e30e210a5f5 100644 --- a/docs/man/man1/kubectl-expose.1 +++ b/docs/man/man1/kubectl-expose.1 @@ -13,7 +13,7 @@ kubectl expose \- Take a replication controller, service, deployment or pod and .SH DESCRIPTION .PP -Take a deployment, service, replica set, replication controller, or pod and expose it as a new Kubernetes service. +Expose a resource as a new Kubernetes service. .PP Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector @@ -23,6 +23,11 @@ i.e. when the selector contains only the matchLabels component. Note that if no \-\-port and the exposed resource has multiple ports, all will be re\-used by the new service. Also if no labels are specified, the new service will re\-use the labels from the resource it exposes. +.PP +Possible resources include (case insensitive): + pod (po), service (svc), replicationcontroller (rc), + deployment, replicaset (rs) + .SH OPTIONS .PP diff --git a/docs/user-guide/kubectl/kubectl_expose.md b/docs/user-guide/kubectl/kubectl_expose.md index ef0f723a328..feca1eadec4 100644 --- a/docs/user-guide/kubectl/kubectl_expose.md +++ b/docs/user-guide/kubectl/kubectl_expose.md @@ -39,7 +39,7 @@ Take a replication controller, service, deployment or pod and expose it as a new ### Synopsis -Take a deployment, service, replica set, replication controller, or pod and expose it as a new Kubernetes service. +Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A deployment or replica set @@ -48,6 +48,11 @@ i.e. when the selector contains only the matchLabels component. Note that if no --port and the exposed resource has multiple ports, all will be re-used by the new service. Also if no labels are specified, the new service will re-use the labels from the resource it exposes. +Possible resources include (case insensitive): + pod (po), service (svc), replicationcontroller (rc), + deployment, replicaset (rs) + + ``` kubectl expose (-f FILENAME | TYPE NAME) [--port=port] [--protocol=TCP|UDP] [--target-port=number-or-name] [--name=name] [--external-ip=external-ip-of-service] [--type=type] ``` @@ -138,7 +143,7 @@ kubectl expose deployment nginx --port=80 --target-port=8000 * [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager -###### Auto generated by spf13/cobra on 30-Mar-2016 +###### Auto generated by spf13/cobra on 10-Apr-2016 [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_expose.md?pixel)]() diff --git a/pkg/kubectl/cmd/cmd.go b/pkg/kubectl/cmd/cmd.go index 68003be44e9..2ed149f5e5f 100644 --- a/pkg/kubectl/cmd/cmd.go +++ b/pkg/kubectl/cmd/cmd.go @@ -125,7 +125,7 @@ __kubectl_require_pod_and_container() __custom_func() { case ${last_command} in kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop | kubectl_edit | kubectl_patch |\ - kubectl_annotate) + kubectl_annotate | kubectl_expose) __kubectl_get_resource return ;; diff --git a/pkg/kubectl/cmd/expose.go b/pkg/kubectl/cmd/expose.go index 6a7e804fc12..c2937583b1c 100644 --- a/pkg/kubectl/cmd/expose.go +++ b/pkg/kubectl/cmd/expose.go @@ -19,6 +19,7 @@ package cmd import ( "fmt" "io" + "regexp" "strings" "github.com/spf13/cobra" @@ -38,14 +39,21 @@ type ExposeOptions struct { } const ( - expose_long = `Take a deployment, service, replica set, replication controller, or pod and expose it as a new Kubernetes service. + expose_resources = ` + pod (po), service (svc), replicationcontroller (rc), + deployment, replicaset (rs) +` + + expose_long = `Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A deployment or replica set will be exposed as a service only if its selector is convertible to a selector that service supports, i.e. when the selector contains only the matchLabels component. Note that if no port is specified via --port and the exposed resource has multiple ports, all will be re-used by the new service. Also if no -labels are specified, the new service will re-use the labels from the resource it exposes.` +labels are specified, the new service will re-use the labels from the resource it exposes. + +Possible resources include (case insensitive):` + expose_resources expose_example = `# Create a service for a replicated nginx, which serves on port 80 and connects to the containers on port 8000. kubectl expose rc nginx --port=80 --target-port=8000 @@ -72,6 +80,13 @@ kubectl expose deployment nginx --port=80 --target-port=8000` func NewCmdExposeService(f *cmdutil.Factory, out io.Writer) *cobra.Command { options := &ExposeOptions{} + validArgs, argAliases := []string{}, []string{} + resources := regexp.MustCompile(`\s*,`).Split(expose_resources, -1) + for _, r := range resources { + validArgs = append(validArgs, strings.Fields(r)[0]) + argAliases = kubectl.ResourceAliases(validArgs) + } + cmd := &cobra.Command{ Use: "expose (-f FILENAME | TYPE NAME) [--port=port] [--protocol=TCP|UDP] [--target-port=number-or-name] [--name=name] [--external-ip=external-ip-of-service] [--type=type]", Short: "Take a replication controller, service, deployment or pod and expose it as a new Kubernetes Service", @@ -81,6 +96,8 @@ func NewCmdExposeService(f *cmdutil.Factory, out io.Writer) *cobra.Command { err := RunExpose(f, out, cmd, args, options) cmdutil.CheckErr(err) }, + ValidArgs: validArgs, + ArgAliases: argAliases, } cmdutil.AddPrinterFlags(cmd) cmd.Flags().String("generator", "service/v2", "The name of the API generator to use. There are 2 generators: 'service/v1' and 'service/v2'. The only difference between them is that service port in v1 is named 'default', while it is left unnamed in v2. Default is 'service/v2'.")