From 428fd030cff538554c41644058daa684080f1f83 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Tue, 29 Apr 2025 17:02:15 -0500 Subject: [PATCH 1/7] chore(cli): rename 'init' cmd to 'quickstart' This command runs all the other commands with defaults so a better name for it would be 'quickstart' so make that change. --- go/understack/README.md | 2 +- .../cmd/{init/init.go => quickstart/quickstart.go} | 14 +++++++------- go/understack/main.go | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) rename go/understack/cmd/{init/init.go => quickstart/quickstart.go} (88%) diff --git a/go/understack/README.md b/go/understack/README.md index 102aacb8e..18a0a8b36 100644 --- a/go/understack/README.md +++ b/go/understack/README.md @@ -21,7 +21,7 @@ export UC_AIO=yes * Run ``` -go run *.go init +go run *.go quickstart go run *.go help ``` diff --git a/go/understack/cmd/init/init.go b/go/understack/cmd/quickstart/quickstart.go similarity index 88% rename from go/understack/cmd/init/init.go rename to go/understack/cmd/quickstart/quickstart.go index 66ea948af..e78610258 100644 --- a/go/understack/cmd/init/init.go +++ b/go/understack/cmd/quickstart/quickstart.go @@ -20,17 +20,17 @@ import ( ) func init() { - cmd.RootCmd.AddCommand(Init) + cmd.RootCmd.AddCommand(Quickstart) } -var Init = &cobra.Command{ - Use: "init", - Short: "Run all the init the steps required", - Long: "Run all the init the steps required", - Run: initRun, +var Quickstart = &cobra.Command{ + Use: "quickstart", + Short: "Run all the steps required", + Long: "Run all the steps required", + Run: qsRun, } -func initRun(cmd *cobra.Command, args []string) { +func qsRun(cmd *cobra.Command, args []string) { log.Info("using envs", "DEPLOY_NAME", envutil.Getenv("DEPLOY_NAME"), diff --git a/go/understack/main.go b/go/understack/main.go index 3a41f4061..44c117f21 100644 --- a/go/understack/main.go +++ b/go/understack/main.go @@ -8,10 +8,10 @@ import ( _ "github.com/rackerlabs/understack/go/understack/cmd/certManager" _ "github.com/rackerlabs/understack/go/understack/cmd/dex" _ "github.com/rackerlabs/understack/go/understack/cmd/helmConfig" - _ "github.com/rackerlabs/understack/go/understack/cmd/init" _ "github.com/rackerlabs/understack/go/understack/cmd/node" _ "github.com/rackerlabs/understack/go/understack/cmd/openstack" _ "github.com/rackerlabs/understack/go/understack/cmd/other" + _ "github.com/rackerlabs/understack/go/understack/cmd/quickstart" ) func main() { From f92c2793711ba4bd19e394ee5848292e7db340b4 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Wed, 30 Apr 2025 15:05:42 -0500 Subject: [PATCH 2/7] feat(cli): nest existing commands under the 'deploy' subcommand As we expand this utility we've discussed adding other commands unrelated to the deployment operations so move the commands under 'deploy' now to future proof us. --- go/understack/cmd/argocd/secrets.go | 2 +- go/understack/cmd/certManager/secrets.go | 2 +- go/understack/cmd/deploy.go | 98 ++++++++++++++++++++++ go/understack/cmd/dex/secrets.go | 2 +- go/understack/cmd/helmConfig/helmConfig.go | 2 +- go/understack/cmd/node/node.go | 2 +- go/understack/cmd/openstack/secrets.go | 2 +- go/understack/cmd/other/other.go | 2 +- go/understack/cmd/quickstart/quickstart.go | 2 +- go/understack/cmd/root.go | 82 ++---------------- 10 files changed, 111 insertions(+), 85 deletions(-) create mode 100644 go/understack/cmd/deploy.go diff --git a/go/understack/cmd/argocd/secrets.go b/go/understack/cmd/argocd/secrets.go index 32ebc8e1f..2747e77a5 100644 --- a/go/understack/cmd/argocd/secrets.go +++ b/go/understack/cmd/argocd/secrets.go @@ -41,7 +41,7 @@ var ArgoCMD = &cobra.Command{ } func init() { - cmd.RootCmd.AddCommand(ArgoCMD) + cmd.DeployCmd.AddCommand(ArgoCMD) } // GenerateSecrets orchestrates the generation of all ArgoCD secrets diff --git a/go/understack/cmd/certManager/secrets.go b/go/understack/cmd/certManager/secrets.go index 18e545e9f..73feccaed 100644 --- a/go/understack/cmd/certManager/secrets.go +++ b/go/understack/cmd/certManager/secrets.go @@ -19,7 +19,7 @@ import ( var clusterIssuerTemplate string func init() { - cmd.RootCmd.AddCommand(CertManager) + cmd.DeployCmd.AddCommand(CertManager) } var CertManager = &cobra.Command{ diff --git a/go/understack/cmd/deploy.go b/go/understack/cmd/deploy.go new file mode 100644 index 000000000..9f6d8b409 --- /dev/null +++ b/go/understack/cmd/deploy.go @@ -0,0 +1,98 @@ +package cmd + +import ( + "fmt" + "github.com/charmbracelet/log" + "github.com/spf13/cobra" + "github.com/spf13/viper" + "os" + "path/filepath" + "strings" +) + +const ( + deployRepoEnvVar = "UC_DEPLOY" + deployRepoFlag = "deploy-repo" +) + +var DeployCmd = &cobra.Command{ + Use: "deploy [--deploy-repo UC_DEPLOY] command", + Short: "UnderStack deployment", + Long: ``, + RunE: func(cmd *cobra.Command, args []string) error { + // If no subcommand, show help + return cmd.Help() + }, + PersistentPreRunE: preRun, + PreRun: func(cmd *cobra.Command, args []string) { + }, + Run: func(cmd *cobra.Command, args []string) { + }, + PostRun: func(cmd *cobra.Command, args []string) { + }, + PersistentPostRun: func(cmd *cobra.Command, args []string) { + }, +} + +func expandPath(path string) (string, error) { + if strings.HasPrefix(path, "~") { + home, err := os.UserHomeDir() + if err != nil { + return "", err + } + return filepath.Join(home, path[1:]), nil + } + return path, nil +} + +func preRun(cmd *cobra.Command, args []string) error { + deployRepo := viper.GetString(deployRepoFlag) + if deployRepo == "" { + return nil + } + + expandedRepoDir, err := expandPath(deployRepo) + if err != nil { + return fmt.Errorf("failed to expand path: %w", err) + } + + info, err := os.Stat(expandedRepoDir) + if err != nil { + return fmt.Errorf("could not access directory '%s': %w", expandedRepoDir, err) + } + if !info.IsDir() { + return fmt.Errorf("path '%s' is not a directory", expandedRepoDir) + } + + // Switch working directory + if err := os.Chdir(expandedRepoDir); err != nil { + return fmt.Errorf("failed to change working directory to '%s': %w", expandedRepoDir, err) + } + + log.Infof("deployment repo path: %s", expandedRepoDir) + + return nil +} + +func init() { + // bind our flag + if err := viper.BindEnv(deployRepoFlag, deployRepoEnvVar); err != nil { + log.Fatal("failed to bind", "env", deployRepoFlag, "err", err) + os.Exit(1) + } + deployRepo := viper.GetString(deployRepoFlag) + if deployRepo == "" { + deployRepo = "." + } + helpText := fmt.Sprintf( + "Path to your deployment repo (env: %s) (current: %s)", + deployRepoEnvVar, deployRepo, + ) + DeployCmd.PersistentFlags().String(deployRepoFlag, "", helpText) + if err := viper.BindPFlag(deployRepoFlag, DeployCmd.PersistentFlags().Lookup(deployRepoFlag)); err != nil { + log.Fatal("failed to bind", "flag", deployRepoFlag, "err", err) + os.Exit(1) + } + + rootCmd.AddCommand(DeployCmd) +} diff --git a/go/understack/cmd/dex/secrets.go b/go/understack/cmd/dex/secrets.go index 1c07666dd..98ba92ed1 100644 --- a/go/understack/cmd/dex/secrets.go +++ b/go/understack/cmd/dex/secrets.go @@ -14,7 +14,7 @@ import ( ) func init() { - cmd.RootCmd.AddCommand(Dex) + cmd.DeployCmd.AddCommand(Dex) } var Dex = &cobra.Command{ diff --git a/go/understack/cmd/helmConfig/helmConfig.go b/go/understack/cmd/helmConfig/helmConfig.go index cbbe913f7..2122f06ba 100644 --- a/go/understack/cmd/helmConfig/helmConfig.go +++ b/go/understack/cmd/helmConfig/helmConfig.go @@ -14,7 +14,7 @@ import ( ) func init() { - cmd.RootCmd.AddCommand(HelmConfig) + cmd.DeployCmd.AddCommand(HelmConfig) } var HelmConfig = &cobra.Command{ diff --git a/go/understack/cmd/node/node.go b/go/understack/cmd/node/node.go index 83d3183d8..da0b024df 100644 --- a/go/understack/cmd/node/node.go +++ b/go/understack/cmd/node/node.go @@ -14,7 +14,7 @@ import ( ) func init() { - cmd.RootCmd.AddCommand(Node) + cmd.DeployCmd.AddCommand(Node) } var Node = &cobra.Command{ diff --git a/go/understack/cmd/openstack/secrets.go b/go/understack/cmd/openstack/secrets.go index 4f907c144..c589ca0ee 100644 --- a/go/understack/cmd/openstack/secrets.go +++ b/go/understack/cmd/openstack/secrets.go @@ -10,7 +10,7 @@ import ( ) func init() { - cmd.RootCmd.AddCommand(Openstack) + cmd.DeployCmd.AddCommand(Openstack) } var Openstack = &cobra.Command{ diff --git a/go/understack/cmd/other/other.go b/go/understack/cmd/other/other.go index 930c53842..60463be25 100644 --- a/go/understack/cmd/other/other.go +++ b/go/understack/cmd/other/other.go @@ -20,7 +20,7 @@ import ( ) func init() { - cmd.RootCmd.AddCommand(Other) + cmd.DeployCmd.AddCommand(Other) } var openStackSecrets map[string]any diff --git a/go/understack/cmd/quickstart/quickstart.go b/go/understack/cmd/quickstart/quickstart.go index e78610258..462f0f47c 100644 --- a/go/understack/cmd/quickstart/quickstart.go +++ b/go/understack/cmd/quickstart/quickstart.go @@ -20,7 +20,7 @@ import ( ) func init() { - cmd.RootCmd.AddCommand(Quickstart) + cmd.DeployCmd.AddCommand(Quickstart) } var Quickstart = &cobra.Command{ diff --git a/go/understack/cmd/root.go b/go/understack/cmd/root.go index e4d486cf5..4677de1d3 100644 --- a/go/understack/cmd/root.go +++ b/go/understack/cmd/root.go @@ -2,28 +2,17 @@ package cmd import ( "fmt" - "github.com/charmbracelet/log" "github.com/spf13/cobra" - "github.com/spf13/viper" - "os" - "path/filepath" - "strings" ) -const ( - deployRepoEnvVar = "UC_DEPLOY" - deployRepoFlag = "deploy-repo" -) - -var RootCmd = &cobra.Command{ - Use: "understack", - Short: "", +var rootCmd = &cobra.Command{ + Use: "understack SUBCOMMAND ...", + Short: "UnderStack CLI", Long: ``, RunE: func(cmd *cobra.Command, args []string) error { // If no subcommand, show help - return cmd.Help() + return fmt.Errorf("a subcommand is required") }, - PersistentPreRunE: preRun, PreRun: func(cmd *cobra.Command, args []string) { }, Run: func(cmd *cobra.Command, args []string) { @@ -34,68 +23,7 @@ var RootCmd = &cobra.Command{ }, } -func expandPath(path string) (string, error) { - if strings.HasPrefix(path, "~") { - home, err := os.UserHomeDir() - if err != nil { - return "", err - } - return filepath.Join(home, path[1:]), nil - } - return path, nil -} - -func preRun(cmd *cobra.Command, args []string) error { - deployRepo := viper.GetString(deployRepoFlag) - if deployRepo == "" { - return nil - } - - expandedRepoDir, err := expandPath(deployRepo) - if err != nil { - return fmt.Errorf("failed to expand path: %w", err) - } - - info, err := os.Stat(expandedRepoDir) - if err != nil { - return fmt.Errorf("could not access directory '%s': %w", expandedRepoDir, err) - } - if !info.IsDir() { - return fmt.Errorf("path '%s' is not a directory", expandedRepoDir) - } - - // Switch working directory - if err := os.Chdir(expandedRepoDir); err != nil { - return fmt.Errorf("failed to change working directory to '%s': %w", expandedRepoDir, err) - } - - log.Infof("deployment repo path: %s", expandedRepoDir) - - return nil -} - // Execute will execute the root command func Execute() error { - return RootCmd.Execute() -} - -func init() { - // bind our flag - if err := viper.BindEnv(deployRepoFlag, deployRepoEnvVar); err != nil { - log.Fatal("failed to bind", "env", deployRepoFlag, "err", err) - os.Exit(1) - } - deployRepo := viper.GetString(deployRepoFlag) - if deployRepo == "" { - deployRepo = "." - } - helpText := fmt.Sprintf( - "Path to your deployment repo (env: %s) (current: %s)", - deployRepoEnvVar, deployRepo, - ) - RootCmd.PersistentFlags().String(deployRepoFlag, "", helpText) - if err := viper.BindPFlag(deployRepoFlag, RootCmd.PersistentFlags().Lookup(deployRepoFlag)); err != nil { - log.Fatal("failed to bind", "flag", deployRepoFlag, "err", err) - os.Exit(1) - } + return rootCmd.Execute() } From d96d3ea7c702bc0fe5fb4ac9b8fbf61f19c1f12e Mon Sep 17 00:00:00 2001 From: Abhimanyu Sharma Date: Tue, 6 May 2025 15:12:11 +0530 Subject: [PATCH 3/7] feat: code refactor and cleanup --- .../cmd/argocd/{secrets.go => argocd.go} | 31 +++++++------- .../certManager/{secrets.go => certManger.go} | 17 ++++---- go/understack/cmd/{ => deploy}/deploy.go | 1 - go/understack/cmd/dex/{secrets.go => dex.go} | 17 ++++---- go/understack/cmd/helmConfig/helmConfig.go | 42 +++++++++---------- go/understack/cmd/node/node.go | 17 ++++---- go/understack/cmd/openstack/secrets.go | 17 ++++---- go/understack/cmd/other/other.go | 23 +++++----- go/understack/cmd/quickstart/quickstart.go | 38 ++++++++--------- go/understack/cmd/root.go | 29 ------------- go/understack/cmd/root/root.go | 41 ++++++++++++++++++ go/understack/main.go | 18 +++----- 12 files changed, 134 insertions(+), 157 deletions(-) rename go/understack/cmd/argocd/{secrets.go => argocd.go} (83%) rename go/understack/cmd/certManager/{secrets.go => certManger.go} (82%) rename go/understack/cmd/{ => deploy}/deploy.go (98%) rename go/understack/cmd/dex/{secrets.go => dex.go} (79%) delete mode 100644 go/understack/cmd/root.go create mode 100644 go/understack/cmd/root/root.go diff --git a/go/understack/cmd/argocd/secrets.go b/go/understack/cmd/argocd/argocd.go similarity index 83% rename from go/understack/cmd/argocd/secrets.go rename to go/understack/cmd/argocd/argocd.go index 2747e77a5..1eb0e4536 100644 --- a/go/understack/cmd/argocd/secrets.go +++ b/go/understack/cmd/argocd/argocd.go @@ -6,7 +6,6 @@ import ( "os" "path/filepath" - "github.com/rackerlabs/understack/go/understack/cmd" "github.com/rackerlabs/understack/go/understack/helpers" "github.com/charmbracelet/log" @@ -28,24 +27,22 @@ const ( argoNamespace = "argocd" ) -var ArgoCMD = &cobra.Command{ - Use: "argocd-secrets", - Short: "Generate ArgoCD secrets", - Long: "Generate repository and cluster secrets for ArgoCD deployment", - Run: func(cmd *cobra.Command, args []string) { - if err := GenerateSecrets(); err != nil { - log.Fatal("Failed to generate secrets", "error", err) - os.Exit(1) - } - }, -} - -func init() { - cmd.DeployCmd.AddCommand(ArgoCMD) +func NewCmdArgocdSecret() *cobra.Command { + return &cobra.Command{ + Use: "argocd-secrets", + Short: "Generate ArgoCD secrets", + Long: "Generate repository and cluster secrets for ArgoCD deployment", + Run: func(cmd *cobra.Command, args []string) { + if err := generateSecrets(); err != nil { + log.Fatal("Failed to generate secrets", "error", err) + os.Exit(1) + } + }, + } } -// GenerateSecrets orchestrates the generation of all ArgoCD secrets -func GenerateSecrets() error { +// generateSecrets orchestrates the generation of all ArgoCD secrets +func generateSecrets() error { basePath := helpers.GetManifestPathToService("argocd") if err := generateDeployRepoSecret(basePath); err != nil { diff --git a/go/understack/cmd/certManager/secrets.go b/go/understack/cmd/certManager/certManger.go similarity index 82% rename from go/understack/cmd/certManager/secrets.go rename to go/understack/cmd/certManager/certManger.go index 73feccaed..5febbc4a9 100644 --- a/go/understack/cmd/certManager/secrets.go +++ b/go/understack/cmd/certManager/certManger.go @@ -5,7 +5,6 @@ import ( "fmt" "os" - "github.com/rackerlabs/understack/go/understack/cmd" "github.com/rackerlabs/understack/go/understack/helpers" "github.com/charmbracelet/log" @@ -18,15 +17,13 @@ import ( //go:embed templates/clusterIssuer.tmpl var clusterIssuerTemplate string -func init() { - cmd.DeployCmd.AddCommand(CertManager) -} - -var CertManager = &cobra.Command{ - Use: "certmanager-secrets", - Short: "Generate certmanager-secrets secrets", - Long: "", - Run: certManagerGen, +func NewCmdCertManagerSecret() *cobra.Command { + return &cobra.Command{ + Use: "certmanager-secrets", + Short: "Generate certmanager-secrets secrets", + Long: "", + Run: certManagerGen, + } } func certManagerGen(cmd *cobra.Command, args []string) { diff --git a/go/understack/cmd/deploy.go b/go/understack/cmd/deploy/deploy.go similarity index 98% rename from go/understack/cmd/deploy.go rename to go/understack/cmd/deploy/deploy.go index 9f6d8b409..0aed5b25f 100644 --- a/go/understack/cmd/deploy.go +++ b/go/understack/cmd/deploy/deploy.go @@ -94,5 +94,4 @@ func init() { os.Exit(1) } - rootCmd.AddCommand(DeployCmd) } diff --git a/go/understack/cmd/dex/secrets.go b/go/understack/cmd/dex/dex.go similarity index 79% rename from go/understack/cmd/dex/secrets.go rename to go/understack/cmd/dex/dex.go index 98ba92ed1..c073d6592 100644 --- a/go/understack/cmd/dex/secrets.go +++ b/go/understack/cmd/dex/dex.go @@ -4,7 +4,6 @@ import ( "fmt" "path/filepath" - "github.com/rackerlabs/understack/go/understack/cmd" "github.com/rackerlabs/understack/go/understack/helpers" "github.com/charmbracelet/log" @@ -13,15 +12,13 @@ import ( "github.com/spf13/cobra" ) -func init() { - cmd.DeployCmd.AddCommand(Dex) -} - -var Dex = &cobra.Command{ - Use: "dex-secrets", - Short: "Create dex secret for nautobot, argo, argocd, keystone, grafana", - Long: "Create dex secret for nautobot, argo, argocd, keystone, grafana", - Run: generateDexSecrets, +func NewCmdDexSecrets() *cobra.Command { + return &cobra.Command{ + Use: "dex-secrets", + Short: "Create dex secret for nautobot, argo, argocd, keystone, grafana", + Long: "Create dex secret for nautobot, argo, argocd, keystone, grafana", + Run: generateDexSecrets, + } } func generateDexSecrets(cmd *cobra.Command, args []string) { diff --git a/go/understack/cmd/helmConfig/helmConfig.go b/go/understack/cmd/helmConfig/helmConfig.go index 2122f06ba..523b1c75c 100644 --- a/go/understack/cmd/helmConfig/helmConfig.go +++ b/go/understack/cmd/helmConfig/helmConfig.go @@ -5,7 +5,6 @@ import ( "os" "path/filepath" - "github.com/rackerlabs/understack/go/understack/cmd" "github.com/rackerlabs/understack/go/understack/helpers" "github.com/gookit/goutil/envutil" @@ -13,30 +12,27 @@ import ( "github.com/spf13/cobra" ) -func init() { - cmd.DeployCmd.AddCommand(HelmConfig) -} - -var HelmConfig = &cobra.Command{ - Use: "helm-config", - Short: "Create helm config for individual services", - Long: "", - Run: helmConfigGen, +func NewCmdHelmConfig() *cobra.Command { + return &cobra.Command{ + Use: "helm-config", + Short: "Create helm config for individual services", + Long: "", + Run: helmConfigGen, + } } - func helmConfigGen(cmd *cobra.Command, args []string) { - functions := []func() error{ - dex, - glance, - ironic, - rook, - } - for _, fn := range functions { - if err := fn(); err != nil { - fmt.Printf("Error helmConfigGen: %v\n", err) - os.Exit(1) - } - } + functions := []func() error{ + dex, + glance, + ironic, + rook, + } + for _, fn := range functions { + if err := fn(); err != nil { + fmt.Printf("Error helmConfigGen: %v\n", err) + os.Exit(1) + } + } } func dex() error { diff --git a/go/understack/cmd/node/node.go b/go/understack/cmd/node/node.go index da0b024df..ddb0f606b 100644 --- a/go/understack/cmd/node/node.go +++ b/go/understack/cmd/node/node.go @@ -4,7 +4,6 @@ import ( "context" "os" - "github.com/rackerlabs/understack/go/understack/cmd" "github.com/rackerlabs/understack/go/understack/helpers" "github.com/charmbracelet/log" @@ -13,15 +12,13 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func init() { - cmd.DeployCmd.AddCommand(Node) -} - -var Node = &cobra.Command{ - Use: "node-update", - Short: "Will update k8s cluster node with labels and tags", - Long: "Will update k8s cluster node with labels and tags", - Run: updateNode, +func NewCmdNode() *cobra.Command { + return &cobra.Command{ + Use: "node-update", + Short: "Will update k8s cluster node with labels and tags", + Long: "Will update k8s cluster node with labels and tags", + Run: updateNode, + } } func updateNode(cmd *cobra.Command, args []string) { diff --git a/go/understack/cmd/openstack/secrets.go b/go/understack/cmd/openstack/secrets.go index c589ca0ee..27c81d30d 100644 --- a/go/understack/cmd/openstack/secrets.go +++ b/go/understack/cmd/openstack/secrets.go @@ -1,7 +1,6 @@ package openstack import ( - "github.com/rackerlabs/understack/go/understack/cmd" "github.com/rackerlabs/understack/go/understack/helpers" "github.com/charmbracelet/log" @@ -9,15 +8,13 @@ import ( "github.com/spf13/cobra" ) -func init() { - cmd.DeployCmd.AddCommand(Openstack) -} - -var Openstack = &cobra.Command{ - Use: "openstack-secrets", - Short: "Generate openstack-secrets", - Long: "Generate openstack-secrets", - Run: openStackGen, +func NewCmdOpenstackSecrets() *cobra.Command { + return &cobra.Command{ + Use: "openstack-secrets", + Short: "Generate openstack-secrets", + Long: "Generate openstack-secrets", + Run: openStackGen, + } } func openStackGen(cmd *cobra.Command, args []string) { diff --git a/go/understack/cmd/other/other.go b/go/understack/cmd/other/other.go index 60463be25..35165196c 100644 --- a/go/understack/cmd/other/other.go +++ b/go/understack/cmd/other/other.go @@ -4,7 +4,6 @@ import ( "os" "path/filepath" - "github.com/rackerlabs/understack/go/understack/cmd" "github.com/rackerlabs/understack/go/understack/helpers" "github.com/charmbracelet/log" @@ -19,17 +18,15 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func init() { - cmd.DeployCmd.AddCommand(Other) -} - var openStackSecrets map[string]any -var Other = &cobra.Command{ - Use: "other-secrets", - Short: "Create secret for keystone, ironic, placement, neutron, nova, glance", - Long: "Create secret for keystone, ironic, placement, neutron, nova, glance", - Run: generateOtherSecrets, +func NewCmdOtherSecrets() *cobra.Command { + return &cobra.Command{ + Use: "other-secrets", + Short: "Create secret for keystone, ironic, placement, neutron, nova, glance", + Long: "Create secret for keystone, ironic, placement, neutron, nova, glance", + Run: generateOtherSecrets, + } } func generateOtherSecrets(_ *cobra.Command, _ []string) { @@ -59,9 +56,9 @@ func generateOtherSecrets(_ *cobra.Command, _ []string) { // Create Empty Dirs emptyDirs := []string{"argo-events", "ovn", "metallb", "undersync", "cilium"} for _, service := range emptyDirs { - if err := fsutil.WriteFile(helpers.GetManifestPathToService(service)+"/.keep", "", os.ModePerm); err != nil { - log.Errorf("Failed creating .keep file for %s: %v", service, err) - } + if err := fsutil.WriteFile(helpers.GetManifestPathToService(service)+"/.keep", "", os.ModePerm); err != nil { + log.Errorf("Failed creating .keep file for %s: %v", service, err) + } } } diff --git a/go/understack/cmd/quickstart/quickstart.go b/go/understack/cmd/quickstart/quickstart.go index 462f0f47c..842303597 100644 --- a/go/understack/cmd/quickstart/quickstart.go +++ b/go/understack/cmd/quickstart/quickstart.go @@ -1,11 +1,12 @@ -package ironic +package quickstart import ( "fmt" "os" "os/exec" - "github.com/rackerlabs/understack/go/understack/cmd" + "github.com/charmbracelet/log" + "github.com/gookit/goutil/envutil" "github.com/rackerlabs/understack/go/understack/cmd/argocd" "github.com/rackerlabs/understack/go/understack/cmd/certManager" "github.com/rackerlabs/understack/go/understack/cmd/dex" @@ -13,21 +14,16 @@ import ( "github.com/rackerlabs/understack/go/understack/cmd/node" "github.com/rackerlabs/understack/go/understack/cmd/openstack" "github.com/rackerlabs/understack/go/understack/cmd/other" - - "github.com/charmbracelet/log" - "github.com/gookit/goutil/envutil" "github.com/spf13/cobra" ) -func init() { - cmd.DeployCmd.AddCommand(Quickstart) -} - -var Quickstart = &cobra.Command{ - Use: "quickstart", - Short: "Run all the steps required", - Long: "Run all the steps required", - Run: qsRun, +func NewCmdQuickStart() *cobra.Command { + return &cobra.Command{ + Use: "quickstart", + Short: "Run all the steps required", + Long: "Run all the steps required", + Run: qsRun, + } } func qsRun(cmd *cobra.Command, args []string) { @@ -60,23 +56,23 @@ func qsRun(cmd *cobra.Command, args []string) { fmt.Println(envutil.Getenv("DEPLOY_NAME")) log.Info("== Node Update") - node.Node.Run(cmd, args) + node.NewCmdNode().Run(cmd, args) log.Info("== Node ArgoCd") - argocd.ArgoCMD.Run(cmd, args) + argocd.NewCmdArgocdSecret().Run(cmd, args) log.Info("== Node Cert Manager") - certManager.CertManager.Run(cmd, args) + certManager.NewCmdCertManagerSecret().Run(cmd, args) log.Info("== Running Dex") - dex.Dex.Run(cmd, args) + dex.NewCmdDexSecrets().Run(cmd, args) log.Info("== Running For Other Services") - other.Other.Run(cmd, args) + other.NewCmdOtherSecrets().Run(cmd, args) log.Info("== Running Openstack") - openstack.Openstack.Run(cmd, args) + openstack.NewCmdOpenstackSecrets().Run(cmd, args) log.Info("== Creating Helm Configs") - helmConfig.HelmConfig.Run(cmd, args) + helmConfig.NewCmdHelmConfig().Run(cmd, args) } diff --git a/go/understack/cmd/root.go b/go/understack/cmd/root.go deleted file mode 100644 index 4677de1d3..000000000 --- a/go/understack/cmd/root.go +++ /dev/null @@ -1,29 +0,0 @@ -package cmd - -import ( - "fmt" - "github.com/spf13/cobra" -) - -var rootCmd = &cobra.Command{ - Use: "understack SUBCOMMAND ...", - Short: "UnderStack CLI", - Long: ``, - RunE: func(cmd *cobra.Command, args []string) error { - // If no subcommand, show help - return fmt.Errorf("a subcommand is required") - }, - PreRun: func(cmd *cobra.Command, args []string) { - }, - Run: func(cmd *cobra.Command, args []string) { - }, - PostRun: func(cmd *cobra.Command, args []string) { - }, - PersistentPostRun: func(cmd *cobra.Command, args []string) { - }, -} - -// Execute will execute the root command -func Execute() error { - return rootCmd.Execute() -} diff --git a/go/understack/cmd/root/root.go b/go/understack/cmd/root/root.go new file mode 100644 index 000000000..6881a478d --- /dev/null +++ b/go/understack/cmd/root/root.go @@ -0,0 +1,41 @@ +package root + +import ( + "fmt" + + "github.com/rackerlabs/understack/go/understack/cmd/argocd" + "github.com/rackerlabs/understack/go/understack/cmd/certManager" + "github.com/rackerlabs/understack/go/understack/cmd/dex" + "github.com/rackerlabs/understack/go/understack/cmd/helmConfig" + "github.com/rackerlabs/understack/go/understack/cmd/node" + "github.com/rackerlabs/understack/go/understack/cmd/openstack" + "github.com/rackerlabs/understack/go/understack/cmd/other" + "github.com/rackerlabs/understack/go/understack/cmd/quickstart" + "github.com/spf13/cobra" +) + +var rootCmd = &cobra.Command{ + Use: "understack SUBCOMMAND ...", + Short: "UnderStack CLI", + Long: ``, + RunE: func(cmd *cobra.Command, args []string) error { + // If no subcommand, show help + return fmt.Errorf("a subcommand is required") + }, +} + +func init() { + rootCmd.AddCommand(argocd.NewCmdArgocdSecret()) + rootCmd.AddCommand(certManager.NewCmdCertManagerSecret()) + rootCmd.AddCommand(dex.NewCmdDexSecrets()) + rootCmd.AddCommand(helmConfig.NewCmdHelmConfig()) + rootCmd.AddCommand(node.NewCmdNode()) + rootCmd.AddCommand(openstack.NewCmdOpenstackSecrets()) + rootCmd.AddCommand(quickstart.NewCmdQuickStart()) + rootCmd.AddCommand(other.NewCmdOtherSecrets()) +} + +// Execute will execute the root command +func Execute() error { + return rootCmd.Execute() +} diff --git a/go/understack/main.go b/go/understack/main.go index 44c117f21..09b46d8d3 100644 --- a/go/understack/main.go +++ b/go/understack/main.go @@ -3,20 +3,12 @@ package main import ( "os" - "github.com/rackerlabs/understack/go/understack/cmd" - _ "github.com/rackerlabs/understack/go/understack/cmd/argocd" - _ "github.com/rackerlabs/understack/go/understack/cmd/certManager" - _ "github.com/rackerlabs/understack/go/understack/cmd/dex" - _ "github.com/rackerlabs/understack/go/understack/cmd/helmConfig" - _ "github.com/rackerlabs/understack/go/understack/cmd/node" - _ "github.com/rackerlabs/understack/go/understack/cmd/openstack" - _ "github.com/rackerlabs/understack/go/understack/cmd/other" - _ "github.com/rackerlabs/understack/go/understack/cmd/quickstart" + "github.com/rackerlabs/understack/go/understack/cmd/root" ) func main() { - err := cmd.Execute() - if err != nil { - os.Exit(1) - } + err := root.Execute() + if err != nil { + os.Exit(1) + } } From aa9dff57821602cd12052411fbf0e6b115014b2c Mon Sep 17 00:00:00 2001 From: Abhimanyu Sharma Date: Tue, 6 May 2025 15:32:29 +0530 Subject: [PATCH 4/7] fix: deploy command --- go/understack/cmd/deploy/deploy.go | 48 ++++++++++++++---------------- go/understack/cmd/root/root.go | 2 ++ 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/go/understack/cmd/deploy/deploy.go b/go/understack/cmd/deploy/deploy.go index 0aed5b25f..d08462725 100644 --- a/go/understack/cmd/deploy/deploy.go +++ b/go/understack/cmd/deploy/deploy.go @@ -1,13 +1,14 @@ -package cmd +package deploy import ( "fmt" - "github.com/charmbracelet/log" - "github.com/spf13/cobra" - "github.com/spf13/viper" "os" "path/filepath" "strings" + + "github.com/charmbracelet/log" + "github.com/spf13/cobra" + "github.com/spf13/viper" ) const ( @@ -15,23 +16,21 @@ const ( deployRepoFlag = "deploy-repo" ) -var DeployCmd = &cobra.Command{ - Use: "deploy [--deploy-repo UC_DEPLOY] command", - Short: "UnderStack deployment", - Long: ``, - RunE: func(cmd *cobra.Command, args []string) error { - // If no subcommand, show help - return cmd.Help() - }, - PersistentPreRunE: preRun, - PreRun: func(cmd *cobra.Command, args []string) { - }, - Run: func(cmd *cobra.Command, args []string) { - }, - PostRun: func(cmd *cobra.Command, args []string) { - }, - PersistentPostRun: func(cmd *cobra.Command, args []string) { - }, +func NewCmdDeploy() *cobra.Command { + cmd := &cobra.Command{ + Use: "deploy [--deploy-repo UC_DEPLOY] command", + Short: "UnderStack deployment", + Long: ``, + RunE: func(cmd *cobra.Command, args []string) error { + // If no subcommand, show help + return cmd.Help() + }, + PersistentPreRunE: preRun, + } + + setFlags(cmd) + + return cmd } func expandPath(path string) (string, error) { @@ -74,7 +73,7 @@ func preRun(cmd *cobra.Command, args []string) error { return nil } -func init() { +func setFlags(cmd *cobra.Command) { // bind our flag if err := viper.BindEnv(deployRepoFlag, deployRepoEnvVar); err != nil { log.Fatal("failed to bind", "env", deployRepoFlag, "err", err) @@ -88,10 +87,9 @@ func init() { "Path to your deployment repo (env: %s) (current: %s)", deployRepoEnvVar, deployRepo, ) - DeployCmd.PersistentFlags().String(deployRepoFlag, "", helpText) - if err := viper.BindPFlag(deployRepoFlag, DeployCmd.PersistentFlags().Lookup(deployRepoFlag)); err != nil { + cmd.PersistentFlags().String(deployRepoFlag, "", helpText) + if err := viper.BindPFlag(deployRepoFlag, cmd.PersistentFlags().Lookup(deployRepoFlag)); err != nil { log.Fatal("failed to bind", "flag", deployRepoFlag, "err", err) os.Exit(1) } - } diff --git a/go/understack/cmd/root/root.go b/go/understack/cmd/root/root.go index 6881a478d..b0bd1d889 100644 --- a/go/understack/cmd/root/root.go +++ b/go/understack/cmd/root/root.go @@ -5,6 +5,7 @@ import ( "github.com/rackerlabs/understack/go/understack/cmd/argocd" "github.com/rackerlabs/understack/go/understack/cmd/certManager" + "github.com/rackerlabs/understack/go/understack/cmd/deploy" "github.com/rackerlabs/understack/go/understack/cmd/dex" "github.com/rackerlabs/understack/go/understack/cmd/helmConfig" "github.com/rackerlabs/understack/go/understack/cmd/node" @@ -25,6 +26,7 @@ var rootCmd = &cobra.Command{ } func init() { + rootCmd.AddCommand(deploy.NewCmdDeploy()) rootCmd.AddCommand(argocd.NewCmdArgocdSecret()) rootCmd.AddCommand(certManager.NewCmdCertManagerSecret()) rootCmd.AddCommand(dex.NewCmdDexSecrets()) From 851a4831ee80d5c527dfb9b63ef10631435c87f2 Mon Sep 17 00:00:00 2001 From: Abhimanyu Sharma Date: Tue, 6 May 2025 15:58:34 +0530 Subject: [PATCH 5/7] fix: function rename --- go/understack/cmd/deploy/deploy.go | 89 +++++++++++++++--------------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/go/understack/cmd/deploy/deploy.go b/go/understack/cmd/deploy/deploy.go index d08462725..d53dc7e10 100644 --- a/go/understack/cmd/deploy/deploy.go +++ b/go/understack/cmd/deploy/deploy.go @@ -16,80 +16,81 @@ const ( deployRepoFlag = "deploy-repo" ) +// NewCmdDeploy returns the root "deploy" command for UnderStack deployments. func NewCmdDeploy() *cobra.Command { cmd := &cobra.Command{ Use: "deploy [--deploy-repo UC_DEPLOY] command", Short: "UnderStack deployment", - Long: ``, RunE: func(cmd *cobra.Command, args []string) error { - // If no subcommand, show help + // Show help if no subcommands are provided return cmd.Help() }, - PersistentPreRunE: preRun, + PersistentPreRunE: ensureDeployRepo, } - setFlags(cmd) - + addDeployRepoFlag(cmd) return cmd } -func expandPath(path string) (string, error) { - if strings.HasPrefix(path, "~") { - home, err := os.UserHomeDir() - if err != nil { - return "", err - } - return filepath.Join(home, path[1:]), nil +// addDeployRepoFlag binds and configures the persistent --deploy-repo flag. +func addDeployRepoFlag(cmd *cobra.Command) { + // Bind environment variable + if err := viper.BindEnv(deployRepoFlag, deployRepoEnvVar); err != nil { + log.Fatal("failed to bind env var", "env", deployRepoEnvVar, "err", err) + os.Exit(1) + } + + // Set default value from env or fallback + defaultRepo := viper.GetString(deployRepoFlag) + if defaultRepo == "" { + defaultRepo = "." + } + + help := fmt.Sprintf("Path to your deployment repo (env: %s) (current: %s)", deployRepoEnvVar, defaultRepo) + cmd.PersistentFlags().String(deployRepoFlag, "", help) + + if err := viper.BindPFlag(deployRepoFlag, cmd.PersistentFlags().Lookup(deployRepoFlag)); err != nil { + log.Fatal("failed to bind flag", "flag", deployRepoFlag, "err", err) + os.Exit(1) } - return path, nil } -func preRun(cmd *cobra.Command, args []string) error { - deployRepo := viper.GetString(deployRepoFlag) - if deployRepo == "" { - return nil +// ensureDeployRepo validates and switches to the deployment repo directory, if provided. +func ensureDeployRepo(cmd *cobra.Command, args []string) error { + repoPath := viper.GetString(deployRepoFlag) + if repoPath == "" { + return nil // nothing to do } - expandedRepoDir, err := expandPath(deployRepo) + expandedPath, err := expandHomePath(repoPath) if err != nil { return fmt.Errorf("failed to expand path: %w", err) } - info, err := os.Stat(expandedRepoDir) + info, err := os.Stat(expandedPath) if err != nil { - return fmt.Errorf("could not access directory '%s': %w", expandedRepoDir, err) + return fmt.Errorf("could not access directory '%s': %w", expandedPath, err) } if !info.IsDir() { - return fmt.Errorf("path '%s' is not a directory", expandedRepoDir) + return fmt.Errorf("path '%s' is not a directory", expandedPath) } - // Switch working directory - if err := os.Chdir(expandedRepoDir); err != nil { - return fmt.Errorf("failed to change working directory to '%s': %w", expandedRepoDir, err) + if err := os.Chdir(expandedPath); err != nil { + return fmt.Errorf("failed to change working directory to '%s': %w", expandedPath, err) } - log.Infof("deployment repo path: %s", expandedRepoDir) - + log.Infof("Using deployment repo: %s", expandedPath) return nil } -func setFlags(cmd *cobra.Command) { - // bind our flag - if err := viper.BindEnv(deployRepoFlag, deployRepoEnvVar); err != nil { - log.Fatal("failed to bind", "env", deployRepoFlag, "err", err) - os.Exit(1) - } - deployRepo := viper.GetString(deployRepoFlag) - if deployRepo == "" { - deployRepo = "." - } - helpText := fmt.Sprintf( - "Path to your deployment repo (env: %s) (current: %s)", - deployRepoEnvVar, deployRepo, - ) - cmd.PersistentFlags().String(deployRepoFlag, "", helpText) - if err := viper.BindPFlag(deployRepoFlag, cmd.PersistentFlags().Lookup(deployRepoFlag)); err != nil { - log.Fatal("failed to bind", "flag", deployRepoFlag, "err", err) - os.Exit(1) +// expandHomePath expands a path starting with "~" to the user's home directory. +func expandHomePath(path string) (string, error) { + if strings.HasPrefix(path, "~") { + home, err := os.UserHomeDir() + if err != nil { + return "", err + } + return filepath.Join(home, path[1:]), nil } + return path, nil } From 9c71c1e2fcc53116d5fbf609b8d06c67ab4aef78 Mon Sep 17 00:00:00 2001 From: Abhimanyu Sharma Date: Tue, 6 May 2025 23:02:36 +0530 Subject: [PATCH 6/7] fix: rename understack to understackctl --- go/understack/.goreleaser.yaml | 48 ------------------- .../.editorconfig | 0 go/{understack => understackctl}/.gitignore | 0 go/{understack => understackctl}/README.md | 2 +- .../cmd/argocd/argocd.go | 2 +- .../cmd/argocd/templates/argoCluster.tmpl | 0 .../templates/argoSecretDeployRepo.tmpl | 0 .../cmd/certManager/certManger.go | 2 +- .../certManager/templates/clusterIssuer.tmpl | 0 .../cmd/deploy/deploy.go | 0 .../cmd/dex/dex.go | 2 +- .../cmd/helmConfig/helmConfig.go | 2 +- .../cmd/node/node.go | 2 +- .../cmd/openstack/secrets.go | 2 +- .../cmd/other/openstack.go | 0 .../cmd/other/other.go | 2 +- .../cmd/quickstart/quickstart.go | 14 +++--- .../cmd/root/root.go | 20 ++++---- go/{understack => understackctl}/go.mod | 2 +- go/{understack => understackctl}/go.sum | 0 .../helpers/helpers.go | 0 .../helpers/kube.go | 0 .../helpers/kubeseal.go | 0 .../helpers/kustomization.go | 0 .../helpers/random.go | 0 .../helpers/template.go | 0 go/{understack => understackctl}/main.go | 2 +- 27 files changed, 27 insertions(+), 75 deletions(-) delete mode 100644 go/understack/.goreleaser.yaml rename go/{understack => understackctl}/.editorconfig (100%) rename go/{understack => understackctl}/.gitignore (100%) rename go/{understack => understackctl}/README.md (97%) rename go/{understack => understackctl}/cmd/argocd/argocd.go (98%) rename go/{understack => understackctl}/cmd/argocd/templates/argoCluster.tmpl (100%) rename go/{understack => understackctl}/cmd/argocd/templates/argoSecretDeployRepo.tmpl (100%) rename go/{understack => understackctl}/cmd/certManager/certManger.go (95%) rename go/{understack => understackctl}/cmd/certManager/templates/clusterIssuer.tmpl (100%) rename go/{understack => understackctl}/cmd/deploy/deploy.go (100%) rename go/{understack => understackctl}/cmd/dex/dex.go (95%) rename go/{understack => understackctl}/cmd/helmConfig/helmConfig.go (98%) rename go/{understack => understackctl}/cmd/node/node.go (95%) rename go/{understack => understackctl}/cmd/openstack/secrets.go (94%) rename go/{understack => understackctl}/cmd/other/openstack.go (100%) rename go/{understack => understackctl}/cmd/other/other.go (98%) rename go/{understack => understackctl}/cmd/quickstart/quickstart.go (78%) rename go/{understack => understackctl}/cmd/root/root.go (56%) rename go/{understack => understackctl}/go.mod (98%) rename go/{understack => understackctl}/go.sum (100%) rename go/{understack => understackctl}/helpers/helpers.go (100%) rename go/{understack => understackctl}/helpers/kube.go (100%) rename go/{understack => understackctl}/helpers/kubeseal.go (100%) rename go/{understack => understackctl}/helpers/kustomization.go (100%) rename go/{understack => understackctl}/helpers/random.go (100%) rename go/{understack => understackctl}/helpers/template.go (100%) rename go/{understack => understackctl}/main.go (62%) diff --git a/go/understack/.goreleaser.yaml b/go/understack/.goreleaser.yaml deleted file mode 100644 index 2f5a376a5..000000000 --- a/go/understack/.goreleaser.yaml +++ /dev/null @@ -1,48 +0,0 @@ -# This is an example .goreleaser.yml file with some sensible defaults. -# Make sure to check the documentation at https://goreleaser.com - -# The lines below are called `modelines`. See `:help modeline` -# Feel free to remove those if you don't want/need to use them. -# yaml-language-server: $schema=https://goreleaser.com/static/schema.json -# vim: set ts=2 sw=2 tw=0 fo=cnqoj - -version: 2 - -before: - hooks: - # You may remove this if you don't use go modules. - - go mod tidy - -builds: - - env: - - CGO_ENABLED=0 - goos: ["linux", "darwin", "windows"] - goarch: ["386", "amd64", "arm64"] - binary: understack - ldflags: - - -s -w -X "main.version={{.Version}}" - -universal_binaries: - - replace: true - -archives: - - formats: [tar.gz] - # this name template makes the OS and Arch compatible with the results of `uname`. - name_template: >- - {{ .ProjectName }}_ - {{- title .Os }}_ - {{- if eq .Arch "amd64" }}x86_64 - {{- else if eq .Arch "386" }}i386 - {{- else }}{{ .Arch }}{{ end }} - {{- if .Arm }}v{{ .Arm }}{{ end }} - # use zip for windows archives - format_overrides: - - goos: windows - formats: [zip] - -changelog: - sort: asc - filters: - exclude: - - "^docs:" - - "^test:" diff --git a/go/understack/.editorconfig b/go/understackctl/.editorconfig similarity index 100% rename from go/understack/.editorconfig rename to go/understackctl/.editorconfig diff --git a/go/understack/.gitignore b/go/understackctl/.gitignore similarity index 100% rename from go/understack/.gitignore rename to go/understackctl/.gitignore diff --git a/go/understack/README.md b/go/understackctl/README.md similarity index 97% rename from go/understack/README.md rename to go/understackctl/README.md index 18a0a8b36..5550d18aa 100644 --- a/go/understack/README.md +++ b/go/understackctl/README.md @@ -30,4 +30,4 @@ go run *.go help ## Contributing -If you find any issues or have suggestions for improvements, please open an issue on the [GitHub repository](https://github.com/rackerlabs/understack). +If you find any issues or have suggestions for improvements, please open an issue on the [GitHub repository](https://github.com/rackerlabs/understack). \ No newline at end of file diff --git a/go/understack/cmd/argocd/argocd.go b/go/understackctl/cmd/argocd/argocd.go similarity index 98% rename from go/understack/cmd/argocd/argocd.go rename to go/understackctl/cmd/argocd/argocd.go index 1eb0e4536..b72d1bd2f 100644 --- a/go/understack/cmd/argocd/argocd.go +++ b/go/understackctl/cmd/argocd/argocd.go @@ -6,7 +6,7 @@ import ( "os" "path/filepath" - "github.com/rackerlabs/understack/go/understack/helpers" + "github.com/rackerlabs/understack/go/understackctl/helpers" "github.com/charmbracelet/log" "github.com/gookit/goutil/envutil" diff --git a/go/understack/cmd/argocd/templates/argoCluster.tmpl b/go/understackctl/cmd/argocd/templates/argoCluster.tmpl similarity index 100% rename from go/understack/cmd/argocd/templates/argoCluster.tmpl rename to go/understackctl/cmd/argocd/templates/argoCluster.tmpl diff --git a/go/understack/cmd/argocd/templates/argoSecretDeployRepo.tmpl b/go/understackctl/cmd/argocd/templates/argoSecretDeployRepo.tmpl similarity index 100% rename from go/understack/cmd/argocd/templates/argoSecretDeployRepo.tmpl rename to go/understackctl/cmd/argocd/templates/argoSecretDeployRepo.tmpl diff --git a/go/understack/cmd/certManager/certManger.go b/go/understackctl/cmd/certManager/certManger.go similarity index 95% rename from go/understack/cmd/certManager/certManger.go rename to go/understackctl/cmd/certManager/certManger.go index 5febbc4a9..6c6f9af80 100644 --- a/go/understack/cmd/certManager/certManger.go +++ b/go/understackctl/cmd/certManager/certManger.go @@ -5,7 +5,7 @@ import ( "fmt" "os" - "github.com/rackerlabs/understack/go/understack/helpers" + "github.com/rackerlabs/understack/go/understackctl/helpers" "github.com/charmbracelet/log" "github.com/gookit/goutil/envutil" diff --git a/go/understack/cmd/certManager/templates/clusterIssuer.tmpl b/go/understackctl/cmd/certManager/templates/clusterIssuer.tmpl similarity index 100% rename from go/understack/cmd/certManager/templates/clusterIssuer.tmpl rename to go/understackctl/cmd/certManager/templates/clusterIssuer.tmpl diff --git a/go/understack/cmd/deploy/deploy.go b/go/understackctl/cmd/deploy/deploy.go similarity index 100% rename from go/understack/cmd/deploy/deploy.go rename to go/understackctl/cmd/deploy/deploy.go diff --git a/go/understack/cmd/dex/dex.go b/go/understackctl/cmd/dex/dex.go similarity index 95% rename from go/understack/cmd/dex/dex.go rename to go/understackctl/cmd/dex/dex.go index c073d6592..7c2ee147a 100644 --- a/go/understack/cmd/dex/dex.go +++ b/go/understackctl/cmd/dex/dex.go @@ -4,7 +4,7 @@ import ( "fmt" "path/filepath" - "github.com/rackerlabs/understack/go/understack/helpers" + "github.com/rackerlabs/understack/go/understackctl/helpers" "github.com/charmbracelet/log" "github.com/gookit/goutil/envutil" diff --git a/go/understack/cmd/helmConfig/helmConfig.go b/go/understackctl/cmd/helmConfig/helmConfig.go similarity index 98% rename from go/understack/cmd/helmConfig/helmConfig.go rename to go/understackctl/cmd/helmConfig/helmConfig.go index 523b1c75c..a3bff5db5 100644 --- a/go/understack/cmd/helmConfig/helmConfig.go +++ b/go/understackctl/cmd/helmConfig/helmConfig.go @@ -5,7 +5,7 @@ import ( "os" "path/filepath" - "github.com/rackerlabs/understack/go/understack/helpers" + "github.com/rackerlabs/understack/go/understackctl/helpers" "github.com/gookit/goutil/envutil" "github.com/gookit/goutil/fsutil" diff --git a/go/understack/cmd/node/node.go b/go/understackctl/cmd/node/node.go similarity index 95% rename from go/understack/cmd/node/node.go rename to go/understackctl/cmd/node/node.go index ddb0f606b..b50e8d7b4 100644 --- a/go/understack/cmd/node/node.go +++ b/go/understackctl/cmd/node/node.go @@ -4,7 +4,7 @@ import ( "context" "os" - "github.com/rackerlabs/understack/go/understack/helpers" + "github.com/rackerlabs/understack/go/understackctl/helpers" "github.com/charmbracelet/log" diff --git a/go/understack/cmd/openstack/secrets.go b/go/understackctl/cmd/openstack/secrets.go similarity index 94% rename from go/understack/cmd/openstack/secrets.go rename to go/understackctl/cmd/openstack/secrets.go index 27c81d30d..6e1cc6c02 100644 --- a/go/understack/cmd/openstack/secrets.go +++ b/go/understackctl/cmd/openstack/secrets.go @@ -1,7 +1,7 @@ package openstack import ( - "github.com/rackerlabs/understack/go/understack/helpers" + "github.com/rackerlabs/understack/go/understackctl/helpers" "github.com/charmbracelet/log" diff --git a/go/understack/cmd/other/openstack.go b/go/understackctl/cmd/other/openstack.go similarity index 100% rename from go/understack/cmd/other/openstack.go rename to go/understackctl/cmd/other/openstack.go diff --git a/go/understack/cmd/other/other.go b/go/understackctl/cmd/other/other.go similarity index 98% rename from go/understack/cmd/other/other.go rename to go/understackctl/cmd/other/other.go index 35165196c..0663b6a03 100644 --- a/go/understack/cmd/other/other.go +++ b/go/understackctl/cmd/other/other.go @@ -4,7 +4,7 @@ import ( "os" "path/filepath" - "github.com/rackerlabs/understack/go/understack/helpers" + "github.com/rackerlabs/understack/go/understackctl/helpers" "github.com/charmbracelet/log" "github.com/gookit/goutil/envutil" diff --git a/go/understack/cmd/quickstart/quickstart.go b/go/understackctl/cmd/quickstart/quickstart.go similarity index 78% rename from go/understack/cmd/quickstart/quickstart.go rename to go/understackctl/cmd/quickstart/quickstart.go index 842303597..344603778 100644 --- a/go/understack/cmd/quickstart/quickstart.go +++ b/go/understackctl/cmd/quickstart/quickstart.go @@ -7,13 +7,13 @@ import ( "github.com/charmbracelet/log" "github.com/gookit/goutil/envutil" - "github.com/rackerlabs/understack/go/understack/cmd/argocd" - "github.com/rackerlabs/understack/go/understack/cmd/certManager" - "github.com/rackerlabs/understack/go/understack/cmd/dex" - "github.com/rackerlabs/understack/go/understack/cmd/helmConfig" - "github.com/rackerlabs/understack/go/understack/cmd/node" - "github.com/rackerlabs/understack/go/understack/cmd/openstack" - "github.com/rackerlabs/understack/go/understack/cmd/other" + "github.com/rackerlabs/understack/go/understackctl/cmd/argocd" + "github.com/rackerlabs/understack/go/understackctl/cmd/certManager" + "github.com/rackerlabs/understack/go/understackctl/cmd/dex" + "github.com/rackerlabs/understack/go/understackctl/cmd/helmConfig" + "github.com/rackerlabs/understack/go/understackctl/cmd/node" + "github.com/rackerlabs/understack/go/understackctl/cmd/openstack" + "github.com/rackerlabs/understack/go/understackctl/cmd/other" "github.com/spf13/cobra" ) diff --git a/go/understack/cmd/root/root.go b/go/understackctl/cmd/root/root.go similarity index 56% rename from go/understack/cmd/root/root.go rename to go/understackctl/cmd/root/root.go index b0bd1d889..797878554 100644 --- a/go/understack/cmd/root/root.go +++ b/go/understackctl/cmd/root/root.go @@ -3,20 +3,20 @@ package root import ( "fmt" - "github.com/rackerlabs/understack/go/understack/cmd/argocd" - "github.com/rackerlabs/understack/go/understack/cmd/certManager" - "github.com/rackerlabs/understack/go/understack/cmd/deploy" - "github.com/rackerlabs/understack/go/understack/cmd/dex" - "github.com/rackerlabs/understack/go/understack/cmd/helmConfig" - "github.com/rackerlabs/understack/go/understack/cmd/node" - "github.com/rackerlabs/understack/go/understack/cmd/openstack" - "github.com/rackerlabs/understack/go/understack/cmd/other" - "github.com/rackerlabs/understack/go/understack/cmd/quickstart" + "github.com/rackerlabs/understack/go/understackctl/cmd/argocd" + "github.com/rackerlabs/understack/go/understackctl/cmd/certManager" + "github.com/rackerlabs/understack/go/understackctl/cmd/deploy" + "github.com/rackerlabs/understack/go/understackctl/cmd/dex" + "github.com/rackerlabs/understack/go/understackctl/cmd/helmConfig" + "github.com/rackerlabs/understack/go/understackctl/cmd/node" + "github.com/rackerlabs/understack/go/understackctl/cmd/openstack" + "github.com/rackerlabs/understack/go/understackctl/cmd/other" + "github.com/rackerlabs/understack/go/understackctl/cmd/quickstart" "github.com/spf13/cobra" ) var rootCmd = &cobra.Command{ - Use: "understack SUBCOMMAND ...", + Use: "understackctl SUBCOMMAND ...", Short: "UnderStack CLI", Long: ``, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/go/understack/go.mod b/go/understackctl/go.mod similarity index 98% rename from go/understack/go.mod rename to go/understackctl/go.mod index 6a3cf5084..a12f1678b 100644 --- a/go/understack/go.mod +++ b/go/understackctl/go.mod @@ -1,4 +1,4 @@ -module github.com/rackerlabs/understack/go/understack +module github.com/rackerlabs/understack/go/understackctl go 1.23.6 diff --git a/go/understack/go.sum b/go/understackctl/go.sum similarity index 100% rename from go/understack/go.sum rename to go/understackctl/go.sum diff --git a/go/understack/helpers/helpers.go b/go/understackctl/helpers/helpers.go similarity index 100% rename from go/understack/helpers/helpers.go rename to go/understackctl/helpers/helpers.go diff --git a/go/understack/helpers/kube.go b/go/understackctl/helpers/kube.go similarity index 100% rename from go/understack/helpers/kube.go rename to go/understackctl/helpers/kube.go diff --git a/go/understack/helpers/kubeseal.go b/go/understackctl/helpers/kubeseal.go similarity index 100% rename from go/understack/helpers/kubeseal.go rename to go/understackctl/helpers/kubeseal.go diff --git a/go/understack/helpers/kustomization.go b/go/understackctl/helpers/kustomization.go similarity index 100% rename from go/understack/helpers/kustomization.go rename to go/understackctl/helpers/kustomization.go diff --git a/go/understack/helpers/random.go b/go/understackctl/helpers/random.go similarity index 100% rename from go/understack/helpers/random.go rename to go/understackctl/helpers/random.go diff --git a/go/understack/helpers/template.go b/go/understackctl/helpers/template.go similarity index 100% rename from go/understack/helpers/template.go rename to go/understackctl/helpers/template.go diff --git a/go/understack/main.go b/go/understackctl/main.go similarity index 62% rename from go/understack/main.go rename to go/understackctl/main.go index 09b46d8d3..1cc9f23eb 100644 --- a/go/understack/main.go +++ b/go/understackctl/main.go @@ -3,7 +3,7 @@ package main import ( "os" - "github.com/rackerlabs/understack/go/understack/cmd/root" + "github.com/rackerlabs/understack/go/understackctl/cmd/root" ) func main() { From 6c1465180f05fe77722efd187918c5e8be20ca44 Mon Sep 17 00:00:00 2001 From: Abhimanyu Sharma Date: Tue, 6 May 2025 23:06:18 +0530 Subject: [PATCH 7/7] fix: lint fix add new line --- go/understackctl/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/understackctl/README.md b/go/understackctl/README.md index 5550d18aa..18a0a8b36 100644 --- a/go/understackctl/README.md +++ b/go/understackctl/README.md @@ -30,4 +30,4 @@ go run *.go help ## Contributing -If you find any issues or have suggestions for improvements, please open an issue on the [GitHub repository](https://github.com/rackerlabs/understack). \ No newline at end of file +If you find any issues or have suggestions for improvements, please open an issue on the [GitHub repository](https://github.com/rackerlabs/understack).