Skip to content

Commit

Permalink
Merge pull request #315 from muvaf/waitconnect
Browse files Browse the repository at this point in the history
connect: wait for helm installation to complete
  • Loading branch information
muvaf committed Mar 23, 2023
2 parents 9553be8 + 0c21032 commit 77b83a8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
12 changes: 8 additions & 4 deletions cmd/up/controlplane/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}

Expand All @@ -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{
Expand All @@ -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
}

Expand Down
21 changes: 20 additions & 1 deletion internal/install/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/Masterminds/semver"
"github.com/crossplane/crossplane-runtime/pkg/errors"
Expand All @@ -43,6 +44,7 @@ const (
defaultCacheDir = ".cache/up/charts"
defaultNamespace = "upbound-system"
allVersions = ">0.0.0-0"
waitTimeout = 10 * time.Minute
)

const (
Expand Down Expand Up @@ -118,6 +120,7 @@ type installer struct {
cacheDir string
rollbackOnError bool
force bool
wait bool
home HomeDirFn
fs afero.Fs
tempDir TempDirFn
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 77b83a8

Please sign in to comment.