Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions go/understack/.goreleaser.yaml

This file was deleted.

101 changes: 0 additions & 101 deletions go/understack/cmd/root.go

This file was deleted.

22 changes: 0 additions & 22 deletions go/understack/main.go

This file was deleted.

File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion go/understack/README.md → go/understackctl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export UC_AIO=yes
* Run

```
go run *.go init
go run *.go quickstart
go run *.go help
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down
96 changes: 96 additions & 0 deletions go/understackctl/cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,21 @@ 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"

"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) {
Expand Down
Loading
Loading