diff --git a/cmd/vela/main.go b/cmd/vela/main.go index 28af5e35c..3e770f14c 100644 --- a/cmd/vela/main.go +++ b/cmd/vela/main.go @@ -7,12 +7,13 @@ import ( "runtime" "time" + "sigs.k8s.io/controller-runtime/pkg/client/config" + "github.com/cloud-native-application/rudrx/pkg/utils/system" "github.com/crossplane/oam-kubernetes-runtime/apis/core" "github.com/spf13/cobra" k8sruntime "k8s.io/apimachinery/pkg/runtime" - "k8s.io/cli-runtime/pkg/genericclioptions" clientgoscheme "k8s.io/client-go/kubernetes/scheme" "sigs.k8s.io/controller-runtime/pkg/client" @@ -65,11 +66,7 @@ func newCommand() *cobra.Command { SilenceUsage: true, } - flags := cmds.PersistentFlags() - kubeConfigFlags := genericclioptions.NewConfigFlags(true).WithDeprecatedPasswordFlag() - kubeConfigFlags.AddFlags(flags) - f := cmdutil.NewFactory(kubeConfigFlags) - restConf, err := f.ToRESTConfig() + restConf, err := config.GetConfig() if err != nil { fmt.Println("get kubeconfig err", err) os.Exit(1) @@ -89,12 +86,12 @@ func newCommand() *cobra.Command { } cmds.AddCommand( - cmd.NewTraitsCommand(f, client, ioStream, []string{}), - cmd.NewWorkloadsCommand(f, client, ioStream, os.Args[1:]), - cmd.NewAdminInitCommand(f, client, ioStream), + cmd.NewTraitsCommand(client, ioStream, []string{}), + cmd.NewWorkloadsCommand(client, ioStream, os.Args[1:]), + cmd.NewAdminInitCommand(client, ioStream), cmd.NewAdminInfoCommand(VelaVersion, ioStream), - cmd.NewDeleteCommand(f, client, ioStream, os.Args[1:]), - cmd.NewAppsCommand(f, client, ioStream), + cmd.NewDeleteCommand(client, ioStream, os.Args[1:]), + cmd.NewAppsCommand(client, ioStream), cmd.NewEnvInitCommand(client, ioStream), cmd.NewEnvSwitchCommand(ioStream), cmd.NewEnvDeleteCommand(ioStream), diff --git a/pkg/cmd/delete.go b/pkg/cmd/delete.go index f5e60f35b..c853eace3 100644 --- a/pkg/cmd/delete.go +++ b/pkg/cmd/delete.go @@ -37,7 +37,7 @@ func newDeleteCommand() *cobra.Command { } // NewDeleteCommand init new command -func NewDeleteCommand(f cmdutil.Factory, c client.Client, ioStreams cmdutil.IOStreams, args []string) *cobra.Command { +func NewDeleteCommand(c client.Client, ioStreams cmdutil.IOStreams, args []string) *cobra.Command { cmd := newDeleteCommand() cmd.SetArgs(args) cmd.SetOut(ioStreams.Out) @@ -45,7 +45,7 @@ func NewDeleteCommand(f cmdutil.Factory, c client.Client, ioStreams cmdutil.IOSt o.client = c o.Env, _ = GetEnv() cmd.RunE = func(cmd *cobra.Command, args []string) error { - if err := o.Complete(f, cmd, args); err != nil { + if err := o.Complete(cmd, args); err != nil { return err } return o.Delete() @@ -53,7 +53,7 @@ func NewDeleteCommand(f cmdutil.Factory, c client.Client, ioStreams cmdutil.IOSt return cmd } -func (o *deleteOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error { +func (o *deleteOptions) Complete(cmd *cobra.Command, args []string) error { if len(args) < 1 { return errors.New("must specify name for workload") diff --git a/pkg/cmd/init.go b/pkg/cmd/init.go index fd7af0709..713cc7837 100644 --- a/pkg/cmd/init.go +++ b/pkg/cmd/init.go @@ -109,7 +109,7 @@ func (i *infoCmd) run(version string, ioStreams cmdutil.IOStreams) error { return nil } -func NewAdminInitCommand(f cmdutil.Factory, c client.Client, ioStreams cmdutil.IOStreams) *cobra.Command { +func NewAdminInitCommand(c client.Client, ioStreams cmdutil.IOStreams) *cobra.Command { i := &initCmd{out: ioStreams.Out} diff --git a/pkg/cmd/ls.go b/pkg/cmd/ls.go index 6707fb593..318c6ed60 100644 --- a/pkg/cmd/ls.go +++ b/pkg/cmd/ls.go @@ -12,7 +12,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -func NewAppsCommand(f cmdutil.Factory, c client.Client, ioStreams cmdutil.IOStreams) *cobra.Command { +func NewAppsCommand(c client.Client, ioStreams cmdutil.IOStreams) *cobra.Command { ctx := context.Background() cmd := &cobra.Command{ Use: "app:ls", diff --git a/pkg/cmd/traits.go b/pkg/cmd/traits.go index 8013e5f3e..dcf987596 100644 --- a/pkg/cmd/traits.go +++ b/pkg/cmd/traits.go @@ -12,7 +12,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -func NewTraitsCommand(f cmdutil.Factory, c client.Client, ioStreams cmdutil.IOStreams, args []string) *cobra.Command { +func NewTraitsCommand(c client.Client, ioStreams cmdutil.IOStreams, args []string) *cobra.Command { ctx := context.Background() var workloadName string cmd := &cobra.Command{ diff --git a/pkg/cmd/workloads.go b/pkg/cmd/workloads.go index 76c7fe8a5..81c8d0ca7 100644 --- a/pkg/cmd/workloads.go +++ b/pkg/cmd/workloads.go @@ -11,7 +11,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -func NewWorkloadsCommand(f cmdutil.Factory, c client.Client, ioStreams cmdutil.IOStreams, args []string) *cobra.Command { +func NewWorkloadsCommand(c client.Client, ioStreams cmdutil.IOStreams, args []string) *cobra.Command { ctx := context.Background() cmd := &cobra.Command{ Use: "workloads", diff --git a/pkg/test/cli.go b/pkg/test/cli.go index 0d497ddb3..7203a6e73 100644 --- a/pkg/test/cli.go +++ b/pkg/test/cli.go @@ -8,7 +8,6 @@ import ( "gotest.tools/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - cmdtesting "k8s.io/kubectl/pkg/cmd/testing" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" @@ -50,12 +49,12 @@ type clitestImpl struct { cases map[string]*CliTestCase t *testing.T scheme *runtime.Scheme - command func(f cmdutil.Factory, c client.Client, ioStreams cmdutil.IOStreams, args []string) *cobra.Command + command func(c client.Client, ioStreams cmdutil.IOStreams, args []string) *cobra.Command } // NewCliTest return cli testimpl func NewCliTest(t *testing.T, scheme *runtime.Scheme, - command func(f cmdutil.Factory, c client.Client, ioStreams cmdutil.IOStreams, + command func(c client.Client, ioStreams cmdutil.IOStreams, args []string) *cobra.Command, cases map[string]*CliTestCase) CliTest { return &clitestImpl{ cases: cases, @@ -69,7 +68,6 @@ func NewCliTest(t *testing.T, scheme *runtime.Scheme, func (c *clitestImpl) Run() { for name, tc := range c.cases { c.t.Run(name, func(t *testing.T) { - factory := cmdtesting.NewTestFactory().WithNamespace("default") fakeClient := fake.NewFakeClientWithScheme(c.scheme) iostream, _, outPut, _ := cmdutil.NewTestIOStreams() @@ -88,7 +86,7 @@ func (c *clitestImpl) Run() { } // init command - runCmd := c.command(factory, fakeClient, iostream, tc.Args) + runCmd := c.command(fakeClient, iostream, tc.Args) runCmd.SetOutput(outPut) err := runCmd.Execute()