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 de7a89c4 [dubboctl] Completion of image deployment logic (#595)
de7a89c4 is described below

commit de7a89c4ebd6aa33656add0a15e75dece73c7bcc
Author: Jian Zhong <[email protected]>
AuthorDate: Tue Feb 11 13:22:10 2025 +0800

    [dubboctl] Completion of image deployment logic (#595)
---
 dubboctl/cmd/image.go                 | 83 +++++++++++++++++++++++++++++------
 dubboctl/pkg/hub/deployer/deploy.tpl  |  7 ++-
 dubboctl/pkg/hub/deployer/deployer.go |  4 +-
 dubboctl/pkg/sdk/dubbo/config.go      | 10 ++---
 4 files changed, 80 insertions(+), 24 deletions(-)

diff --git a/dubboctl/cmd/image.go b/dubboctl/cmd/image.go
index e8ab7d27..9455668e 100644
--- a/dubboctl/cmd/image.go
+++ b/dubboctl/cmd/image.go
@@ -18,10 +18,9 @@ import (
 )
 
 type imageArgs struct {
-       dockerfile   bool
-       builder      bool
-       deployment   bool
-       generateYaml string
+       dockerfile bool
+       builder    bool
+       output     string
 }
 
 func addHubFlags(cmd *cobra.Command, iArgs *imageArgs) {
@@ -30,7 +29,7 @@ func addHubFlags(cmd *cobra.Command, iArgs *imageArgs) {
 }
 
 func addDeployFlags(cmd *cobra.Command, iArgs *imageArgs) {
-       cmd.PersistentFlags().StringVarP(&iArgs.generateYaml, "output", "o", 
"dubbo-deploy.yaml", "The output generates k8s yaml file")
+       cmd.PersistentFlags().StringVarP(&iArgs.output, "output", "o", 
"dubbo-deploy.yaml", "The output generates k8s yaml file")
 
 }
 
@@ -44,8 +43,10 @@ type hubConfig struct {
 
 type deployConfig struct {
        *hubConfig
-       Output string
-       Path   string
+       Output    string
+       Namespace string
+       Port      int
+       Path      string
 }
 
 func ImageCmd(ctx cli.Context, cmd *cobra.Command, clientFactory 
ClientFactory) *cobra.Command {
@@ -134,7 +135,7 @@ func runHub(cmd *cobra.Command, args []string, 
clientFactory ClientFactory) erro
                return err
        }
 
-       hcfg, err = hcfg.prompt(fp)
+       hcfg, err = hcfg.hubPrompt(fp)
        if err != nil {
                return err
        }
@@ -195,16 +196,21 @@ func runDeploy(cmd *cobra.Command, args []string, 
clientFactory ClientFactory) e
        if err := util.GetCreatePath(); err != nil {
                return err
        }
-       config := newDeployConfig(cmd)
+       dcfg := newDeployConfig(cmd)
 
-       fp, err := dubbo.NewDubboConfig(config.Path)
+       fp, err := dubbo.NewDubboConfig(dcfg.Path)
        if err != nil {
                return err
        }
 
-       config.checkDeployConfig(fp)
+       dcfg, err = dcfg.deployPrompt(fp)
+       if err != nil {
+               return err
+       }
 
-       clientOptions, err := config.deployClientOptions()
+       dcfg.checkDeployConfig(fp)
+
+       clientOptions, err := dcfg.deployClientOptions()
        if err != nil {
                return err
        }
@@ -261,9 +267,15 @@ func (dc deployConfig) checkDeployConfig(dc2 
*dubbo.DubboConfig) {
        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) prompt(dc *dubbo.DubboConfig) (*hubConfig, error) {
+func (hc *hubConfig) hubPrompt(dc *dubbo.DubboConfig) (*hubConfig, error) {
        var err error
        if !util.InteractiveTerminal() {
                return hc, nil
@@ -286,3 +298,48 @@ func (hc *hubConfig) prompt(dc *dubbo.DubboConfig) 
(*hubConfig, error) {
        }
        return hc, err
 }
+
+func (dc *deployConfig) deployPrompt(dc2 *dubbo.DubboConfig) (*deployConfig, 
error) {
+       var err error
+       if !util.InteractiveTerminal() {
+               return dc, nil
+       }
+       if dc2.Deploy.Namespace == "" {
+               qs := []*survey.Question{
+                       {
+                               Name:     "namespace",
+                               Validate: survey.Required,
+                               Prompt: &survey.Input{
+                                       Message: "Namespace",
+                               },
+                       },
+               }
+               if err = survey.Ask(qs, dc); err != nil {
+                       return dc, err
+               }
+       }
+
+       buildconfig, err := dc.hubConfig.hubPrompt(dc2)
+       if err != nil {
+               return dc, err
+       }
+
+       dc.hubConfig = buildconfig
+
+       if dc2.Deploy.Port == 0 && dc.Port == 0 {
+               qs := []*survey.Question{
+                       {
+                               Name:     "port",
+                               Validate: survey.Required,
+                               Prompt: &survey.Input{
+                                       Message: "Port",
+                               },
+                       },
+               }
+               if err = survey.Ask(qs, dc); err != nil {
+                       return dc, err
+               }
+       }
+
+       return dc, err
+}
diff --git a/dubboctl/pkg/hub/deployer/deploy.tpl 
b/dubboctl/pkg/hub/deployer/deploy.tpl
index a7f35e9e..4c2eff39 100644
--- a/dubboctl/pkg/hub/deployer/deploy.tpl
+++ b/dubboctl/pkg/hub/deployer/deploy.tpl
@@ -46,11 +46,10 @@ metadata:
   namespace: {{.Namespace}}
 spec:
   ports:
-  - nodePort: {{.NodePort}}
-    port: {{.Port}}
+  - port: {{.Port}}
     protocol: TCP
-    targetPort: {{.TargetPort}}
-  type: NodePort
+    targetPort: dubbo
+  type: ClusterIP
   selector:
     app: {{.Name}}
 
diff --git a/dubboctl/pkg/hub/deployer/deployer.go 
b/dubboctl/pkg/hub/deployer/deployer.go
index acf9d1ef..675814fe 100644
--- a/dubboctl/pkg/hub/deployer/deployer.go
+++ b/dubboctl/pkg/hub/deployer/deployer.go
@@ -53,7 +53,7 @@ func (d *deploy) Deploy(ctx context.Context, dc 
*dubbo.DubboConfig, option ...sd
 
        targetPort := dc.Deploy.TargetPort
        if targetPort == 0 {
-               targetPort = dc.Deploy.ContainerPort
+               targetPort = dc.Deploy.Port
        }
 
        path := dc.Root + "/" + dc.Deploy.Output
@@ -74,7 +74,7 @@ func (d *deploy) Deploy(ctx context.Context, dc 
*dubbo.DubboConfig, option ...sd
                Name:       dc.Name,
                Namespace:  ns,
                Image:      dc.Image,
-               Port:       dc.Deploy.ContainerPort,
+               Port:       dc.Deploy.Port,
                TargetPort: targetPort,
                NodePort:   dc.Deploy.NodePort,
        })
diff --git a/dubboctl/pkg/sdk/dubbo/config.go b/dubboctl/pkg/sdk/dubbo/config.go
index 7f7f1870..fda66e93 100644
--- a/dubboctl/pkg/sdk/dubbo/config.go
+++ b/dubboctl/pkg/sdk/dubbo/config.go
@@ -40,11 +40,11 @@ type BuildSpec struct {
 }
 
 type DeploySpec struct {
-       Namespace     string `yaml:"namespace,omitempty"`
-       Output        string `yaml:"output,omitempty"`
-       ContainerPort int    `yaml:"containerPort,omitempty"`
-       TargetPort    int    `yaml:"targetPort,omitempty"`
-       NodePort      int    `yaml:"nodePort,omitempty"`
+       Namespace  string `yaml:"namespace,omitempty"`
+       Output     string `yaml:"output,omitempty"`
+       Port       int    `yaml:"port,omitempty"`
+       TargetPort int    `yaml:"targetPort,omitempty"`
+       NodePort   int    `yaml:"nodePort,omitempty"`
 }
 
 func NewDubboConfig(path string) (*DubboConfig, error) {

Reply via email to