Skip to content

Commit

Permalink
chore: begin full bubbletea rip-out
Browse files Browse the repository at this point in the history
Signed-off-by: nathan-nicholson <[email protected]>
  • Loading branch information
nathan-nicholson committed Jan 30, 2025
1 parent 32badfa commit 834b55c
Show file tree
Hide file tree
Showing 30 changed files with 861 additions and 315 deletions.
38 changes: 24 additions & 14 deletions cmd/akamai/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (

"github.com/konstructio/kubefirst-api/pkg/constants"
"github.com/konstructio/kubefirst/internal/catalog"
"github.com/konstructio/kubefirst/internal/cluster"
"github.com/konstructio/kubefirst/internal/common"
"github.com/konstructio/kubefirst/internal/progress"
"github.com/konstructio/kubefirst/internal/provision"
"github.com/konstructio/kubefirst/internal/step"
"github.com/konstructio/kubefirst/internal/utilities"
"github.com/spf13/cobra"
)
Expand All @@ -34,10 +35,6 @@ func NewCommand() *cobra.Command {
Run: func(_ *cobra.Command, _ []string) {
fmt.Println("To learn more about akamai in kubefirst, run:")
fmt.Println(" kubefirst akamai --help")

if progress.Progress != nil {
progress.Progress.Quit()
}
},
}

Expand All @@ -54,26 +51,39 @@ func Create() *cobra.Command {
TraverseChildren: true,
RunE: func(cmd *cobra.Command, _ []string) error {
ctx := cmd.Context()
cliFlags, err := utilities.GetFlags(cmd, "akamai")
cloudProvider := "akamai"
stepper := step.NewStepFactory(cmd.ErrOrStderr())

stepper.DisplayLogHints(cloudProvider, 25)

stepper.NewProgressStep("Validate Configuration")

cliFlags, err := utilities.GetFlags(cmd, cloudProvider)
if err != nil {
progress.Error(err.Error())
return fmt.Errorf("failed to get flags: %w", err)
wrerr := fmt.Errorf("error during flag retrieval: %w", err)
stepper.FailCurrentStep(wrerr)
return wrerr
}

progress.DisplayLogHints(25)

isValid, catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
if !isValid {
return fmt.Errorf("catalog validation failed: %w", err)
wrerr := fmt.Errorf("catalog validation failed: %w", err)
stepper.FailCurrentStep(wrerr)
return wrerr
}

err = ValidateProvidedFlags(cliFlags.GitProvider, cliFlags.DNSProvider)
if err != nil {
progress.Error(err.Error())
return fmt.Errorf("failed to validate flags: %w", err)
wrerr := fmt.Errorf("error during flag validation: %w", err)
stepper.FailCurrentStep(wrerr)
return wrerr
}

provision := provision.Provisioner{}
stepper.CompleteCurrentStep()

clusterClient := cluster.ClusterClient{}

provision := provision.NewProvisioner(provision.NewProvisionWatcher(cliFlags.ClusterName, &clusterClient), stepper)

if err := provision.ProvisionManagementCluster(ctx, &cliFlags, catalogApps); err != nil {
return fmt.Errorf("failed to create cluster: %w", err)
Expand Down
45 changes: 32 additions & 13 deletions cmd/aws/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import (
"github.com/aws/aws-sdk-go-v2/config"
"github.com/konstructio/kubefirst-api/pkg/constants"
"github.com/konstructio/kubefirst/internal/catalog"
"github.com/konstructio/kubefirst/internal/cluster"
"github.com/konstructio/kubefirst/internal/common"
"github.com/konstructio/kubefirst/internal/progress"
"github.com/konstructio/kubefirst/internal/provision"
"github.com/konstructio/kubefirst/internal/step"
"github.com/konstructio/kubefirst/internal/utilities"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -85,45 +87,62 @@ func Create() *cobra.Command {
Short: "create the kubefirst platform running in aws",
TraverseChildren: true,
RunE: func(cmd *cobra.Command, _ []string) error {
cloudProvider := "aws"
estimatedDurationMin := 40
ctx := cmd.Context()
cliFlags, err := utilities.GetFlags(cmd, "aws")
stepper := step.NewStepFactory(cmd.ErrOrStderr())

stepper.DisplayLogHints(cloudProvider, estimatedDurationMin)

stepper.NewProgressStep("Validate Configuration")

cliFlags, err := utilities.GetFlags(cmd, cloudProvider)
if err != nil {
progress.Error(err.Error())
return fmt.Errorf("failed to get flags: %w", err)
wrerr := fmt.Errorf("failed to get flags: %w", err)
stepper.FailCurrentStep(wrerr)
return wrerr
}

progress.DisplayLogHints(40)

isValid, catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
if !isValid {
return fmt.Errorf("invalid catalog apps: %w", err)
wrerr := fmt.Errorf("invalid catalog apps: %w", err)
stepper.FailCurrentStep(wrerr)
return wrerr
}

cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion(cliFlags.CloudRegion))
if err != nil {
return fmt.Errorf("unable to load AWS SDK config: %w", err)
wrerr := fmt.Errorf("failed to load AWS SDK config: %w", err)
stepper.FailCurrentStep(wrerr)
return wrerr
}

err = ValidateProvidedFlags(ctx, cfg, cliFlags.GitProvider, cliFlags.AMIType, cliFlags.NodeType)
if err != nil {
progress.Error(err.Error())
return fmt.Errorf("failed to validate provided flags: %w", err)
wrerr := fmt.Errorf("failed to validate provided flags: %w", err)
stepper.FailCurrentStep(wrerr)
return wrerr
}

creds, err := getSessionCredentials(ctx, cfg.Credentials)
if err != nil {
progress.Error(err.Error())
return fmt.Errorf("failed to retrieve AWS credentials: %w", err)
wrerr := fmt.Errorf("failed to get session credentials: %w", err)
stepper.FailCurrentStep(wrerr)
return wrerr
}

viper.Set("kubefirst.state-store-creds.access-key-id", creds.AccessKeyID)
viper.Set("kubefirst.state-store-creds.secret-access-key-id", creds.SecretAccessKey)
viper.Set("kubefirst.state-store-creds.token", creds.SessionToken)
if err := viper.WriteConfig(); err != nil {
return fmt.Errorf("failed to write config: %w", err)
wrerr := fmt.Errorf("failed to write config: %w", err)
stepper.FailCurrentStep(wrerr)
return wrerr
}

provision := provision.Provisioner{}
clusterClient := cluster.ClusterClient{}

provision := provision.NewProvisioner(provision.NewProvisionWatcher(cliFlags.ClusterName, &clusterClient), stepper)

if err := provision.ProvisionManagementCluster(ctx, &cliFlags, catalogApps); err != nil {
return fmt.Errorf("failed to provision aws management cluster: %w", err)
Expand Down
1 change: 0 additions & 1 deletion cmd/aws/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func ValidateProvidedFlags(ctx context.Context, cfg aws.Config, gitProvider, ami
paginator := ec2.NewDescribeInstanceTypesPaginator(ec2Client, &ec2.DescribeInstanceTypesInput{})

if err := validateAMIType(ctx, amiType, nodeType, ssmClient, ec2Client, paginator); err != nil {
progress.Error(err.Error())
return fmt.Errorf("failed to validate ami type for node group: %w", err)
}

Expand Down
33 changes: 23 additions & 10 deletions cmd/azure/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import (

"github.com/konstructio/kubefirst-api/pkg/constants"
"github.com/konstructio/kubefirst/internal/catalog"
"github.com/konstructio/kubefirst/internal/cluster"
"github.com/konstructio/kubefirst/internal/common"
"github.com/konstructio/kubefirst/internal/progress"
"github.com/konstructio/kubefirst/internal/provision"
"github.com/konstructio/kubefirst/internal/step"
"github.com/konstructio/kubefirst/internal/utilities"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -58,28 +60,39 @@ func Create() *cobra.Command {
Short: "create the kubefirst platform running on Azure kubernetes",
TraverseChildren: true,
RunE: func(cmd *cobra.Command, _ []string) error {
cloudProvider := "azure"
estimatedDurationMin := 20
ctx := cmd.Context()
cliFlags, err := utilities.GetFlags(cmd, "azure")
stepper := step.NewStepFactory(cmd.ErrOrStderr())

stepper.DisplayLogHints(cloudProvider, estimatedDurationMin)

stepper.NewProgressStep("Validate Configuration")
cliFlags, err := utilities.GetFlags(cmd, cloudProvider)
if err != nil {
progress.Error(err.Error())
return fmt.Errorf("failed to get flags: %w", err)
wrerr := fmt.Errorf("failed to get flags: %w", err)
stepper.FailCurrentStep(wrerr)
return wrerr
}

progress.DisplayLogHints(20)

isValid, catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
if !isValid {
progress.Error(err.Error())
return nil
wrerr := fmt.Errorf("invalid catalog apps: %w", err)
stepper.FailCurrentStep(wrerr)
return wrerr
}

err = ValidateProvidedFlags(cliFlags.GitProvider)
if err != nil {
progress.Error(err.Error())
return nil
wrerr := fmt.Errorf("failed to validate provided flags: %w", err)
stepper.FailCurrentStep(wrerr)
return wrerr
}

provision := provision.Provisioner{}
stepper.CompleteCurrentStep()

clusterClient := cluster.ClusterClient{}
provision := provision.NewProvisioner(provision.NewProvisionWatcher(cliFlags.ClusterName, &clusterClient), stepper)

if err := provision.ProvisionManagementCluster(ctx, &cliFlags, catalogApps); err != nil {
return fmt.Errorf("failed to create Azure management cluster: %w", err)
Expand Down
19 changes: 13 additions & 6 deletions cmd/civo/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (

"github.com/konstructio/kubefirst-api/pkg/constants"
"github.com/konstructio/kubefirst/internal/catalog"
"github.com/konstructio/kubefirst/internal/cluster"
"github.com/konstructio/kubefirst/internal/common"
"github.com/konstructio/kubefirst/internal/progress"
"github.com/konstructio/kubefirst/internal/provision"
"github.com/konstructio/kubefirst/internal/step"
"github.com/konstructio/kubefirst/internal/utilities"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -65,28 +67,33 @@ func Create() *cobra.Command {
TraverseChildren: true,
RunE: func(cmd *cobra.Command, _ []string) error {
ctx := cmd.Context()
stepper := step.NewStepFactory(cmd.ErrOrStderr())

cliFlags, err := utilities.GetFlags(cmd, "civo")
if err != nil {
progress.Error(err.Error())
return fmt.Errorf("failed to get CLI flags: %w", err)
}

progress.DisplayLogHints(15)

isValid, catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
if !isValid {
return fmt.Errorf("catalog apps validation failed: %w", err)
}

err = ValidateProvidedFlags(cliFlags.GitProvider, cliFlags.DNSProvider)
if err != nil {
progress.Error(err.Error())
return fmt.Errorf("failed to validate provided flags: %w", err)
}

provision := provision.Provisioner{}
stepper.DisplayLogHints(cliFlags.CloudProvider, 15)

clusterClient := cluster.ClusterClient{}

provisioner := provision.NewProvisioner(
provision.NewProvisionWatcher(cliFlags.ClusterName, &clusterClient),
stepper,
)

if err := provision.ProvisionManagementCluster(ctx, &cliFlags, catalogApps); err != nil {
if err := provisioner.ProvisionManagementCluster(ctx, &cliFlags, catalogApps); err != nil {
return fmt.Errorf("failed to create Civo management cluster: %w", err)
}

Expand Down
1 change: 0 additions & 1 deletion cmd/civo/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
)

func ValidateProvidedFlags(gitProvider, dnsProvider string) error {
progress.AddStep("Validate provided flags")

if os.Getenv("CIVO_TOKEN") == "" {
return fmt.Errorf("your CIVO_TOKEN is not set - please set and re-run your last command")
Expand Down
38 changes: 24 additions & 14 deletions cmd/digitalocean/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ See the LICENSE file for more details.
package digitalocean

import (
"errors"
"fmt"

"github.com/konstructio/kubefirst-api/pkg/constants"
"github.com/konstructio/kubefirst/internal/catalog"
"github.com/konstructio/kubefirst/internal/cluster"
"github.com/konstructio/kubefirst/internal/common"
"github.com/konstructio/kubefirst/internal/progress"
"github.com/konstructio/kubefirst/internal/provision"
"github.com/konstructio/kubefirst/internal/step"
"github.com/konstructio/kubefirst/internal/utilities"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -57,31 +58,40 @@ func Create() *cobra.Command {
Short: "create the Kubefirst platform running on DigitalOcean Kubernetes",
TraverseChildren: true,
RunE: func(cmd *cobra.Command, _ []string) error {
cloudProvider := "digitalocean"
estimatedTimeMin := 20
stepper := step.NewStepFactory(cmd.ErrOrStderr())
ctx := cmd.Context()
cliFlags, err := utilities.GetFlags(cmd, "digitalocean")
if err != nil {
progress.Error(err.Error())
return fmt.Errorf("failed to get flags: %w", err)
}

progress.DisplayLogHints(20)
stepper.DisplayLogHints(cloudProvider, estimatedTimeMin)

stepper.NewProgressStep("Validate Configuration")

isValid, catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
cliFlags, err := utilities.GetFlags(cmd, "digitalocean")
if err != nil {
return fmt.Errorf("catalog validation error: %w", err)
wrerr := fmt.Errorf("failed to get flags: %w", err)
stepper.FailCurrentStep(wrerr)
return wrerr
}

if !isValid {
return errors.New("catalog did not pass a validation check")
_, catalogApps, err := catalog.ValidateCatalogApps(ctx, cliFlags.InstallCatalogApps)
if err != nil {
wrerr := fmt.Errorf("failed to validate catalog apps: %w", err)
stepper.FailCurrentStep(wrerr)
return wrerr
}

err = ValidateProvidedFlags(cliFlags.GitProvider, cliFlags.DNSProvider)
if err != nil {
progress.Error(err.Error())
return fmt.Errorf("failed to validate provided flags: %w", err)
wrerr := fmt.Errorf("failed to validate provided flags: %w", err)
stepper.FailCurrentStep(wrerr)
return wrerr
}

provision := provision.Provisioner{}
stepper.CompleteCurrentStep()
clusterClient := cluster.ClusterClient{}

provision := provision.NewProvisioner(provision.NewProvisionWatcher(cliFlags.ClusterName, &clusterClient), stepper)

if err := provision.ProvisionManagementCluster(ctx, &cliFlags, catalogApps); err != nil {
return fmt.Errorf("failed to create DigitalOcean management cluster: %w", err)
Expand Down
18 changes: 13 additions & 5 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"path/filepath"

"github.com/konstructio/kubefirst/internal/generate"
"github.com/konstructio/kubefirst/internal/progress"
"github.com/konstructio/kubefirst/internal/step"
"github.com/spf13/cobra"
)

Expand All @@ -36,13 +36,21 @@ func generateApp() *cobra.Command {
Use: "app-scaffold",
Short: "scaffold the gitops application repo",
TraverseChildren: true,
RunE: func(_ *cobra.Command, _ []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
stepper := step.NewStepFactory(cmd.ErrOrStderr())

stepper.NewProgressStep("Create App Scaffold")

if err := generate.AppScaffold(name, environments, outputPath); err != nil {
progress.Error(err.Error())
return fmt.Errorf("error scaffolding app: %w", err)
wrerr := fmt.Errorf("error scaffolding app: %w", err)
stepper.FailCurrentStep(wrerr)
return wrerr
}

progress.Success(fmt.Sprintf("App successfully scaffolded: %s", name))
stepper.CompleteCurrentStep()

stepper.InfoStepString(fmt.Sprintf("App successfully scaffolded: %s", name))

return nil
},
}
Expand Down
Loading

0 comments on commit 834b55c

Please sign in to comment.