mirror of
https://github.com/kubevela/kubevela.git
synced 2026-02-14 18:10:21 +00:00
remove kube flags
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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}
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user