Skip to content

Commit

Permalink
Bypass email prompt for upgrades if installed
Browse files Browse the repository at this point in the history
Moves prepare call to Run, similar to Destroy
Removes interactive argumment in place of checking itself.
  • Loading branch information
zerbitx committed Dec 13, 2024
1 parent fa41bde commit cf8bb42
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
4 changes: 2 additions & 2 deletions cmd/vclusterctl/cmd/platform/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewDestroyCmd(globalFlags *flags.GlobalFlags) *cobra.Command {
Destroys a vCluster Platform instance in your Kubernetes cluster.
IMPORTANT: This action is done against the cluster the the kube-context is pointing to, and not the vCluster Platform instance that is logged in.
It does not require logging in to vCluster Platform.
It does not require logging in to vCluster Platform.
Please make sure you meet the following requirements
before running this command:
Expand Down Expand Up @@ -72,7 +72,7 @@ VirtualClusterInstances managed with driver helm will be deleted, but the underl

func (cmd *DestroyCmd) Run(ctx context.Context) error {
// initialise clients, verify binaries exist, sanity-check context
err := cmd.Options.Prepare(cmd.NonInteractive)
err := cmd.Options.Prepare()
if err != nil {
return fmt.Errorf("failed to prepare clients: %w", err)
}
Expand Down
27 changes: 22 additions & 5 deletions cmd/vclusterctl/cmd/platform/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package platform
import (
"context"
"fmt"
"k8s.io/client-go/kubernetes"
"strings"
"time"

Expand Down Expand Up @@ -84,10 +85,6 @@ before running this command:
}

func (cmd *StartCmd) Run(ctx context.Context) error {
if err := cmd.ensureEmailWithDisclaimer(); err != nil {
return err
}

// get version to deploy
if cmd.Version == "latest" || cmd.Version == "" {
cmd.Version = platform.MinimumVersionTag
Expand Down Expand Up @@ -150,10 +147,30 @@ func (cmd *StartCmd) Run(ctx context.Context) error {
}
}

if err := cmd.StartOptions.Prepare(); err != nil {
return err
}

if err := cmd.ensureEmailWithDisclaimer(ctx, cmd.KubeClient, cmd.Namespace); err != nil {
return err
}

return start.NewLoftStarter(cmd.StartOptions).Start(ctx)
}

func (cmd *StartCmd) ensureEmailWithDisclaimer() error {
func (cmd *StartCmd) ensureEmailWithDisclaimer(ctx context.Context, kc kubernetes.Interface, namespace string) error {
if cmd.Upgrade {
isInstalled, err := clihelper.IsLoftAlreadyInstalled(ctx, kc, namespace)

if err != nil {
return err
}

if isInstalled {
return nil
}
}

fmt.Printf(`By providing your email, you accept our Terms of Service and Privacy Statement:
Terms of Service: https://www.loft.sh/legal/terms
Privacy Statement: https://www.loft.sh/legal/privacy
Expand Down
11 changes: 4 additions & 7 deletions pkg/cli/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package start
import (
"context"
"fmt"
"github.com/loft-sh/log/terminal"
"os"
"os/exec"

Expand Down Expand Up @@ -93,15 +94,11 @@ func (l *LoftStarter) Start(ctx context.Context) error {
l.LocalPort = "9898"
}

err := l.Prepare(false)
if err != nil {
return err
}
l.Log.WriteString(logrus.InfoLevel, "\n")

// Uninstall already existing Loft instance
if l.Reset {
err = clihelper.UninstallLoft(ctx, l.KubeClient, l.RestConfig, l.Context, l.Namespace, l.Log)
err := clihelper.UninstallLoft(ctx, l.KubeClient, l.RestConfig, l.Context, l.Namespace, l.Log)
if err != nil {
return err
}
Expand Down Expand Up @@ -141,7 +138,7 @@ func (l *LoftStarter) Start(ctx context.Context) error {
}

// Prepare initializes clients, verifies the existense of binaries, and ensures we are starting with the right kube context
func (l *Options) Prepare(cliNonInteractive bool) error {
func (l *Options) Prepare() error {
platformClient := platform.NewClientFromConfig(l.LoadedConfig(l.Log))

platformConfig := platformClient.Config().Platform
Expand All @@ -160,7 +157,7 @@ func (l *Options) Prepare(cliNonInteractive bool) error {
if l.Context != "" {
contextToLoad = l.Context
} else if platformConfig.LastInstallContext != "" && platformConfig.LastInstallContext != contextToLoad {
if !cliNonInteractive {
if terminal.IsTerminalIn {
contextToLoad, err = l.Log.Question(&survey.QuestionOptions{
Question: product.Replace(fmt.Sprintf("Seems like you try to use 'vcluster %s' with a different kubernetes context than before. Please choose which kubernetes context you want to use", l.CommandName)),
DefaultValue: contextToLoad,
Expand Down

0 comments on commit cf8bb42

Please sign in to comment.