remove kube flags

This commit is contained in:
天元
2020-08-07 15:08:35 +08:00
parent 428cb57b59
commit 772ea69fa2
7 changed files with 18 additions and 23 deletions

View File

@@ -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),

View File

@@ -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")

View File

@@ -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}

View File

@@ -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",

View File

@@ -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{

View File

@@ -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",

View File

@@ -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()