Merge pull request #111689 from ardaguclu/use-restgetter-clusterinfo

(kubectl cluster-info): Move towards RESTClientGetter instead cmdutil.Factory

Kubernetes-commit: f51d934aed721a0cdb169c0f61bcbf18bd138a69
This commit is contained in:
Kubernetes Publisher 2022-08-23 17:17:19 -07:00
commit 35125e2226
2 changed files with 13 additions and 13 deletions

View File

@ -55,7 +55,7 @@ type ClusterInfoOptions struct {
Client *restclient.Config
}
func NewCmdClusterInfo(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
func NewCmdClusterInfo(restClientGetter genericclioptions.RESTClientGetter, ioStreams genericclioptions.IOStreams) *cobra.Command {
o := &ClusterInfoOptions{
IOStreams: ioStreams,
}
@ -66,17 +66,17 @@ func NewCmdClusterInfo(f cmdutil.Factory, ioStreams genericclioptions.IOStreams)
Long: longDescr,
Example: clusterinfoExample,
Run: func(cmd *cobra.Command, args []string) {
cmdutil.CheckErr(o.Complete(f, cmd))
cmdutil.CheckErr(o.Complete(restClientGetter, cmd))
cmdutil.CheckErr(o.Run())
},
}
cmd.AddCommand(NewCmdClusterInfoDump(f, ioStreams))
cmd.AddCommand(NewCmdClusterInfoDump(restClientGetter, ioStreams))
return cmd
}
func (o *ClusterInfoOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error {
func (o *ClusterInfoOptions) Complete(restClientGetter genericclioptions.RESTClientGetter, cmd *cobra.Command) error {
var err error
o.Client, err = f.ToRESTConfig()
o.Client, err = restClientGetter.ToRESTConfig()
if err != nil {
return err
}
@ -87,7 +87,7 @@ func (o *ClusterInfoOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) err
}
o.Namespace = cmdNamespace
o.Builder = f.NewBuilder()
o.Builder = resource.NewBuilder(restClientGetter)
return nil
}

View File

@ -62,7 +62,7 @@ type ClusterInfoDumpOptions struct {
genericclioptions.IOStreams
}
func NewCmdClusterInfoDump(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
func NewCmdClusterInfoDump(restClientGetter genericclioptions.RESTClientGetter, ioStreams genericclioptions.IOStreams) *cobra.Command {
o := &ClusterInfoDumpOptions{
PrintFlags: genericclioptions.NewPrintFlags("").WithTypeSetter(scheme.Scheme).WithDefaultOutput("json"),
@ -75,7 +75,7 @@ func NewCmdClusterInfoDump(f cmdutil.Factory, ioStreams genericclioptions.IOStre
Long: dumpLong,
Example: dumpExample,
Run: func(cmd *cobra.Command, args []string) {
cmdutil.CheckErr(o.Complete(f, cmd))
cmdutil.CheckErr(o.Complete(restClientGetter, cmd))
cmdutil.CheckErr(o.Run())
},
}
@ -126,7 +126,7 @@ func setupOutputWriter(dir string, defaultWriter io.Writer, filename string, fil
return file
}
func (o *ClusterInfoDumpOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error {
func (o *ClusterInfoDumpOptions) Complete(restClientGetter genericclioptions.RESTClientGetter, cmd *cobra.Command) error {
printer, err := o.PrintFlags.ToPrinter()
if err != nil {
return err
@ -134,7 +134,7 @@ func (o *ClusterInfoDumpOptions) Complete(f cmdutil.Factory, cmd *cobra.Command)
o.PrintObj = printer.PrintObj
config, err := f.ToRESTConfig()
config, err := restClientGetter.ToRESTConfig()
if err != nil {
return err
}
@ -154,12 +154,12 @@ func (o *ClusterInfoDumpOptions) Complete(f cmdutil.Factory, cmd *cobra.Command)
return err
}
o.Namespace, _, err = f.ToRawKubeConfigLoader().Namespace()
o.Namespace, _, err = restClientGetter.ToRawKubeConfigLoader().Namespace()
if err != nil {
return err
}
// TODO this should eventually just be the completed kubeconfigflag struct
o.RESTClientGetter = f
o.RESTClientGetter = restClientGetter
o.LogsForObject = polymorphichelpers.LogsForObjectFn
return nil