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

feat: disable bubbletea #2321

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions cmd/akamai/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func RootCredentials() *cobra.Command {
authCmd.Flags().BoolVar(&copyArgoCDPasswordToClipboardFlag, "argocd", false, "copy the ArgoCD password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyKbotPasswordToClipboardFlag, "kbot", false, "copy the kbot password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyVaultPasswordToClipboardFlag, "vault", false, "copy the vault password to the clipboard (optional)")
authCmd.Flags().BoolVar(&ciFlag, "ci", false, "if running kubefirst in ci, set this flag to disable interactive features")

return authCmd
}
10 changes: 6 additions & 4 deletions cmd/akamai/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ func createAkamai(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("catalog validation failed: %w", err)
}

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

utilities.CreateK1ClusterDirectory(clusterNameFlag)
Expand Down
2 changes: 2 additions & 0 deletions cmd/aws/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,7 @@ func RootCredentials() *cobra.Command {
RunE: common.GetRootCredentials,
}

authCmd.Flags().BoolVar(&ciFlag, "ci", false, "if running kubefirst in ci, set this flag to disable interactive features")

return authCmd
}
10 changes: 6 additions & 4 deletions cmd/aws/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ func createAws(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("invalid catalog apps: %w", err)
}

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

utilities.CreateK1ClusterDirectory(cliFlags.ClusterName)
Expand Down
1 change: 1 addition & 0 deletions cmd/azure/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func RootCredentials() *cobra.Command {
authCmd.Flags().BoolVar(&copyArgoCDPasswordToClipboardFlag, "argocd", false, "copy the argocd password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyKbotPasswordToClipboardFlag, "kbot", false, "copy the kbot password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyVaultPasswordToClipboardFlag, "vault", false, "copy the vault password to the clipboard (optional)")
authCmd.Flags().BoolVar(&ciFlag, "ci", false, "if running kubefirst in ci, set this flag to disable interactive features")

return authCmd
}
15 changes: 9 additions & 6 deletions cmd/azure/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ func createAzure(cmd *cobra.Command, _ []string) error {
return nil
}

err = ValidateProvidedFlags(cliFlags.GitProvider, cliFlags.DNSProvider, cliFlags.DNSAzureRG)
if err != nil {
progress.Error(err.Error())
return nil
if progress.CanRunBubbleTea {
err = ValidateProvidedFlags(cliFlags.GitProvider, cliFlags.DNSProvider, cliFlags.DNSAzureRG)
if err != nil {
progress.Error(err.Error())
return nil
}
}

// If cluster setup is complete, return
Expand Down Expand Up @@ -113,8 +115,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
1 change: 1 addition & 0 deletions cmd/civo/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func RootCredentials() *cobra.Command {
authCmd.Flags().BoolVar(&copyArgoCDPasswordToClipboardFlag, "argocd", false, "Copy the ArgoCD password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyKbotPasswordToClipboardFlag, "kbot", false, "Copy the Kbot password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyVaultPasswordToClipboardFlag, "vault", false, "Copy the Vault password to the clipboard (optional)")
authCmd.Flags().BoolVar(&ciFlag, "ci", false, "if running kubefirst in ci, set this flag to disable interactive features")

return authCmd
}
10 changes: 6 additions & 4 deletions cmd/civo/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ func createCivo(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("catalog apps validation failed: %w", err)
}

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

// If cluster setup is complete, return
Expand Down
1 change: 1 addition & 0 deletions cmd/digitalocean/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func RootCredentials() *cobra.Command {
authCmd.Flags().BoolVar(&copyArgoCDPasswordToClipboardFlag, "argocd", false, "copy the ArgoCD password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyKbotPasswordToClipboardFlag, "kbot", false, "copy the kbot password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyVaultPasswordToClipboardFlag, "vault", false, "copy the vault password to the clipboard (optional)")
authCmd.Flags().BoolVar(&ciFlag, "ci", false, "if running kubefirst in ci, set this flag to disable interactive features")

return authCmd
}
10 changes: 6 additions & 4 deletions cmd/digitalocean/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ func createDigitalocean(cmd *cobra.Command, _ []string) error {
return errors.New("catalog did not pass a validation check")
}

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

// If cluster setup is complete, return
Expand Down
1 change: 1 addition & 0 deletions cmd/google/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func RootCredentials() *cobra.Command {
authCmd.Flags().BoolVar(&copyArgoCDPasswordToClipboardFlag, "argocd", false, "copy the ArgoCD password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyKbotPasswordToClipboardFlag, "kbot", false, "copy the kbot password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyVaultPasswordToClipboardFlag, "vault", false, "copy the vault password to the clipboard (optional)")
authCmd.Flags().BoolVar(&ciFlag, "ci", false, "if running kubefirst in ci, set this flag to disable interactive features")

return authCmd
}
10 changes: 6 additions & 4 deletions cmd/google/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ func createGoogle(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("catalog apps validation failed: %w", err)
}

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

clusterSetupComplete := viper.GetBool("kubefirst-checks.cluster-install-complete")
Expand Down
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
}
1 change: 1 addition & 0 deletions cmd/vultr/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func RootCredentials() *cobra.Command {
authCmd.Flags().BoolVar(&copyArgoCDPasswordToClipboardFlag, "argocd", false, "Copy the ArgoCD password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyKbotPasswordToClipboardFlag, "kbot", false, "Copy the kbot password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyVaultPasswordToClipboardFlag, "vault", false, "Copy the vault password to the clipboard (optional)")
authCmd.Flags().BoolVar(&ciFlag, "ci", false, "if running kubefirst in ci, set this flag to disable interactive features")

return authCmd
}
11 changes: 7 additions & 4 deletions cmd/vultr/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ func createVultr(cmd *cobra.Command, _ []string) error {
return errors.New("catalog validation failed")
}

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

clusterSetupComplete := viper.GetBool("kubefirst-checks.cluster-install-complete")
Expand Down Expand Up @@ -139,5 +141,6 @@ func ValidateProvidedFlags(gitProvider string) error {
}

progress.CompleteStep("Validate provided flags")

return nil
}
39 changes: 39 additions & 0 deletions internal/progress/ci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package progress

import (
"fmt"
"time"

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

func WatchClusterForCi(clusterName string) {
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" {
fmt.Printf("unable to provision cluster: %s", provisioningCluster.LastCondition)
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok this is a bit of a nasty cheat that more than one might have a hard time using in the future 😆

You're waiting here because nobody has sent data to it. But you also have the read inside the goroutine inside the case statement! Which one wins when done <- true happens inside the ticker.C?

The short answer is the asynchronous one, at the top level that simply returns. The second one, the one inside the for select will need an extra CPU cycle to leave the statement of the ticker.C then go back to the parent one, to finally read the "return" you have there, but at that point, the function is long gone.

May I propose you to use an errgroup or the tool we've been using so far for waiting for events from happening instead of generating yet another function "that waits for a condition"?

The other part this doesn't cover is that there is no timeout. This function will run forever if none of the conditions break the loop.

}
49 changes: 45 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,21 @@ 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) {
if !CanRunBubbleTea {
fmt.Println(message)
return
}

Progress.Send(completeStep{
message: message,
})
Expand All @@ -186,6 +212,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 +225,23 @@ func Success(success string) {

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

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

Progress.Send(renderedMessage)
}

func StartProvisioning(clusterName string) {
provisioningMessage := startProvision{
clusterName: clusterName,
}
if !CanRunBubbleTea {
WatchClusterForCi(clusterName)
} else {
provisioningMessage := startProvision{
clusterName: clusterName,
}

Progress.Send(provisioningMessage)
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a debugging statement, might want to remove it.

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()
}
}
Loading