diff --git a/docs/.generated_docs b/docs/.generated_docs index 6068315a6e9..d1b300e84a1 100644 --- a/docs/.generated_docs +++ b/docs/.generated_docs @@ -10,6 +10,7 @@ docs/man/man1/kube-apiserver.1 docs/man/man1/kube-controller-manager.1 docs/man/man1/kube-proxy.1 docs/man/man1/kube-scheduler.1 +docs/man/man1/kubectl-alpha.1 docs/man/man1/kubectl-annotate.1 docs/man/man1/kubectl-api-versions.1 docs/man/man1/kubectl-apply-set-last-applied.1 @@ -189,6 +190,7 @@ docs/user-guide/kubectl/kubectl_top_pod.md docs/user-guide/kubectl/kubectl_uncordon.md docs/user-guide/kubectl/kubectl_version.md docs/yaml/kubectl/kubectl.yaml +docs/yaml/kubectl/kubectl_alpha.yaml docs/yaml/kubectl/kubectl_annotate.yaml docs/yaml/kubectl/kubectl_api-versions.yaml docs/yaml/kubectl/kubectl_apply.yaml diff --git a/docs/man/man1/kubectl-alpha.1 b/docs/man/man1/kubectl-alpha.1 new file mode 100644 index 00000000000..b6fd7a0f989 --- /dev/null +++ b/docs/man/man1/kubectl-alpha.1 @@ -0,0 +1,3 @@ +This file is autogenerated, but we've stopped checking such files into the +repository to reduce the need for rebases. Please run hack/generate-docs.sh to +populate this file. diff --git a/docs/yaml/kubectl/kubectl_alpha.yaml b/docs/yaml/kubectl/kubectl_alpha.yaml new file mode 100644 index 00000000000..b6fd7a0f989 --- /dev/null +++ b/docs/yaml/kubectl/kubectl_alpha.yaml @@ -0,0 +1,3 @@ +This file is autogenerated, but we've stopped checking such files into the +repository to reduce the need for rebases. Please run hack/generate-docs.sh to +populate this file. diff --git a/pkg/kubectl/cmd/BUILD b/pkg/kubectl/cmd/BUILD index 195c1c5d700..7c35d08598e 100644 --- a/pkg/kubectl/cmd/BUILD +++ b/pkg/kubectl/cmd/BUILD @@ -9,6 +9,7 @@ load( go_library( name = "go_default_library", srcs = [ + "alpha.go", "annotate.go", "apiversions.go", "apply.go", diff --git a/pkg/kubectl/cmd/alpha.go b/pkg/kubectl/cmd/alpha.go new file mode 100644 index 00000000000..60fa03130d9 --- /dev/null +++ b/pkg/kubectl/cmd/alpha.go @@ -0,0 +1,50 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cmd + +import ( + "io" + + "github.com/spf13/cobra" + + "k8s.io/kubernetes/pkg/kubectl/cmd/templates" + cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" + "k8s.io/kubernetes/pkg/util/i18n" +) + +// NewCmdAlpha creates a command that acts as an alternate root command for features in alpha +func NewCmdAlpha(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cobra.Command { + cmd := &cobra.Command{ + Use: "alpha", + Short: i18n.T("Commands for features in alpha"), + Long: templates.LongDesc(i18n.T("These commands correspond to alpha features that are not enabled in Kubernetes clusters by default.")), + } + + // Alpha commands should be added here. As features graduate from alpha they should move + // from here to the CommandGroups defined by NewKubeletCommand() in cmd.go. + //cmd.AddCommand(NewCmdDebug(f, in, out, err)) + + // NewKubeletCommand() will hide the alpha command if it has no subcommands. Overriding + // the help function ensures a reasonable message if someone types the hidden command anyway. + if !cmd.HasSubCommands() { + cmd.SetHelpFunc(func(*cobra.Command, []string) { + cmd.Println(i18n.T("No alpha commands are available in this version of kubectl")) + }) + } + + return cmd +} diff --git a/pkg/kubectl/cmd/cmd.go b/pkg/kubectl/cmd/cmd.go index 21087c8a456..da90ac23cb1 100644 --- a/pkg/kubectl/cmd/cmd.go +++ b/pkg/kubectl/cmd/cmd.go @@ -354,6 +354,13 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob "options", Deprecated("kubectl", "delete", cmds, NewCmdStop(f, out)), } + + // Hide the "alpha" subcommand if there are no alpha commands in this build. + alpha := NewCmdAlpha(f, in, out, err) + if !alpha.HasSubCommands() { + filters = append(filters, alpha.Name()) + } + templates.ActsAsRootCommand(cmds, filters, groups...) for name, completion := range bash_completion_flags { @@ -368,6 +375,7 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob } } + cmds.AddCommand(alpha) cmds.AddCommand(cmdconfig.NewCmdConfig(clientcmd.NewDefaultPathOptions(), out, err)) cmds.AddCommand(NewCmdPlugin(f, in, out, err)) cmds.AddCommand(NewCmdVersion(f, out))