Skip to content

Commit

Permalink
[dubboctl] add image apply logic (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfordjody authored Jan 29, 2025
1 parent 11c2214 commit 824babb
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 6 deletions.
68 changes: 63 additions & 5 deletions dubboctl/cmd/image.go
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion dubboctl/cmd/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 824babb

Please sign in to comment.