Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion launchpad/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ type DeployOptions struct {

LifecycleHook hook.LifecycleHook

Namespace string
Namespace string
CreateNamespace bool

RemoteEnvVars map[string]string
Runtime *HelmOptions
Expand Down
20 changes: 13 additions & 7 deletions launchpad/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func applyHelmCharts(
return nil, errorutil.CombinedError(err, errUnableToAccessHelmReleases)
}

createNamespace := plan.DeployOptions.CreateNamespace
for _, cc := range plan.Charts() {
c, err := actionConfig(ctx, plan.helmDriver, cc.Namespace, settings)
if err != nil {
Expand All @@ -53,7 +54,7 @@ func applyHelmCharts(
releases[cc.Name], err = upgradeHelmChart(ctx, cc, settings, c)

if plan.DeployOptions.ReinstallOnHelmUpgradeError {
releases[cc.Name], err = reinstallHelmChart(ctx, cc.Release, cc, settings, c)
releases[cc.Name], err = reinstallHelmChart(ctx, cc.Release, cc, settings, c, createNamespace)
if err != nil {
return nil, errors.WithStack(err)
}
Expand All @@ -71,12 +72,12 @@ func applyHelmCharts(
// We will automatically down the old release and up a new release.
// Since the old release is using app name as the release name.
jetlog.Logger(ctx).IndentedPrintln("Detected old install by the project name. Changing to install by project ID.")
releases[cc.Name], err = reinstallHelmChart(ctx, cc.instanceName, cc, settings, c)
releases[cc.Name], err = reinstallHelmChart(ctx, cc.instanceName, cc, settings, c, createNamespace)
if err != nil {
return nil, errors.WithStack(err)
}
} else {
releases[cc.Name], err = installHelmChart(ctx, cc, settings, c)
releases[cc.Name], err = installHelmChart(ctx, cc, settings, c, createNamespace)
if err != nil {
return releases, errors.Wrap(err, "Error installing helm chart")
}
Expand All @@ -96,7 +97,7 @@ func applyHelmCharts(
return nil, err
}
} else {
_, err = installHelmChart(ctx, chart, settings, c)
_, err = installHelmChart(ctx, chart, settings, c, createNamespace)
if err != nil {
return nil, err
}
Expand All @@ -111,6 +112,7 @@ func installHelmChart(
cc *ChartConfig,
settings *cli.EnvSettings,
config *action.Configuration,
createNamespace bool,
) (*release.Release, error) {
install := action.NewInstall(config)

Expand All @@ -121,8 +123,11 @@ func installHelmChart(

install.Namespace = cc.Namespace
install.ReleaseName = cc.Release
// For Jetpack-managed clusters, namespace is created (and permissions are set) by InitNamespace. And we
// cannot set --create-namespace=true because multi-tenant cluster users won't have permissions.
// Setting --create-namespace=true makes Helm attempt to create the namespace and continue if it already
// exists, but it will fail if the user lacks permissions to create namespaces. Thus, we cannot set this
// to true every time, because it might fail for managed multi-tenant clusters where a user's permissions
// are limited.
install.CreateNamespace = createNamespace

install.Wait = cc.Wait
install.Timeout = cc.Timeout
Expand Down Expand Up @@ -376,6 +381,7 @@ func reinstallHelmChart(
cc *ChartConfig,
settings *cli.EnvSettings,
config *action.Configuration,
createNamespace bool,
) (*release.Release, error) {
jetlog.Logger(ctx).BoldPrintf("Could not upgrade. Reinstalling...\n")
uninstall := action.NewUninstall(config)
Expand All @@ -384,5 +390,5 @@ func reinstallHelmChart(
if err != nil {
return nil, errorutil.CombinedError(err, errUserReinstallFail)
}
return installHelmChart(ctx, cc, settings, config)
return installHelmChart(ctx, cc, settings, config, createNamespace)
}
1 change: 1 addition & 0 deletions padcli/command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func makeDeployOptions(
Values: appValues,
Timeout: lo.Ternary(len(jetCfg.Jobs()) > 0, 5*time.Minute, 0),
},
CreateNamespace: hvc.CreateNamespace(),
Environment: cmdOpts.RootFlags().Env().String(),
ExternalCharts: jetconfigHelmToChartConfig(jetCfg, ns),
JetCfg: jetCfg,
Expand Down
18 changes: 9 additions & 9 deletions padcli/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ import (
"go.jetpack.io/launchpad/proto/api"
)

// type cluster interface {
// GetHostname() string
// GetIsPrivate() bool
// GetName() string
// IsLocal() bool
// IsJetpackManaged() bool
// IsRemoteUnmanaged() bool
// }

// ValueComputer transforms jetpack CLI inputs into helm values.
// Right now we mostly copy paste the logic, but the idea is to have individual
// modules that compute sections of the values. e.g. ambassadorModule, cronjobModule, etc.
Expand All @@ -31,6 +22,7 @@ type ValueComputer struct {

env api.Environment
namespace string // The final namespace to be used
createNamespace bool // Value used for helm's --create-namespace
execQualifiedSymbol string // Used by jetpack dev <path/to/project> --exec <symbol>
imageProvider *ImageProvider
jetCfg *jetconfig.Config // consider interface
Expand Down Expand Up @@ -217,6 +209,14 @@ func (hvc *ValueComputer) Namespace() string {
return hvc.namespace
}

func (hvc *ValueComputer) CreateNamespace() bool {
return hvc.createNamespace
}

func (hvc *ValueComputer) SetCreateNamespace(createNamespace bool) {
hvc.createNamespace = createNamespace
}

func (hvc *ValueComputer) Cluster() provider.Cluster {
return hvc.cluster
}