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/cmd/root.go b/go/understack/cmd/root.go deleted file mode 100644 index e4d486cf5..000000000 --- a/go/understack/cmd/root.go +++ /dev/null @@ -1,101 +0,0 @@ -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: "", - 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 -} - -// 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) - } -} diff --git a/go/understack/main.go b/go/understack/main.go deleted file mode 100644 index 3a41f4061..000000000 --- a/go/understack/main.go +++ /dev/null @@ -1,22 +0,0 @@ -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/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" -) - -func main() { - err := cmd.Execute() - if err != nil { - os.Exit(1) - } -} 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 102aacb8e..18a0a8b36 100644 --- a/go/understack/README.md +++ b/go/understackctl/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/argocd/secrets.go b/go/understackctl/cmd/argocd/argocd.go similarity index 81% rename from go/understack/cmd/argocd/secrets.go rename to go/understackctl/cmd/argocd/argocd.go index 32ebc8e1f..b72d1bd2f 100644 --- a/go/understack/cmd/argocd/secrets.go +++ b/go/understackctl/cmd/argocd/argocd.go @@ -6,8 +6,7 @@ import ( "os" "path/filepath" - "github.com/rackerlabs/understack/go/understack/cmd" - "github.com/rackerlabs/understack/go/understack/helpers" + "github.com/rackerlabs/understack/go/understackctl/helpers" "github.com/charmbracelet/log" "github.com/gookit/goutil/envutil" @@ -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.RootCmd.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/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/secrets.go b/go/understackctl/cmd/certManager/certManger.go similarity index 78% rename from go/understack/cmd/certManager/secrets.go rename to go/understackctl/cmd/certManager/certManger.go index 18e545e9f..6c6f9af80 100644 --- a/go/understack/cmd/certManager/secrets.go +++ b/go/understackctl/cmd/certManager/certManger.go @@ -5,8 +5,7 @@ import ( "fmt" "os" - "github.com/rackerlabs/understack/go/understack/cmd" - "github.com/rackerlabs/understack/go/understack/helpers" + "github.com/rackerlabs/understack/go/understackctl/helpers" "github.com/charmbracelet/log" "github.com/gookit/goutil/envutil" @@ -18,15 +17,13 @@ import ( //go:embed templates/clusterIssuer.tmpl var clusterIssuerTemplate string -func init() { - cmd.RootCmd.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/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/understackctl/cmd/deploy/deploy.go b/go/understackctl/cmd/deploy/deploy.go new file mode 100644 index 000000000..d53dc7e10 --- /dev/null +++ b/go/understackctl/cmd/deploy/deploy.go @@ -0,0 +1,96 @@ +package deploy + +import ( + "fmt" + "os" + "path/filepath" + "strings" + + "github.com/charmbracelet/log" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +const ( + deployRepoEnvVar = "UC_DEPLOY" + 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", + RunE: func(cmd *cobra.Command, args []string) error { + // Show help if no subcommands are provided + return cmd.Help() + }, + PersistentPreRunE: ensureDeployRepo, + } + + addDeployRepoFlag(cmd) + return cmd +} + +// 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) + } +} + +// 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 + } + + expandedPath, err := expandHomePath(repoPath) + if err != nil { + return fmt.Errorf("failed to expand path: %w", err) + } + + info, err := os.Stat(expandedPath) + if err != nil { + return fmt.Errorf("could not access directory '%s': %w", expandedPath, err) + } + if !info.IsDir() { + return fmt.Errorf("path '%s' is not a directory", expandedPath) + } + + if err := os.Chdir(expandedPath); err != nil { + return fmt.Errorf("failed to change working directory to '%s': %w", expandedPath, err) + } + + log.Infof("Using deployment repo: %s", expandedPath) + return nil +} + +// 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 +} diff --git a/go/understack/cmd/dex/secrets.go b/go/understackctl/cmd/dex/dex.go similarity index 75% rename from go/understack/cmd/dex/secrets.go rename to go/understackctl/cmd/dex/dex.go index 1c07666dd..7c2ee147a 100644 --- a/go/understack/cmd/dex/secrets.go +++ b/go/understackctl/cmd/dex/dex.go @@ -4,8 +4,7 @@ import ( "fmt" "path/filepath" - "github.com/rackerlabs/understack/go/understack/cmd" - "github.com/rackerlabs/understack/go/understack/helpers" + "github.com/rackerlabs/understack/go/understackctl/helpers" "github.com/charmbracelet/log" "github.com/gookit/goutil/envutil" @@ -13,15 +12,13 @@ import ( "github.com/spf13/cobra" ) -func init() { - cmd.RootCmd.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/understackctl/cmd/helmConfig/helmConfig.go similarity index 90% rename from go/understack/cmd/helmConfig/helmConfig.go rename to go/understackctl/cmd/helmConfig/helmConfig.go index cbbe913f7..a3bff5db5 100644 --- a/go/understack/cmd/helmConfig/helmConfig.go +++ b/go/understackctl/cmd/helmConfig/helmConfig.go @@ -5,38 +5,34 @@ import ( "os" "path/filepath" - "github.com/rackerlabs/understack/go/understack/cmd" - "github.com/rackerlabs/understack/go/understack/helpers" + "github.com/rackerlabs/understack/go/understackctl/helpers" "github.com/gookit/goutil/envutil" "github.com/gookit/goutil/fsutil" "github.com/spf13/cobra" ) -func init() { - cmd.RootCmd.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/understackctl/cmd/node/node.go similarity index 75% rename from go/understack/cmd/node/node.go rename to go/understackctl/cmd/node/node.go index 83d3183d8..b50e8d7b4 100644 --- a/go/understack/cmd/node/node.go +++ b/go/understackctl/cmd/node/node.go @@ -4,8 +4,7 @@ import ( "context" "os" - "github.com/rackerlabs/understack/go/understack/cmd" - "github.com/rackerlabs/understack/go/understack/helpers" + "github.com/rackerlabs/understack/go/understackctl/helpers" "github.com/charmbracelet/log" @@ -13,15 +12,13 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func init() { - cmd.RootCmd.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/understackctl/cmd/openstack/secrets.go similarity index 73% rename from go/understack/cmd/openstack/secrets.go rename to go/understackctl/cmd/openstack/secrets.go index 4f907c144..6e1cc6c02 100644 --- a/go/understack/cmd/openstack/secrets.go +++ b/go/understackctl/cmd/openstack/secrets.go @@ -1,23 +1,20 @@ package openstack import ( - "github.com/rackerlabs/understack/go/understack/cmd" - "github.com/rackerlabs/understack/go/understack/helpers" + "github.com/rackerlabs/understack/go/understackctl/helpers" "github.com/charmbracelet/log" "github.com/spf13/cobra" ) -func init() { - cmd.RootCmd.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/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 85% rename from go/understack/cmd/other/other.go rename to go/understackctl/cmd/other/other.go index 930c53842..0663b6a03 100644 --- a/go/understack/cmd/other/other.go +++ b/go/understackctl/cmd/other/other.go @@ -4,8 +4,7 @@ import ( "os" "path/filepath" - "github.com/rackerlabs/understack/go/understack/cmd" - "github.com/rackerlabs/understack/go/understack/helpers" + "github.com/rackerlabs/understack/go/understackctl/helpers" "github.com/charmbracelet/log" "github.com/gookit/goutil/envutil" @@ -19,17 +18,15 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func init() { - cmd.RootCmd.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/init/init.go b/go/understackctl/cmd/quickstart/quickstart.go similarity index 52% rename from go/understack/cmd/init/init.go rename to go/understackctl/cmd/quickstart/quickstart.go index 66ea948af..344603778 100644 --- a/go/understack/cmd/init/init.go +++ b/go/understackctl/cmd/quickstart/quickstart.go @@ -1,36 +1,32 @@ -package ironic +package quickstart import ( "fmt" "os" "os/exec" - "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/charmbracelet/log" "github.com/gookit/goutil/envutil" + "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" ) -func init() { - cmd.RootCmd.AddCommand(Init) -} - -var Init = &cobra.Command{ - Use: "init", - Short: "Run all the init the steps required", - Long: "Run all the init the steps required", - Run: initRun, +func NewCmdQuickStart() *cobra.Command { + return &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"), @@ -60,23 +56,23 @@ func initRun(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/understackctl/cmd/root/root.go b/go/understackctl/cmd/root/root.go new file mode 100644 index 000000000..797878554 --- /dev/null +++ b/go/understackctl/cmd/root/root.go @@ -0,0 +1,43 @@ +package root + +import ( + "fmt" + + "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: "understackctl 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(deploy.NewCmdDeploy()) + 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/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/understackctl/main.go b/go/understackctl/main.go new file mode 100644 index 000000000..1cc9f23eb --- /dev/null +++ b/go/understackctl/main.go @@ -0,0 +1,14 @@ +package main + +import ( + "os" + + "github.com/rackerlabs/understack/go/understackctl/cmd/root" +) + +func main() { + err := root.Execute() + if err != nil { + os.Exit(1) + } +}