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 8881d52a [dubboctl] Optimize code readability (#630)
8881d52a is described below

commit 8881d52a5dc7db8313af4589e206876d47eb3a84
Author: Jian Zhong <[email protected]>
AuthorDate: Sat Mar 1 13:45:24 2025 +0800

    [dubboctl] Optimize code readability (#630)
---
 dubboctl/cmd/create.go                       |  2 +-
 dubboctl/cmd/image.go                        | 86 ++++++++++++++--------------
 dubboctl/cmd/root.go                         | 16 +++---
 dubboctl/pkg/cli/context.go                  |  4 ++
 dubboctl/pkg/cli/options.go                  |  1 -
 dubboctl/pkg/hub/builder/dockerfile/build.go |  3 +
 dubboctl/pkg/hub/builder/pack/build.go       |  2 -
 7 files changed, 60 insertions(+), 54 deletions(-)

diff --git a/dubboctl/cmd/create.go b/dubboctl/cmd/create.go
index ab702828..79afe9c7 100644
--- a/dubboctl/cmd/create.go
+++ b/dubboctl/cmd/create.go
@@ -90,7 +90,7 @@ type createConfig struct {
        Initialzed bool
 }
 
-func newCreateConfig(cmd *cobra.Command, args []string, clientFactory 
ClientFactory) (dcfg createConfig, err error) {
+func newCreateConfig(_ *cobra.Command, _ []string, _ ClientFactory) (dcfg 
createConfig, err error) {
        var absolutePath string
        absolutePath = cwd()
 
diff --git a/dubboctl/cmd/image.go b/dubboctl/cmd/image.go
index f4a208e1..b73ed2f9 100644
--- a/dubboctl/cmd/image.go
+++ b/dubboctl/cmd/image.go
@@ -34,6 +34,18 @@ func addDeployFlags(cmd *cobra.Command, iArgs *imageArgs) {
        cmd.PersistentFlags().BoolVarP(&iArgs.destroy, "delete", "d", false, 
"delete k8s yaml file")
 }
 
+func ImageCmd(ctx cli.Context, cmd *cobra.Command, clientFactory 
ClientFactory) *cobra.Command {
+       ihc := imageHubCmd(cmd, clientFactory)
+       idc := imageDeployCmd(cmd, clientFactory)
+       ic := &cobra.Command{
+               Use:   "image",
+               Short: "Used to build and push images, apply to cluster",
+       }
+       ic.AddCommand(ihc)
+       ic.AddCommand(idc)
+       return ic
+}
+
 type hubConfig struct {
        Dockerfile   bool
        Builder      bool
@@ -51,18 +63,6 @@ type deployConfig struct {
        Path      string
 }
 
-func ImageCmd(ctx cli.Context, cmd *cobra.Command, clientFactory 
ClientFactory) *cobra.Command {
-       ihc := imageHubCmd(cmd, clientFactory)
-       idc := imageDeployCmd(cmd, clientFactory)
-       ic := &cobra.Command{
-               Use:   "image",
-               Short: "Used to build and push images, apply to cluster",
-       }
-       ic.AddCommand(ihc)
-       ic.AddCommand(idc)
-       return ic
-}
-
 func newHubConfig(cmd *cobra.Command) *hubConfig {
        hc := &hubConfig{
                Dockerfile: viper.GetBool("file"),
@@ -128,6 +128,24 @@ func imageHubCmd(cmd *cobra.Command, clientFactory 
ClientFactory) *cobra.Command
        return hc
 }
 
+func (hc *hubConfig) checkHubConfig(dc *dubbo.DubboConfig) {
+       if hc.Path == "" {
+               root, err := os.Getwd()
+               if err != nil {
+                       return
+               }
+               dc.Root = root
+       } else {
+               dc.Root = hc.Path
+       }
+       if hc.BuilderImage != "" {
+               dc.Build.BuilderImages["pack"] = hc.BuilderImage
+       }
+       if hc.Image != "" {
+               dc.Image = hc.Image
+       }
+}
+
 func runHub(cmd *cobra.Command, args []string, clientFactory ClientFactory) 
error {
        if err := util.GetCreatePath(); err != nil {
                return err
@@ -192,6 +210,19 @@ func imageDeployCmd(cmd *cobra.Command, clientFactory 
ClientFactory) *cobra.Comm
        return hc
 }
 
+func (dc deployConfig) checkDeployConfig(dc2 *dubbo.DubboConfig) {
+       dc.checkHubConfig(dc2)
+       if dc.Output != "" {
+               dc2.Deploy.Output = dc.Output
+       }
+       if dc.Namespace != "" {
+               dc2.Deploy.Namespace = dc.Namespace
+       }
+       if dc.Port != 0 {
+               dc2.Deploy.Port = dc.Port
+       }
+}
+
 func runDeploy(cmd *cobra.Command, args []string, clientFactory ClientFactory) 
error {
        if err := util.GetCreatePath(); err != nil {
                return err
@@ -262,37 +293,6 @@ func remove(cmd *cobra.Command, dc *dubbo.DubboConfig) 
error {
        return nil
 }
 
-func (hc *hubConfig) checkHubConfig(dc *dubbo.DubboConfig) {
-       if hc.Path == "" {
-               root, err := os.Getwd()
-               if err != nil {
-                       return
-               }
-               dc.Root = root
-       } else {
-               dc.Root = hc.Path
-       }
-       if hc.BuilderImage != "" {
-               dc.Build.BuilderImages["pack"] = hc.BuilderImage
-       }
-       if hc.Image != "" {
-               dc.Image = hc.Image
-       }
-}
-
-func (dc deployConfig) checkDeployConfig(dc2 *dubbo.DubboConfig) {
-       dc.checkHubConfig(dc2)
-       if dc.Output != "" {
-               dc2.Deploy.Output = dc.Output
-       }
-       if dc.Namespace != "" {
-               dc2.Deploy.Namespace = dc.Namespace
-       }
-       if dc.Port != 0 {
-               dc2.Deploy.Port = dc.Port
-       }
-}
-
 func (hc *hubConfig) hubPrompt(dc *dubbo.DubboConfig) (*hubConfig, error) {
        var err error
        if !util.InteractiveTerminal() {
diff --git a/dubboctl/cmd/root.go b/dubboctl/cmd/root.go
index 04340c78..97ef2dca 100644
--- a/dubboctl/cmd/root.go
+++ b/dubboctl/cmd/root.go
@@ -34,6 +34,8 @@ import (
        // "os"
 )
 
+const ChartFlag = "charts"
+
 type staticClient struct {
        clientFactory ClientFactory
 }
@@ -104,7 +106,7 @@ func GetRootCmd(args []string) *cobra.Command {
 
        installCmd := cluster.InstallCmd(ctx)
        rootCmd.AddCommand(installCmd)
-       hideFlags(installCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag, 
cli.ChartFlag)
+       hideFlags(installCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag, 
ChartFlag)
 
        uninstallCmd := cluster.UninstallCmd(ctx)
        rootCmd.AddCommand(uninstallCmd)
@@ -114,27 +116,27 @@ func GetRootCmd(args []string) *cobra.Command {
 
        manifestCmd := cluster.ManifestCmd(ctx)
        rootCmd.AddCommand(manifestCmd)
-       hideFlags(manifestCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag, 
cli.ChartFlag)
+       hideFlags(manifestCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag, 
ChartFlag)
 
        validateCmd := validate.NewValidateCommand(ctx)
        rootCmd.AddCommand(validateCmd)
-       hideFlags(validateCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag, 
cli.ChartFlag)
+       hideFlags(validateCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag, 
ChartFlag)
 
        versionCmd := version.NewVersionCommand(ctx)
        rootCmd.AddCommand(versionCmd)
-       hideFlags(versionCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag, 
cli.ChartFlag)
+       hideFlags(versionCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag, 
ChartFlag)
 
        createCmd := CreateCmd(ctx, rootCmd, factory)
        rootCmd.AddCommand(createCmd)
-       hideFlags(createCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag, 
cli.ChartFlag)
+       hideFlags(createCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag, 
ChartFlag)
 
        repoCmd := RepoCmd(ctx, rootCmd, factory)
        rootCmd.AddCommand(repoCmd)
-       hideFlags(repoCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag, 
cli.ChartFlag)
+       hideFlags(repoCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag, ChartFlag)
 
        imageCmd := ImageCmd(ctx, rootCmd, factory)
        rootCmd.AddCommand(imageCmd)
-       hideFlags(imageCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag, 
cli.ChartFlag)
+       hideFlags(imageCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag, 
ChartFlag)
 
        return rootCmd
 
diff --git a/dubboctl/pkg/cli/context.go b/dubboctl/pkg/cli/context.go
index d647af3d..6be674ba 100644
--- a/dubboctl/pkg/cli/context.go
+++ b/dubboctl/pkg/cli/context.go
@@ -39,6 +39,7 @@ func (i *instance) CLIClientWithRevision(rev string) 
(kube.CLIClient, error) {
        if i.clients == nil {
                i.clients = make(map[string]kube.CLIClient)
        }
+
        if i.clients[rev] == nil {
                impersonationConfig := rest.ImpersonationConfig{}
                client, err := newKubeClientWithRevision(*i.kubeconfig, 
*i.Context, rev, impersonationConfig)
@@ -47,6 +48,7 @@ func (i *instance) CLIClientWithRevision(rev string) 
(kube.CLIClient, error) {
                }
                i.clients[rev] = client
        }
+
        return i.clients[rev], nil
 }
 
@@ -56,8 +58,10 @@ func newKubeClientWithRevision(kubeconfig, context, revision 
string, impersonati
                config.Burst = 95
                config.Impersonate = impersonationConfig
        })
+
        if err != nil {
                return nil, err
        }
+
        return kube.NewCLIClient(kube.NewClientConfigForRestConfig(drc), 
kube.WithRevision(revision))
 }
diff --git a/dubboctl/pkg/cli/options.go b/dubboctl/pkg/cli/options.go
index 0934a02a..778be126 100644
--- a/dubboctl/pkg/cli/options.go
+++ b/dubboctl/pkg/cli/options.go
@@ -12,7 +12,6 @@ const (
        ContextFlag        = "context"
        NamespaceFlag      = "namespace"
        DubboNamespaceFlag = "dubbo-namespace"
-       ChartFlag          = "charts"
 )
 
 type RootFlags struct {
diff --git a/dubboctl/pkg/hub/builder/dockerfile/build.go 
b/dubboctl/pkg/hub/builder/dockerfile/build.go
index 0a4f7e23..5e7f9c03 100644
--- a/dubboctl/pkg/hub/builder/dockerfile/build.go
+++ b/dubboctl/pkg/hub/builder/dockerfile/build.go
@@ -33,11 +33,14 @@ func (b Builder) Build(ctx context.Context, dc 
*dubbo.DubboConfig) error {
        if err != nil {
                return err
        }
+
        defer resp.Body.Close()
+
        termFd, isTerm := term.GetFdInfo(os.Stderr)
        err = jsonmessage.DisplayJSONMessagesStream(resp.Body, os.Stderr, 
termFd, isTerm, nil)
        if err != nil {
                return err
        }
+
        return nil
 }
diff --git a/dubboctl/pkg/hub/builder/pack/build.go 
b/dubboctl/pkg/hub/builder/pack/build.go
index 16d780cb..f193dfbf 100644
--- a/dubboctl/pkg/hub/builder/pack/build.go
+++ b/dubboctl/pkg/hub/builder/pack/build.go
@@ -20,8 +20,6 @@ import (
 const DefaultName = builder.Pack
 
 var (
-       // DefaulttinyBuilder   = "ghcr.io/knative/builder-jammy-tiny:latest"
-       // DefaulttinyBuilder = "ghcr.io/knative/builder-jammy-tiny:latest"
        DefaultGoBuilder   = "heroku/builder:24"
        DefaultJavaBuilder = "heroku/builder:24"
 )

Reply via email to