Merge pull request #102049 from navist2020/kubectl/notUseParam
Kubectl:remove Factory that not used Kubernetes-commit: 60e4be3151c2aec4919e9ab287aa9edb4b2e0ca0
This commit is contained in:
commit
a66725a1e1
12
go.mod
12
go.mod
|
@ -31,10 +31,10 @@ require (
|
||||||
github.com/stretchr/testify v1.7.0
|
github.com/stretchr/testify v1.7.0
|
||||||
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22
|
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
gopkg.in/yaml.v2 v2.4.0
|
||||||
k8s.io/api v0.0.0-20210708014407-1e1dad4bd9d1
|
k8s.io/api v0.0.0-20210708214500-0ff29d3f16e4
|
||||||
k8s.io/apimachinery v0.0.0-20210708014216-0dafcb48b31e
|
k8s.io/apimachinery v0.0.0-20210708214246-ff522ab81c74
|
||||||
k8s.io/cli-runtime v0.0.0-20210708100424-f7c3433b9975
|
k8s.io/cli-runtime v0.0.0-20210708100424-f7c3433b9975
|
||||||
k8s.io/client-go v0.0.0-20210708094636-69e00b04ba4c
|
k8s.io/client-go v0.0.0-20210708214809-f0bc45ffb439
|
||||||
k8s.io/component-base v0.0.0-20210708095030-632996df852a
|
k8s.io/component-base v0.0.0-20210708095030-632996df852a
|
||||||
k8s.io/component-helpers v0.0.0-20210708095128-55a3896515e9
|
k8s.io/component-helpers v0.0.0-20210708095128-55a3896515e9
|
||||||
k8s.io/klog/v2 v2.9.0
|
k8s.io/klog/v2 v2.9.0
|
||||||
|
@ -47,10 +47,10 @@ require (
|
||||||
)
|
)
|
||||||
|
|
||||||
replace (
|
replace (
|
||||||
k8s.io/api => k8s.io/api v0.0.0-20210708014407-1e1dad4bd9d1
|
k8s.io/api => k8s.io/api v0.0.0-20210708214500-0ff29d3f16e4
|
||||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20210708014216-0dafcb48b31e
|
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20210708214246-ff522ab81c74
|
||||||
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20210708100424-f7c3433b9975
|
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20210708100424-f7c3433b9975
|
||||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20210708094636-69e00b04ba4c
|
k8s.io/client-go => k8s.io/client-go v0.0.0-20210708214809-f0bc45ffb439
|
||||||
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20210708071253-ee3ba0fad71e
|
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20210708071253-ee3ba0fad71e
|
||||||
k8s.io/component-base => k8s.io/component-base v0.0.0-20210708095030-632996df852a
|
k8s.io/component-base => k8s.io/component-base v0.0.0-20210708095030-632996df852a
|
||||||
k8s.io/component-helpers => k8s.io/component-helpers v0.0.0-20210708095128-55a3896515e9
|
k8s.io/component-helpers => k8s.io/component-helpers v0.0.0-20210708095128-55a3896515e9
|
||||||
|
|
12
go.sum
12
go.sum
|
@ -737,14 +737,14 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh
|
||||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||||
k8s.io/api v0.0.0-20210708014407-1e1dad4bd9d1 h1:BsVbhrF9ZXWlpo/84y3WdGGw+SYu61RlNKOMqGKDIQE=
|
k8s.io/api v0.0.0-20210708214500-0ff29d3f16e4 h1:SONTS5tRMTV7iWmw9T6C7vsEFrQy4bygwu/PaUJP2Lo=
|
||||||
k8s.io/api v0.0.0-20210708014407-1e1dad4bd9d1/go.mod h1:UGtjmHCgj1IMXqa0rRAXNNszZBo1IKpAhbvSre33vSU=
|
k8s.io/api v0.0.0-20210708214500-0ff29d3f16e4/go.mod h1:72i8FbvEsYM9+Hy9ZRCr4WADf5G8kTsusBNrcSkt2aY=
|
||||||
k8s.io/apimachinery v0.0.0-20210708014216-0dafcb48b31e h1:EZ+ZrcPtnkR8vVo7bBSwoMD9a0HaC29O6lJhcZgwsJQ=
|
k8s.io/apimachinery v0.0.0-20210708214246-ff522ab81c74 h1:Daxg4VCqUpkKuMJjia7XcVVDHnPjH6IeKb7jcZDcQUM=
|
||||||
k8s.io/apimachinery v0.0.0-20210708014216-0dafcb48b31e/go.mod h1:O3oNtNadZdeOMxHFVxOreoznohCpy0z6mocxbZr7oJ0=
|
k8s.io/apimachinery v0.0.0-20210708214246-ff522ab81c74/go.mod h1:O3oNtNadZdeOMxHFVxOreoznohCpy0z6mocxbZr7oJ0=
|
||||||
k8s.io/cli-runtime v0.0.0-20210708100424-f7c3433b9975 h1:0PtzYqhVBCUKi/XvmanrSTIcfsWg1t5VVgJ/Yx25CMM=
|
k8s.io/cli-runtime v0.0.0-20210708100424-f7c3433b9975 h1:0PtzYqhVBCUKi/XvmanrSTIcfsWg1t5VVgJ/Yx25CMM=
|
||||||
k8s.io/cli-runtime v0.0.0-20210708100424-f7c3433b9975/go.mod h1:vBIJsdwtI2UT9JES/vOvvOQ+D0cmTCtsG25Hm45AuKw=
|
k8s.io/cli-runtime v0.0.0-20210708100424-f7c3433b9975/go.mod h1:vBIJsdwtI2UT9JES/vOvvOQ+D0cmTCtsG25Hm45AuKw=
|
||||||
k8s.io/client-go v0.0.0-20210708094636-69e00b04ba4c h1:bm2mq36WyGKROFmZlbM7pjKGB+lMtClCABatAi2olrg=
|
k8s.io/client-go v0.0.0-20210708214809-f0bc45ffb439 h1:/KWGV2YkMr96+/rRzrRkhI4bvzwS8NixKg3ElVoFAws=
|
||||||
k8s.io/client-go v0.0.0-20210708094636-69e00b04ba4c/go.mod h1:gdC8LfT2kw5hm9VcRUqlVkMMkbfYIxDWvPITF7hl7K8=
|
k8s.io/client-go v0.0.0-20210708214809-f0bc45ffb439/go.mod h1:sf6aX4lO8AyErF5l4A2Aa//yf44Xb5ghYUCNLRBLOKk=
|
||||||
k8s.io/code-generator v0.0.0-20210708071253-ee3ba0fad71e/go.mod h1:eV77Y09IopzeXOJzndrDyCI88UBok2h6WxAlBwpxa+o=
|
k8s.io/code-generator v0.0.0-20210708071253-ee3ba0fad71e/go.mod h1:eV77Y09IopzeXOJzndrDyCI88UBok2h6WxAlBwpxa+o=
|
||||||
k8s.io/component-base v0.0.0-20210708095030-632996df852a h1:PRk5Hh5WlaBfH5IjtoqNeL1Waqillce5m2p7RuvOeqA=
|
k8s.io/component-base v0.0.0-20210708095030-632996df852a h1:PRk5Hh5WlaBfH5IjtoqNeL1Waqillce5m2p7RuvOeqA=
|
||||||
k8s.io/component-base v0.0.0-20210708095030-632996df852a/go.mod h1:LBVnEifw+SvQx2si1RCpd0WVE198EULnwqnMg0QBBQQ=
|
k8s.io/component-base v0.0.0-20210708095030-632996df852a/go.mod h1:LBVnEifw+SvQx2si1RCpd0WVE198EULnwqnMg0QBBQQ=
|
||||||
|
|
|
@ -20,13 +20,12 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
|
||||||
"k8s.io/kubectl/pkg/util/i18n"
|
"k8s.io/kubectl/pkg/util/i18n"
|
||||||
"k8s.io/kubectl/pkg/util/templates"
|
"k8s.io/kubectl/pkg/util/templates"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCmdAlpha creates a command that acts as an alternate root command for features in alpha
|
// NewCmdAlpha creates a command that acts as an alternate root command for features in alpha
|
||||||
func NewCmdAlpha(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
|
func NewCmdAlpha(streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "alpha",
|
Use: "alpha",
|
||||||
Short: i18n.T("Commands for features in alpha"),
|
Short: i18n.T("Commands for features in alpha"),
|
||||||
|
|
|
@ -374,7 +374,7 @@ func NewKubectlCommand(in io.Reader, out, err io.Writer) *cobra.Command {
|
||||||
filters := []string{"options"}
|
filters := []string{"options"}
|
||||||
|
|
||||||
// Hide the "alpha" subcommand if there are no alpha commands in this build.
|
// Hide the "alpha" subcommand if there are no alpha commands in this build.
|
||||||
alpha := NewCmdAlpha(f, ioStreams)
|
alpha := NewCmdAlpha(ioStreams)
|
||||||
if !alpha.HasSubCommands() {
|
if !alpha.HasSubCommands() {
|
||||||
filters = append(filters, alpha.Name())
|
filters = append(filters, alpha.Name())
|
||||||
}
|
}
|
||||||
|
@ -385,8 +385,8 @@ func NewKubectlCommand(in io.Reader, out, err io.Writer) *cobra.Command {
|
||||||
registerCompletionFuncForGlobalFlags(cmds, f)
|
registerCompletionFuncForGlobalFlags(cmds, f)
|
||||||
|
|
||||||
cmds.AddCommand(alpha)
|
cmds.AddCommand(alpha)
|
||||||
cmds.AddCommand(cmdconfig.NewCmdConfig(f, clientcmd.NewDefaultPathOptions(), ioStreams))
|
cmds.AddCommand(cmdconfig.NewCmdConfig(clientcmd.NewDefaultPathOptions(), ioStreams))
|
||||||
cmds.AddCommand(plugin.NewCmdPlugin(f, ioStreams))
|
cmds.AddCommand(plugin.NewCmdPlugin(ioStreams))
|
||||||
cmds.AddCommand(version.NewCmdVersion(f, ioStreams))
|
cmds.AddCommand(version.NewCmdVersion(f, ioStreams))
|
||||||
cmds.AddCommand(apiresources.NewCmdAPIVersions(f, ioStreams))
|
cmds.AddCommand(apiresources.NewCmdAPIVersions(f, ioStreams))
|
||||||
cmds.AddCommand(apiresources.NewCmdAPIResources(f, ioStreams))
|
cmds.AddCommand(apiresources.NewCmdAPIResources(f, ioStreams))
|
||||||
|
|
|
@ -31,7 +31,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCmdConfig creates a command object for the "config" action, and adds all child commands to it.
|
// NewCmdConfig creates a command object for the "config" action, and adds all child commands to it.
|
||||||
func NewCmdConfig(f cmdutil.Factory, pathOptions *clientcmd.PathOptions, streams genericclioptions.IOStreams) *cobra.Command {
|
func NewCmdConfig(pathOptions *clientcmd.PathOptions, streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
if len(pathOptions.ExplicitFileFlag) == 0 {
|
if len(pathOptions.ExplicitFileFlag) == 0 {
|
||||||
pathOptions.ExplicitFileFlag = clientcmd.RecommendedConfigPathFlag
|
pathOptions.ExplicitFileFlag = clientcmd.RecommendedConfigPathFlag
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ func NewCmdConfig(f cmdutil.Factory, pathOptions *clientcmd.PathOptions, streams
|
||||||
cmd.PersistentFlags().StringVar(&pathOptions.LoadingRules.ExplicitPath, pathOptions.ExplicitFileFlag, pathOptions.LoadingRules.ExplicitPath, "use a particular kubeconfig file")
|
cmd.PersistentFlags().StringVar(&pathOptions.LoadingRules.ExplicitPath, pathOptions.ExplicitFileFlag, pathOptions.LoadingRules.ExplicitPath, "use a particular kubeconfig file")
|
||||||
|
|
||||||
// TODO(juanvallejo): update all subcommands to work with genericclioptions.IOStreams
|
// TODO(juanvallejo): update all subcommands to work with genericclioptions.IOStreams
|
||||||
cmd.AddCommand(NewCmdConfigView(f, streams, pathOptions))
|
cmd.AddCommand(NewCmdConfigView(streams, pathOptions))
|
||||||
cmd.AddCommand(NewCmdConfigSetCluster(streams.Out, pathOptions))
|
cmd.AddCommand(NewCmdConfigSetCluster(streams.Out, pathOptions))
|
||||||
cmd.AddCommand(NewCmdConfigSetAuthInfo(streams.Out, pathOptions))
|
cmd.AddCommand(NewCmdConfigSetAuthInfo(streams.Out, pathOptions))
|
||||||
cmd.AddCommand(NewCmdConfigSetContext(streams.Out, pathOptions))
|
cmd.AddCommand(NewCmdConfigSetContext(streams.Out, pathOptions))
|
||||||
|
|
|
@ -864,7 +864,7 @@ func testConfigCommand(args []string, startingConfig clientcmdapi.Config, t *tes
|
||||||
argsToUse = append(argsToUse, args...)
|
argsToUse = append(argsToUse, args...)
|
||||||
|
|
||||||
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
cmd := NewCmdConfig(cmdutil.NewFactory(genericclioptions.NewTestConfigFlags()), clientcmd.NewDefaultPathOptions(), streams)
|
cmd := NewCmdConfig(clientcmd.NewDefaultPathOptions(), streams)
|
||||||
// "context" is a global flag, inherited from base kubectl command in the real world
|
// "context" is a global flag, inherited from base kubectl command in the real world
|
||||||
cmd.PersistentFlags().String("context", "", "The name of the kubeconfig context to use")
|
cmd.PersistentFlags().String("context", "", "The name of the kubeconfig context to use")
|
||||||
cmd.SetArgs(argsToUse)
|
cmd.SetArgs(argsToUse)
|
||||||
|
|
|
@ -68,7 +68,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCmdConfigView returns a Command instance for 'config view' sub command
|
// NewCmdConfigView returns a Command instance for 'config view' sub command
|
||||||
func NewCmdConfigView(f cmdutil.Factory, streams genericclioptions.IOStreams, ConfigAccess clientcmd.ConfigAccess) *cobra.Command {
|
func NewCmdConfigView(streams genericclioptions.IOStreams, ConfigAccess clientcmd.ConfigAccess) *cobra.Command {
|
||||||
o := &ViewOptions{
|
o := &ViewOptions{
|
||||||
PrintFlags: genericclioptions.NewPrintFlags("").WithTypeSetter(scheme.Scheme).WithDefaultOutput("yaml"),
|
PrintFlags: genericclioptions.NewPrintFlags("").WithTypeSetter(scheme.Scheme).WithDefaultOutput("yaml"),
|
||||||
ConfigAccess: ConfigAccess,
|
ConfigAccess: ConfigAccess,
|
||||||
|
|
|
@ -24,7 +24,6 @@ import (
|
||||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type viewClusterTest struct {
|
type viewClusterTest struct {
|
||||||
|
@ -185,7 +184,7 @@ func (test viewClusterTest) run(t *testing.T) {
|
||||||
pathOptions.GlobalFile = fakeKubeFile.Name()
|
pathOptions.GlobalFile = fakeKubeFile.Name()
|
||||||
pathOptions.EnvVar = ""
|
pathOptions.EnvVar = ""
|
||||||
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
cmd := NewCmdConfigView(cmdutil.NewFactory(genericclioptions.NewTestConfigFlags()), streams, pathOptions)
|
cmd := NewCmdConfigView(streams, pathOptions)
|
||||||
// "context" is a global flag, inherited from base kubectl command in the real world
|
// "context" is a global flag, inherited from base kubectl command in the real world
|
||||||
cmd.Flags().String("context", "", "The name of the kubeconfig context to use")
|
cmd.Flags().String("context", "", "The name of the kubeconfig context to use")
|
||||||
cmd.Flags().Parse(test.flags)
|
cmd.Flags().Parse(test.flags)
|
||||||
|
|
|
@ -55,7 +55,7 @@ var (
|
||||||
ValidPluginFilenamePrefixes = []string{"kubectl"}
|
ValidPluginFilenamePrefixes = []string{"kubectl"}
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewCmdPlugin(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
|
func NewCmdPlugin(streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "plugin [flags]",
|
Use: "plugin [flags]",
|
||||||
DisableFlagsInUseLine: true,
|
DisableFlagsInUseLine: true,
|
||||||
|
@ -66,7 +66,7 @@ func NewCmdPlugin(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.AddCommand(NewCmdPluginList(f, streams))
|
cmd.AddCommand(NewCmdPluginList(streams))
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ type PluginListOptions struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdPluginList provides a way to list all plugin executables visible to kubectl
|
// NewCmdPluginList provides a way to list all plugin executables visible to kubectl
|
||||||
func NewCmdPluginList(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
|
func NewCmdPluginList(streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
o := &PluginListOptions{
|
o := &PluginListOptions{
|
||||||
IOStreams: streams,
|
IOStreams: streams,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue