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 b9ae4fde [operator] Additions to the installation logic
b9ae4fde is described below

commit b9ae4fde0402a3bd6aaecb8d99b7112544606331
Author: mfordjody <[email protected]>
AuthorDate: Sat Dec 14 08:55:48 2024 +0800

    [operator] Additions to the installation logic
---
 dubboctl/cmd/manifest.go        | 29 ++++++++++++-----------------
 dubboctl/cmd/profile.go         | 27 +++++++++++----------------
 dubboctl/cmd/root.go            |  2 +-
 operator/cmd/cluster/install.go | 39 ++++++++++++++++++++++++++++++++++++---
 operator/pkg/render/manifest.go |  2 +-
 pkg/util/pointer/pointer.go     |  8 ++++++++
 6 files changed, 69 insertions(+), 38 deletions(-)

diff --git a/dubboctl/cmd/manifest.go b/dubboctl/cmd/manifest.go
index c5523001..8141e854 100644
--- a/dubboctl/cmd/manifest.go
+++ b/dubboctl/cmd/manifest.go
@@ -15,20 +15,15 @@
 
 package cmd
 
-import (
-       "github.com/apache/dubbo-kubernetes/dubboctl/pkg/manifest"
-       "github.com/spf13/cobra"
-)
-
-func AddManifest(rootCmd *cobra.Command) {
-       manifestCmd := &cobra.Command{
-               Use:   "manifest",
-               Short: "Commands related to manifest",
-               Long:  "Commands help user to generate manifest and install 
manifest",
-       }
-       manifest.ConfigManifestGenerateCmd(manifestCmd)
-       manifest.ConfigManifestInstallCmd(manifestCmd)
-       manifest.ConfigManifestUninstallCmd(manifestCmd)
-       manifest.ConfigManifestDiffCmd(manifestCmd)
-       rootCmd.AddCommand(manifestCmd)
-}
+//func AddManifest(rootCmd *cobra.Command) {
+//     manifestCmd := &cobra.Command{
+//             Use:   "manifest",
+//             Short: "Commands related to manifest",
+//             Long:  "Commands help user to generate manifest and install 
manifest",
+//     }
+//     manifest.ConfigManifestGenerateCmd(manifestCmd)
+//     manifest.ConfigManifestInstallCmd(manifestCmd)
+//     manifest.ConfigManifestUninstallCmd(manifestCmd)
+//     manifest.ConfigManifestDiffCmd(manifestCmd)
+//     rootCmd.AddCommand(manifestCmd)
+//}
diff --git a/dubboctl/cmd/profile.go b/dubboctl/cmd/profile.go
index 3f4d2ce8..b5c0161a 100644
--- a/dubboctl/cmd/profile.go
+++ b/dubboctl/cmd/profile.go
@@ -15,19 +15,14 @@
 
 package cmd
 
-import (
-       "github.com/apache/dubbo-kubernetes/dubboctl/pkg/profile"
-       "github.com/spf13/cobra"
-)
-
-func addProfile(rootCmd *cobra.Command) {
-       profileCmd := &cobra.Command{
-               Use:   "profile",
-               Short: "Commands related to profiles",
-               Long:  "Commands help user to list and describe profiles",
-       }
-       profile.ConfigProfileListCmd(profileCmd)
-       profile.ConfigProfileDiffCmd(profileCmd)
-
-       rootCmd.AddCommand(profileCmd)
-}
+//func addProfile(rootCmd *cobra.Command) {
+//     profileCmd := &cobra.Command{
+//             Use:   "profile",
+//             Short: "Commands related to profiles",
+//             Long:  "Commands help user to list and describe profiles",
+//     }
+//     profile.ConfigProfileListCmd(profileCmd)
+//     profile.ConfigProfileDiffCmd(profileCmd)
+//
+//     rootCmd.AddCommand(profileCmd)
+//}
diff --git a/dubboctl/cmd/root.go b/dubboctl/cmd/root.go
index d8bd6f20..efcf5b9d 100644
--- a/dubboctl/cmd/root.go
+++ b/dubboctl/cmd/root.go
@@ -47,7 +47,7 @@ func GetRootCmd(args []string) *cobra.Command {
 
        upgradeCmd := cluster.UpgradeCmd(ctx)
        rootCmd.AddCommand(upgradeCmd)
-       
+
        AddFlags(installCmd)
        hideFlags(installCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag, 
cli.ChartFlag)
        return rootCmd
diff --git a/operator/cmd/cluster/install.go b/operator/cmd/cluster/install.go
index 0efeb988..af886a92 100644
--- a/operator/cmd/cluster/install.go
+++ b/operator/cmd/cluster/install.go
@@ -3,8 +3,14 @@ package cluster
 import (
        "fmt"
        "github.com/apache/dubbo-kubernetes/dubboctl/pkg/cli"
+       "github.com/apache/dubbo-kubernetes/operator/pkg/installer"
+       "github.com/apache/dubbo-kubernetes/operator/pkg/render"
+       "github.com/apache/dubbo-kubernetes/operator/pkg/util/clog"
        "github.com/apache/dubbo-kubernetes/pkg/kube"
+       "github.com/apache/dubbo-kubernetes/pkg/util/pointer"
        "github.com/spf13/cobra"
+       "io"
+       "os"
        "strings"
        "time"
 )
@@ -46,13 +52,40 @@ func InstallCmdWithArgs(ctx cli.Context, rootArgs 
*RootArgs, iArgs *installArgs)
                        if err != nil {
                                return err
                        }
-                       return install(kubeClient, rootArgs, iArgs)
                },
        }
        return ic
 }
 
-func install(kubeClient kube.CLIClient, rootArgs *RootArgs, iArgs 
*installArgs) error {
-
+func install(kubeClient kube.CLIClient, rootArgs *RootArgs, iArgs 
*installArgs, cl clog.Logger, stdOut io.Writer, p Printer) error {
+       setFlags := applyFlagAliases(iArgs.Set, iArgs.ManifestsPath, 
iArgs.Revision)
+       manifests, vals, err := render.GenerateManifest(iArgs.Files, setFlags)
+       if err != nil {
+               return fmt.Errorf("generate config: %v", err)
+       }
+       profile := 
pointer.NonEmptyOrDefault(vals.GetPathString("spec.profile"), "default")
+       if !rootArgs.DryRun && !iArgs.SkipConfirmation {
+               prompt := fmt.Sprintf("You are currently selecting the %q 
profile to install into the cluster. %v Do you want to proceed? (y/N)", 
profile, vals)
+               if !OptionDeterminator(prompt, stdOut) {
+                       p.Println("Cancelled.")
+                       os.Exit(1)
+               }
+       }
+       i := installer.Installer{
+               DryRun:   rootArgs.DryRun,
+               SkipWait: false,
+               Kube:     kubeClient,
+               Values:   vals,
+       }
+       if err := i.InstallManifests(manifests); err != nil {
+               return fmt.Errorf("failed to install manifests: %v", err)
+       }
        return nil
 }
+
+func applyFlagAliases(flags []string, manifestsPath string, revision string) 
[]string {
+       if manifestsPath != "" {
+               flags = append(flags, fmt.Sprintf("manifestsPath=%s", 
manifestsPath))
+       }
+       return flags
+}
diff --git a/operator/pkg/render/manifest.go b/operator/pkg/render/manifest.go
index c946c1a7..cab6091d 100644
--- a/operator/pkg/render/manifest.go
+++ b/operator/pkg/render/manifest.go
@@ -177,4 +177,4 @@ func applyComponentValuesToHelmValues(comp 
component.Component, spec apis.Metada
 
 func postProcess(comp component.Component, manifests []manifest.Manifest, vals 
values.Map) ([]manifest.Manifest, error) {
        return manifests, nil
-}
\ No newline at end of file
+}
diff --git a/pkg/util/pointer/pointer.go b/pkg/util/pointer/pointer.go
index 1a4ea513..8bb9f2e8 100644
--- a/pkg/util/pointer/pointer.go
+++ b/pkg/util/pointer/pointer.go
@@ -37,3 +37,11 @@ func DerefOr[T any](ptr *T, def T) T {
 func To[T any](t T) *T {
        return &t
 }
+
+func NonEmptyOrDefault[T comparable](t T, def T) T {
+       var empty T
+       if t != empty {
+               return t
+       }
+       return def
+}

Reply via email to