From 0c21032549185d35dbcf2fb65bc21e4cb09e1914 Mon Sep 17 00:00:00 2001 From: Muvaffak Onus Date: Thu, 23 Mar 2023 18:27:09 +0300 Subject: [PATCH] connect: wait for helm installation to complete Signed-off-by: Muvaffak Onus --- cmd/up/controlplane/connect.go | 12 ++++++++---- internal/install/helm/helm.go | 21 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/cmd/up/controlplane/connect.go b/cmd/up/controlplane/connect.go index f7fd615a..89713993 100644 --- a/cmd/up/controlplane/connect.go +++ b/cmd/up/controlplane/connect.go @@ -60,7 +60,9 @@ func (c *connectCmd) AfterApply(kongCtx *kong.Context, upCtx *upbound.Context) e mgr, err := helm.NewManager(kubeconfig, connectorName, mcpRepoURL, - helm.WithNamespace(c.InstallationNamespace)) + helm.WithNamespace(c.InstallationNamespace), + helm.Wait(), + ) if err != nil { return err } @@ -124,6 +126,7 @@ func (c *connectCmd) Run(p pterm.TextPrinter, upCtx *upbound.Context) error { "host": fmt.Sprintf("%s://%s", upCtx.ProxyEndpoint.Scheme, upCtx.ProxyEndpoint.Host), "token": token, } + p.Printfln("Installing %s to kube-system. This may take a few minutes.", connectorName) if err = c.mgr.Install("", params); err != nil { return err } @@ -132,7 +135,8 @@ func (c *connectCmd) Run(p pterm.TextPrinter, upCtx *upbound.Context) error { return err } - p.Printfln("Connected to the control plane %q !", c.Name) + p.Printfln("Connected to the control plane %s.", c.Name) + p.Println("See available APIs with the following command: \n\n$ kubectl api-resources") return nil } @@ -157,7 +161,7 @@ func (c *connectCmd) getToken(p pterm.TextPrinter, upCtx *upbound.Context) (stri if err != nil { return "", errors.Wrap(err, "failed to get account details") } - p.Printfln("Creating an API token for the user %s. This token will be"+ + p.Printfln("Creating an API token for the user %s. This token will be "+ "used to authenticate the cluster.", a.User.Username) resp, err := tokens.NewClient(cfg).Create(context.Background(), &tokens.TokenCreateParameters{ Attributes: tokens.TokenAttributes{ @@ -175,7 +179,7 @@ func (c *connectCmd) getToken(p pterm.TextPrinter, upCtx *upbound.Context) (stri if err != nil { return "", errors.Wrap(err, "failed to create token") } - p.Printfln("Created a token named %q", c.ClusterName) + p.Printfln("Created a token named %s.", c.ClusterName) return fmt.Sprint(resp.DataSet.Meta["jwt"]), nil } diff --git a/internal/install/helm/helm.go b/internal/install/helm/helm.go index 668ce7a6..885215bf 100644 --- a/internal/install/helm/helm.go +++ b/internal/install/helm/helm.go @@ -20,6 +20,7 @@ import ( "os" "path/filepath" "strings" + "time" "github.com/Masterminds/semver" "github.com/crossplane/crossplane-runtime/pkg/errors" @@ -43,6 +44,7 @@ const ( defaultCacheDir = ".cache/up/charts" defaultNamespace = "upbound-system" allVersions = ">0.0.0-0" + waitTimeout = 10 * time.Minute ) const ( @@ -118,6 +120,7 @@ type installer struct { cacheDir string rollbackOnError bool force bool + wait bool home HomeDirFn fs afero.Fs tempDir TempDirFn @@ -207,6 +210,13 @@ func Force(f bool) InstallerModifierFn { } } +// Wait will wait operations till they are completed. +func Wait() InstallerModifierFn { + return func(h *installer) { + h.wait = true + } +} + // NewManager builds a helm install manager for UXP. func NewManager(config *rest.Config, chartName string, repoURL *url.URL, modifiers ...InstallerModifierFn) (install.Manager, error) { // nolint:gocyclo h := &installer{ @@ -276,18 +286,27 @@ func NewManager(config *rest.Config, chartName string, repoURL *url.URL, modifie ic := action.NewInstall(actionConfig) ic.Namespace = h.namespace ic.ReleaseName = h.chartName + ic.Wait = h.wait + ic.Timeout = waitTimeout h.installClient = ic // Upgrade Client uc := action.NewUpgrade(actionConfig) uc.Namespace = h.namespace + uc.Wait = h.wait + uc.Timeout = waitTimeout h.upgradeClient = uc // Uninstall Client - h.uninstallClient = action.NewUninstall(actionConfig) + unc := action.NewUninstall(actionConfig) + unc.Wait = h.wait + unc.Timeout = waitTimeout + h.uninstallClient = unc // Rollback Client rb := action.NewRollback(actionConfig) + rb.Wait = h.wait + rb.Timeout = waitTimeout h.rollbackClient = rb return h, nil