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 824babba [dubboctl] add image apply logic (#566)
824babba is described below
commit 824babba43a7db2b1b156abd7f17f6de899a4af9
Author: Jian Zhong <[email protected]>
AuthorDate: Wed Jan 29 15:05:29 2025 +0800
[dubboctl] add image apply logic (#566)
---
dubboctl/cmd/image.go | 68 +++++++++++++++++++++++++++++++++++++++++++++++----
dubboctl/cmd/repo.go | 2 +-
2 files changed, 64 insertions(+), 6 deletions(-)
diff --git a/dubboctl/cmd/image.go b/dubboctl/cmd/image.go
index 63f34614..bfcf8b15 100644
--- a/dubboctl/cmd/image.go
+++ b/dubboctl/cmd/image.go
@@ -1,19 +1,23 @@
package cmd
import (
+ "fmt"
"github.com/apache/dubbo-kubernetes/dubboctl/pkg/cli"
+ "github.com/apache/dubbo-kubernetes/dubboctl/pkg/sdk/dubbo"
"github.com/spf13/cobra"
+ "os"
+ "os/exec"
+ "path/filepath"
)
func ImageCmd(ctx cli.Context, cmd *cobra.Command, clientFactory
ClientFactory) *cobra.Command {
ibc := imageBuildCmd(cmd, clientFactory)
- ipc := imageBuildCmd(cmd, clientFactory)
+ ipc := imagePushCmd(cmd, clientFactory)
iac := imageApplyCmd(cmd, clientFactory)
ic := &cobra.Command{
Use: "image",
- Short: "",
- Long: "",
+ Short: "Used to build images, push images, apply to cluster",
}
ic.AddCommand(ibc)
ic.AddCommand(ipc)
@@ -22,13 +26,67 @@ func ImageCmd(ctx cli.Context, cmd *cobra.Command,
clientFactory ClientFactory)
}
func imageBuildCmd(cmd *cobra.Command, clientFactory ClientFactory)
*cobra.Command {
- return nil
+ bc := &cobra.Command{
+ Use: "build",
+ Short: "build to images",
+ Long: "The build subcommand used to build images",
+ Example: "",
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return runBuild(cmd, args, clientFactory)
+ },
+ }
+ return bc
+}
+
+func runBuild(cmd *cobra.Command, args []string, clientFactory ClientFactory)
error {
+ return fmt.Errorf("TODO")
}
func imagePushCmd(cmd *cobra.Command, clientFactory ClientFactory)
*cobra.Command {
- return nil
+ pc := &cobra.Command{
+ Use: "push",
+ Short: "push to images",
+ Long: "The push subcommand used to push images",
+ Example: "",
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return runPush(cmd, args, clientFactory)
+ },
+ }
+ return pc
+}
+
+func runPush(cmd *cobra.Command, args []string, clientFactory ClientFactory)
error {
+ return fmt.Errorf("TODO")
}
func imageApplyCmd(cmd *cobra.Command, clientFactory ClientFactory)
*cobra.Command {
+ ac := &cobra.Command{
+ Use: "apply",
+ Short: "apply to images",
+ Long: "The apply subcommand used to apply images",
+ Example: "",
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return runApply(cmd, args, clientFactory)
+ },
+ }
+ return ac
+}
+
+func runApply(cmd *cobra.Command, args []string, clientFactory ClientFactory)
error {
+ if err := applyToCluster(cmd, nil); err != nil {
+ return err
+ }
+
+ return nil
+}
+
+func applyToCluster(cmd *cobra.Command, dc *dubbo.DubboConfig) error {
+ file := filepath.Join(dc.Root)
+ ec := exec.CommandContext(cmd.Context(), "kubectl", "apply", "-f", file)
+ ec.Stdout = os.Stdout
+ ec.Stderr = os.Stderr
+ if err := ec.Run(); err != nil {
+ return err
+ }
return nil
}
diff --git a/dubboctl/cmd/repo.go b/dubboctl/cmd/repo.go
index 19f8435b..52a4c779 100644
--- a/dubboctl/cmd/repo.go
+++ b/dubboctl/cmd/repo.go
@@ -20,7 +20,7 @@ func RepoCmd(_ cli.Context, cmd *cobra.Command, clientFactory
ClientFactory) *co
re := removeCmd(cmd, clientFactory)
rc := &cobra.Command{
Use: "repo",
- Short: "Manage existing Dubbo SDK module libraries",
+ Short: "Manage exist Dubbo sdk module libraries",
Long: "The repo command Manage existing Dubbo SDK module
libraries",
Example: ` # Add a new template library.
dubboctl repo add [name] [URL]