Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: begin full bubbletea rip-out KRA-72 #2406

Merged
merged 13 commits into from
Feb 3, 2025
Merged
39 changes: 25 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,40 @@ func Create() *cobra.Command {
TraverseChildren: true,
RunE: func(cmd *cobra.Command, _ []string) error {
ctx := cmd.Context()
cliFlags, err := utilities.GetFlags(cmd, "akamai")
cloudProvider := "akamai"
estimatedTimeMin := 25
stepper := step.NewStepFactory(cmd.ErrOrStderr())

stepper.DisplayLogHints(cloudProvider, estimatedTimeMin)

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.Client{}

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
5 changes: 0 additions & 5 deletions cmd/akamai/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ import (
"os"

internalssh "github.com/konstructio/kubefirst-api/pkg/ssh"
"github.com/konstructio/kubefirst/internal/progress"
"github.com/rs/zerolog/log"
)

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

if os.Getenv("LINODE_TOKEN") == "" {
return fmt.Errorf("your LINODE_TOKEN is not set - please set and re-run your last command")
}
Expand All @@ -43,7 +40,5 @@ func ValidateProvidedFlags(gitProvider, dnsProvider string) error {
log.Info().Msgf("%q %s", "gitlab.com", key.Type())
}

progress.CompleteStep("Validate provided flags")

return nil
}
51 changes: 33 additions & 18 deletions cmd/aws/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ 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 @@ -66,10 +67,6 @@ func NewCommand() *cobra.Command {
Run: func(_ *cobra.Command, _ []string) {
fmt.Println("To learn more about aws in kubefirst, run:")
fmt.Println(" kubefirst help")

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

Expand All @@ -85,47 +82,65 @@ 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.Client{}

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

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

Expand Down
6 changes: 0 additions & 6 deletions cmd/aws/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ import (
ec2Types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/aws/aws-sdk-go-v2/service/ssm"
internalssh "github.com/konstructio/kubefirst-api/pkg/ssh"
"github.com/konstructio/kubefirst/internal/progress"
"github.com/rs/zerolog/log"
)

func ValidateProvidedFlags(ctx context.Context, cfg aws.Config, gitProvider, amiType, nodeType string) error {
progress.AddStep("Validate provided flags")

// Validate required environment variables for dns provider
if dnsProviderFlag == "cloudflare" {
if os.Getenv("CF_API_TOKEN") == "" {
Expand Down Expand Up @@ -51,12 +48,9 @@ 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)
}

progress.CompleteStep("Validate provided flags")

return nil
}

Expand Down
43 changes: 25 additions & 18 deletions cmd/azure/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,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 @@ -36,16 +37,11 @@ func NewCommand() *cobra.Command {
Run: func(_ *cobra.Command, _ []string) {
fmt.Println("To learn more about azure in kubefirst, run:")
fmt.Println(" kubefirst azure --help")

if progress.Progress != nil {
progress.Progress.Quit()
}
},
SilenceErrors: true,
SilenceUsage: true,
}

// on error, doesnt show helper/usage
azureCmd.SilenceUsage = true

// wire up new commands
azureCmd.AddCommand(Create(), Destroy(), RootCredentials())

Expand All @@ -58,28 +54,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.Client{}
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
5 changes: 0 additions & 5 deletions cmd/azure/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"os"

internalssh "github.com/konstructio/kubefirst-api/pkg/ssh"
"github.com/konstructio/kubefirst/internal/progress"
"github.com/rs/zerolog/log"
)

Expand All @@ -27,8 +26,6 @@ var envvarSecrets = []string{
}

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

for _, env := range envvarSecrets {
if os.Getenv(env) == "" {
return fmt.Errorf("your %s is not set - please set and re-run your last command", env)
Expand All @@ -52,7 +49,5 @@ func ValidateProvidedFlags(gitProvider string) error {
}
}

progress.CompleteStep("Validate provided flags")

return nil
}
Loading
Loading