This is an automated email from the ASF dual-hosted git repository.
zhongxjian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-kubernetes.git
The following commit(s) were added to refs/heads/master by this push:
new 7fd5d3bc [dubboctl] Migration creates file optimization fields (#539)
7fd5d3bc is described below
commit 7fd5d3bc460234510c9770e14551d52361f522d2
Author: Jian Zhong <[email protected]>
AuthorDate: Tue Jan 14 17:38:34 2025 +0800
[dubboctl] Migration creates file optimization fields (#539)
---
{operator/cmd/cluster => dubboctl/cmd}/create.go | 75 +++++++++++-------------
dubboctl/cmd/root.go | 8 +--
go.mod | 2 +-
operator/cmd/cluster/install.go | 6 +-
operator/cmd/cluster/manifest.go | 6 +-
operator/cmd/cluster/root.go | 11 +---
operator/cmd/cluster/uninstall.go | 4 +-
operator/cmd/cluster/upgrade.go | 6 +-
8 files changed, 52 insertions(+), 66 deletions(-)
diff --git a/operator/cmd/cluster/create.go b/dubboctl/cmd/create.go
similarity index 52%
rename from operator/cmd/cluster/create.go
rename to dubboctl/cmd/create.go
index c1c57411..32883f06 100644
--- a/operator/cmd/cluster/create.go
+++ b/dubboctl/cmd/create.go
@@ -1,8 +1,9 @@
-package cluster
+package cmd
import (
"fmt"
"github.com/apache/dubbo-kubernetes/dubboctl/pkg/cli"
+ "github.com/apache/dubbo-kubernetes/operator/cmd/cluster"
"github.com/apache/dubbo-kubernetes/operator/pkg/util/clog"
"github.com/apache/dubbo-kubernetes/pkg/kube"
"github.com/spf13/cobra"
@@ -20,50 +21,55 @@ func addTemplateFlags(cmd *cobra.Command, args
*templateArgs) {
}
func CreateCmd(ctx cli.Context) *cobra.Command {
- rootArgs := &RootArgs{}
- tArgs := &templateArgs{}
- sc := sdkCmd(ctx, rootArgs, tArgs)
+ rootArgs := &cluster.RootArgs{}
+ tempArgs := &templateArgs{}
+ sc := sdkGenerateCmd(ctx, rootArgs, tempArgs)
cc := &cobra.Command{
Use: "create",
- Short: "Create a custom sdk",
+ Short: "Create a custom dubbo sdk sample",
RunE: func(cmd *cobra.Command, args []string) error {
return nil
},
}
- addFlags(cc, rootArgs)
- addFlags(sc, rootArgs)
- addTemplateFlags(cc, tArgs)
+ cluster.AddFlags(cc, rootArgs)
+ cluster.AddFlags(sc, rootArgs)
+ addTemplateFlags(cc, tempArgs)
cc.AddCommand(sc)
return cc
}
-func sdkCmd(ctx cli.Context, _ *RootArgs, tArgs *templateArgs) *cobra.Command {
+var kubeClientFunc func() (kube.CLIClient, error)
+
+func sdkGenerateCmd(ctx cli.Context, _ *cluster.RootArgs, tempArgs
*templateArgs) *cobra.Command {
return &cobra.Command{
Use: "sdk",
- Short: "Generates dubbo sdk language templates",
- Long: "",
- Example: `
- Create a java common in the directory 'mydubbo'.
- dubboctl create sdk java -t common mydubbo
-
- Create a go common in the directory ./mydubbo.
- dubboctl create sdk go -t common mydubbogo
+ Short: "Generate SDK samples for Dubbo supported languages",
+ Long: "The SDK subcommand generates an SDK sample provided by
Dubbo supported languages.",
+ Example: ` # Create a java sample sdk.
+ dubboctl create sdk java -t mydubbo
+
+ # Create a go sample sdk.
+ dubboctl create sdk go -t mydubbogo
`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
- if args[0] == "java" {
- // TODO
- fmt.Println("This is java sdk.")
- }
- if args[0] == "go" {
- // TODO
- fmt.Println("This is go sdk.")
- }
+ return fmt.Errorf("generate accepts no
positional arguments, got %#v", args)
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
- return nil
+ if kubeClientFunc == nil {
+ kubeClientFunc = ctx.CLIClient
+ }
+ var kubeClient kube.CLIClient
+ kc, err := kubeClientFunc()
+ if err != nil {
+ return err
+ }
+ kubeClient = kc
+
+ cl := clog.NewConsoleLogger(cmd.OutOrStdout(),
cmd.ErrOrStderr(), cluster.InstallerScope)
+ return runCreate(kubeClient, tempArgs, cl)
},
}
}
@@ -74,22 +80,11 @@ type createArgs struct {
create string
}
-func create(kc kube.CLIClient, tArgs *templateArgs, cl clog.Logger) {
- return
+func runCreate(kc kube.CLIClient, tempArgs *templateArgs, cl clog.Logger)
error {
+ return nil
}
-func newCreate(kc kube.CLIClient, tArgs *templateArgs, cl clog.Logger)
(createArgs, error) {
- var (
- path string
- dirName string
- absolutePath string
- )
- dirName, absolutePath = deriveNameAndAbsolutePathFromPath(path)
-
- _ = createArgs{
- dirname: dirName,
- path: absolutePath,
- }
+func newCreate(kc kube.CLIClient, tempArgs *templateArgs, cl clog.Logger)
(createArgs, error) {
return createArgs{}, nil
}
diff --git a/dubboctl/cmd/root.go b/dubboctl/cmd/root.go
index 59441828..826a21d3 100644
--- a/dubboctl/cmd/root.go
+++ b/dubboctl/cmd/root.go
@@ -55,10 +55,6 @@ func GetRootCmd(args []string) *cobra.Command {
rootCmd.AddCommand(manifestCmd)
hideFlags(manifestCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag,
cli.ChartFlag)
- createCmd := cluster.CreateCmd(ctx)
- rootCmd.AddCommand(createCmd)
- hideFlags(rootCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag,
cli.ChartFlag)
-
validateCmd := validate.NewValidateCommand(ctx)
rootCmd.AddCommand(validateCmd)
hideFlags(validateCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag,
cli.ChartFlag)
@@ -67,6 +63,10 @@ func GetRootCmd(args []string) *cobra.Command {
rootCmd.AddCommand(versionCmd)
hideFlags(versionCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag,
cli.ChartFlag)
+ createCmd := CreateCmd(ctx)
+ rootCmd.AddCommand(createCmd)
+ hideFlags(createCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag,
cli.ChartFlag)
+
return rootCmd
}
diff --git a/go.mod b/go.mod
index 51cf2767..5473dfe5 100644
--- a/go.mod
+++ b/go.mod
@@ -72,6 +72,7 @@ require (
google.golang.org/grpc v1.65.0
google.golang.org/protobuf v1.36.1
gopkg.in/natefinch/lumberjack.v2 v2.2.1
+ gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/mysql v1.5.4
gorm.io/driver/sqlite v1.5.5
gorm.io/gorm v1.25.7
@@ -257,7 +258,6 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
- gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/cli-runtime v0.32.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
diff --git a/operator/cmd/cluster/install.go b/operator/cmd/cluster/install.go
index 5ca0de4c..0fd4b932 100644
--- a/operator/cmd/cluster/install.go
+++ b/operator/cmd/cluster/install.go
@@ -18,7 +18,7 @@ import (
"time"
)
-var installerScope = log.RegisterScope("installer")
+var InstallerScope = log.RegisterScope("installer")
type installArgs struct {
files []string
@@ -69,12 +69,12 @@ func InstallCmdWithArgs(ctx cli.Context, rootArgs
*RootArgs, iArgs *installArgs)
return err
}
p := NewPrinterForWriter(cmd.OutOrStderr())
- cl := clog.NewConsoleLogger(cmd.OutOrStdout(),
cmd.ErrOrStderr(), installerScope)
+ cl := clog.NewConsoleLogger(cmd.OutOrStdout(),
cmd.ErrOrStderr(), InstallerScope)
p.Printf("%v\n", art.DubboColoredArt())
return Install(kubeClient, rootArgs, iArgs, cl,
cmd.OutOrStdout(), p)
},
}
- addFlags(ic, rootArgs)
+ AddFlags(ic, rootArgs)
addInstallFlags(ic, iArgs)
return ic
}
diff --git a/operator/cmd/cluster/manifest.go b/operator/cmd/cluster/manifest.go
index 5e501c43..0b75c668 100644
--- a/operator/cmd/cluster/manifest.go
+++ b/operator/cmd/cluster/manifest.go
@@ -43,8 +43,8 @@ func ManifestCmd(ctx cli.Context) *cobra.Command {
Short: "dubbo manifest related commands",
Long: "The manifest command will generates dubbo manifests.",
}
- addFlags(mc, rootArgs)
- addFlags(mgc, rootArgs)
+ AddFlags(mc, rootArgs)
+ AddFlags(mgc, rootArgs)
addManifestGenerateFlags(mgc, mgcArgs)
mc.AddCommand(mgc)
return mc
@@ -80,7 +80,7 @@ func manifestGenerateCmd(ctx cli.Context, _ *RootArgs, mgArgs
*manifestGenerateA
}
kubeClient = kc
- cl := clog.NewConsoleLogger(cmd.OutOrStdout(),
cmd.ErrOrStderr(), installerScope)
+ cl := clog.NewConsoleLogger(cmd.OutOrStdout(),
cmd.ErrOrStderr(), InstallerScope)
return manifestGenerate(kubeClient, mgArgs, cl)
},
}
diff --git a/operator/cmd/cluster/root.go b/operator/cmd/cluster/root.go
index 69bf9320..581337b6 100644
--- a/operator/cmd/cluster/root.go
+++ b/operator/cmd/cluster/root.go
@@ -13,15 +13,6 @@ type RootArgs struct {
RootFlags
}
-func AddRootFlags(cmd *cobra.Command) *RootFlags {
- rootFlags := &RootFlags{
- kubeconfig: nil,
- namespace: nil,
- dubboNamespace: nil,
- }
- return rootFlags
-}
-
-func addFlags(cmd *cobra.Command, rootArgs *RootArgs) {
+func AddFlags(cmd *cobra.Command, rootArgs *RootArgs) {
cmd.Flags().BoolVar(&rootArgs.DryRun, "dry-run", false, `Outputs only
the console/log without making any changes`)
}
diff --git a/operator/cmd/cluster/uninstall.go
b/operator/cmd/cluster/uninstall.go
index 79fd4874..f93f9e3e 100644
--- a/operator/cmd/cluster/uninstall.go
+++ b/operator/cmd/cluster/uninstall.go
@@ -54,13 +54,13 @@ func UninstallCmd(ctx cli.Context) *cobra.Command {
return Uninstall(cmd, ctx, rootArgs, uiArgs)
},
}
- addFlags(uicmd, rootArgs)
+ AddFlags(uicmd, rootArgs)
addUninstallFlags(uicmd, uiArgs)
return uicmd
}
func Uninstall(cmd *cobra.Command, ctx cli.Context, rootArgs *RootArgs, uiArgs
*uninstallArgs) error {
- cl := clog.NewConsoleLogger(cmd.OutOrStdout(), cmd.ErrOrStderr(),
installerScope)
+ cl := clog.NewConsoleLogger(cmd.OutOrStdout(), cmd.ErrOrStderr(),
InstallerScope)
var kubeClient kube.CLIClient
var err error
kubeClient, err = ctx.CLIClientWithRevision("")
diff --git a/operator/cmd/cluster/upgrade.go b/operator/cmd/cluster/upgrade.go
index 49d5c15c..0ecfd32a 100644
--- a/operator/cmd/cluster/upgrade.go
+++ b/operator/cmd/cluster/upgrade.go
@@ -4,7 +4,7 @@ import (
"github.com/apache/dubbo-kubernetes/dubboctl/pkg/cli"
"github.com/apache/dubbo-kubernetes/operator/pkg/util/clog"
- //"github.com/apache/dubbo-kubernetes/operator/pkg/util/clog"
+ // "github.com/apache/dubbo-kubernetes/operator/pkg/util/clog"
"github.com/spf13/cobra"
)
@@ -32,7 +32,7 @@ func UpgradeCmd(ctx cli.Context) *cobra.Command {
`,
RunE: func(cmd *cobra.Command, args []string) error {
- cl := clog.NewConsoleLogger(cmd.OutOrStdout(),
cmd.ErrOrStderr(), installerScope)
+ cl := clog.NewConsoleLogger(cmd.OutOrStdout(),
cmd.ErrOrStderr(), InstallerScope)
p := NewPrinterForWriter(cmd.OutOrStderr())
client, err := ctx.CLIClient()
if err != nil {
@@ -41,7 +41,7 @@ func UpgradeCmd(ctx cli.Context) *cobra.Command {
return Install(client, rootArgs, upArgs.installArgs,
cl, cmd.OutOrStdout(), p)
},
}
- addFlags(cmd, rootArgs)
+ AddFlags(cmd, rootArgs)
addInstallFlags(cmd, upArgs.installArgs)
return cmd
}