Skip to content

Commit

Permalink
feat: add ci flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jokestax committed Nov 11, 2024
1 parent 3625641 commit 2727b45
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 26 deletions.
8 changes: 6 additions & 2 deletions cmd/akamai/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ func createAkamai(cmd *cobra.Command, _ []string) error {
}

func ValidateProvidedFlags(gitProvider string) error {
progress.AddStep("Validate provided flags")
if progress.CanRunBubbleTea {
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 @@ -126,7 +128,9 @@ func ValidateProvidedFlags(gitProvider string) error {
log.Info().Msgf("%q %s", "gitlab.com", key.Type())
}

progress.CompleteStep("Validate provided flags")
if progress.CanRunBubbleTea {
progress.CompleteStep("Validate provided flags")
}

return nil
}
9 changes: 6 additions & 3 deletions cmd/aws/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ func createAws(cmd *cobra.Command, _ []string) error {
}

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

if progress.CanRunBubbleTea {
progress.AddStep("Validate provided flags")
}
// Validate required environment variables for dns provider
if dnsProviderFlag == "cloudflare" {
if os.Getenv("CF_API_TOKEN") == "" {
Expand All @@ -161,7 +162,9 @@ func ValidateProvidedFlags(gitProvider string) error {
log.Info().Msgf("%q %s", "gitlab.com", key.Type())
}

progress.CompleteStep("Validate provided flags")
if progress.CanRunBubbleTea {
progress.CompleteStep("Validate provided flags")
}

return nil
}
5 changes: 3 additions & 2 deletions cmd/azure/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ func createAzure(cmd *cobra.Command, _ []string) error {
}

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

if progress.CanRunBubbleTea {
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 Down
8 changes: 6 additions & 2 deletions cmd/civo/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ func createCivo(cmd *cobra.Command, _ []string) error {
}

func ValidateProvidedFlags(gitProvider string) error {
progress.AddStep("Validate provided flags")
if progress.CanRunBubbleTea {
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 Expand Up @@ -130,7 +132,9 @@ func ValidateProvidedFlags(gitProvider string) error {
log.Info().Msgf("gitlab.com %q", key.Type())
}

progress.CompleteStep("Validate provided flags")
if progress.CanRunBubbleTea {
progress.CompleteStep("Validate provided flags")
}

return nil
}
10 changes: 6 additions & 4 deletions cmd/digitalocean/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ func createDigitalocean(cmd *cobra.Command, _ []string) error {
}

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

if progress.CanRunBubbleTea {
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 @@ -141,7 +142,8 @@ func ValidateProvidedFlags(gitProvider string) error {
log.Info().Msgf("%q %s", "gitlab.com", key.Type())
}

progress.CompleteStep("Validate provided flags")

if progress.CanRunBubbleTea {
progress.CompleteStep("Validate provided flags")
}
return nil
}
9 changes: 6 additions & 3 deletions cmd/google/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ func createGoogle(cmd *cobra.Command, _ []string) error {
}

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

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

progress.CompleteStep("Validate provided flags")

if progress.CanRunBubbleTea {
progress.CompleteStep("Validate provided flags")
}
return nil
}
4 changes: 3 additions & 1 deletion cmd/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/spf13/cobra"
)

var ciFlag bool

// additionalHelmFlags can optionally pass user-supplied flags to helm
var additionalHelmFlags []string

Expand Down Expand Up @@ -102,6 +104,6 @@ func launchDeleteCluster() *cobra.Command {
launch.DeleteCluster(args[0])
},
}

launchDeleteClusterCmd.Flags().BoolVar(&ciFlag, "ci", false, "if running kubefirst in ci, set this flag to disable interactive features")
return launchDeleteClusterCmd
}
8 changes: 6 additions & 2 deletions cmd/vultr/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ func createVultr(cmd *cobra.Command, _ []string) error {
}

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

if os.Getenv("VULTR_API_KEY") == "" {
return fmt.Errorf("your VULTR_API_KEY variable is unset - please set it before continuing")
Expand All @@ -138,6 +140,8 @@ func ValidateProvidedFlags(gitProvider string) error {
log.Info().Msgf("%q %s", "gitlab.com", key.Type())
}

progress.CompleteStep("Validate provided flags")
if progress.CanRunBubbleTea {
progress.CompleteStep("Validate provided flags")
}
return nil
}
41 changes: 41 additions & 0 deletions internal/progress/ci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package progress

import (
"fmt"
"log"
"time"

"github.com/konstructio/kubefirst/internal/cluster"
)

func WatchClusterForCi(clusterName string) {

Check failure on line 11 in internal/progress/ci.go

View workflow job for this annotation

GitHub Actions / build

unnecessary leading newline (whitespace)

ticker := time.NewTicker(10 * time.Second)
defer ticker.Stop()

done := make(chan bool)

go func() {
for {
select {
case <-done:
return
case <-ticker.C:
provisioningCluster, _ := cluster.GetCluster(clusterName)

if provisioningCluster.Status == "error" {
log.Fatalf("unable to provision cluster: %s", provisioningCluster.LastCondition)

Check failure on line 27 in internal/progress/ci.go

View workflow job for this annotation

GitHub Actions / build

unreachable-code: unreachable code after this statement (revive)
done <- true
}

if provisioningCluster.Status == "provisioned" {
fmt.Println("\n cluster has been provisioned via ci")
fmt.Printf("\n kubefirst URL: https://kubefirst.%s \n", provisioningCluster.DomainName)
done <- true
}
}
}
}()

<-done
}
51 changes: 47 additions & 4 deletions internal/progress/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ func DisplayLogHints(estimatedTime int) {

headerMessage := renderMessage(header)

if !CanRunBubbleTea {
fmt.Println(headerMessage)
return
}

Progress.Send(headerMsg{
message: headerMessage,
})
Expand Down Expand Up @@ -141,6 +146,11 @@ func DisplaySuccessMessage(cluster types.Cluster) successMsg {

successMessage := renderMessage(success)

if !CanRunBubbleTea {
fmt.Println(successMessage)
return successMsg{}
}

return successMsg{
message: successMessage,
}
Expand All @@ -165,6 +175,11 @@ func DisplayCredentials(cluster types.Cluster) {

headerMessage := renderMessage(header)

if !CanRunBubbleTea {
fmt.Println(headerMessage)
return
}

Progress.Send(headerMsg{
message: headerMessage,
})
Expand All @@ -174,10 +189,22 @@ func DisplayCredentials(cluster types.Cluster) {

func AddStep(message string) {
renderedMessage := createStep(fmt.Sprintf("%s %s", ":dizzy:", message))

if !CanRunBubbleTea {
fmt.Println(renderedMessage)
return
}

Progress.Send(renderedMessage)
}

func CompleteStep(message string) {

Check failure on line 201 in internal/progress/message.go

View workflow job for this annotation

GitHub Actions / build

unnecessary leading newline (whitespace)

if !CanRunBubbleTea {
fmt.Println(message)
return
}

Progress.Send(completeStep{
message: message,
})
Expand All @@ -186,6 +213,11 @@ func CompleteStep(message string) {
func Success(success string) {
successMessage := renderMessage(success)

if !CanRunBubbleTea {
fmt.Println(successMessage)
return
}

Progress.Send(
successMsg{
message: successMessage,
Expand All @@ -194,13 +226,24 @@ func Success(success string) {

func Error(message string) {
renderedMessage := createErrorLog(message)

if !CanRunBubbleTea {
fmt.Println(renderedMessage)
return
}

Progress.Send(renderedMessage)
}

func StartProvisioning(clusterName string) {

Check failure on line 238 in internal/progress/message.go

View workflow job for this annotation

GitHub Actions / build

unnecessary leading newline (whitespace)
provisioningMessage := startProvision{
clusterName: clusterName,
}

Progress.Send(provisioningMessage)
if !CanRunBubbleTea {
WatchClusterForCi(clusterName)
} else {
provisioningMessage := startProvision{
clusterName: clusterName,
}

Progress.Send(provisioningMessage)
}
}
9 changes: 8 additions & 1 deletion internal/progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import (
"github.com/spf13/viper"
)

var Progress *tea.Program
var (
Progress *tea.Program
CanRunBubbleTea bool
)

//nolint:revive // will be removed after refactoring
func NewModel() progressModel {
Expand All @@ -23,6 +26,10 @@ func NewModel() progressModel {
}
}

func DiableBubbleTeaExecution() {
CanRunBubbleTea = false
}

// Bubbletea functions
func InitializeProgressTerminal() {
Progress = tea.NewProgram(NewModel())
Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (

func main() {
argsWithProg := os.Args

bubbleTeaBlacklist := []string{"completion", "help", "--help", "-h", "quota", "logs"}
fmt.Println(argsWithProg)
bubbleTeaBlacklist := []string{"completion", "help", "--help", "-h", "quota", "logs", "--ci"}
canRunBubbleTea := true

for _, arg := range argsWithProg {
Expand Down Expand Up @@ -143,5 +143,6 @@ func main() {
progress.Progress.Run()
} else {
cmd.Execute()
progress.DiableBubbleTeaExecution()
}
}

0 comments on commit 2727b45

Please sign in to comment.