@@ -42,6 +42,7 @@ func applyHelmCharts(
42
42
return nil , errorutil .CombinedError (err , errUnableToAccessHelmReleases )
43
43
}
44
44
45
+ createNamespace := plan .DeployOptions .CreateNamespace
45
46
for _ , cc := range plan .Charts () {
46
47
c , err := actionConfig (ctx , plan .helmDriver , cc .Namespace , settings )
47
48
if err != nil {
@@ -53,7 +54,7 @@ func applyHelmCharts(
53
54
releases [cc .Name ], err = upgradeHelmChart (ctx , cc , settings , c )
54
55
55
56
if plan .DeployOptions .ReinstallOnHelmUpgradeError {
56
- releases [cc .Name ], err = reinstallHelmChart (ctx , cc .Release , cc , settings , c )
57
+ releases [cc .Name ], err = reinstallHelmChart (ctx , cc .Release , cc , settings , c , createNamespace )
57
58
if err != nil {
58
59
return nil , errors .WithStack (err )
59
60
}
@@ -71,12 +72,12 @@ func applyHelmCharts(
71
72
// We will automatically down the old release and up a new release.
72
73
// Since the old release is using app name as the release name.
73
74
jetlog .Logger (ctx ).IndentedPrintln ("Detected old install by the project name. Changing to install by project ID." )
74
- releases [cc .Name ], err = reinstallHelmChart (ctx , cc .instanceName , cc , settings , c )
75
+ releases [cc .Name ], err = reinstallHelmChart (ctx , cc .instanceName , cc , settings , c , createNamespace )
75
76
if err != nil {
76
77
return nil , errors .WithStack (err )
77
78
}
78
79
} else {
79
- releases [cc .Name ], err = installHelmChart (ctx , cc , settings , c )
80
+ releases [cc .Name ], err = installHelmChart (ctx , cc , settings , c , createNamespace )
80
81
if err != nil {
81
82
return releases , errors .Wrap (err , "Error installing helm chart" )
82
83
}
@@ -96,7 +97,7 @@ func applyHelmCharts(
96
97
return nil , err
97
98
}
98
99
} else {
99
- _ , err = installHelmChart (ctx , chart , settings , c )
100
+ _ , err = installHelmChart (ctx , chart , settings , c , createNamespace )
100
101
if err != nil {
101
102
return nil , err
102
103
}
@@ -111,6 +112,7 @@ func installHelmChart(
111
112
cc * ChartConfig ,
112
113
settings * cli.EnvSettings ,
113
114
config * action.Configuration ,
115
+ createNamespace bool ,
114
116
) (* release.Release , error ) {
115
117
install := action .NewInstall (config )
116
118
@@ -121,8 +123,11 @@ func installHelmChart(
121
123
122
124
install .Namespace = cc .Namespace
123
125
install .ReleaseName = cc .Release
124
- // For Jetpack-managed clusters, namespace is created (and permissions are set) by InitNamespace. And we
125
- // cannot set --create-namespace=true because multi-tenant cluster users won't have permissions.
126
+ // Setting --create-namespace=true makes Helm attempt to create the namespace and continue if it already
127
+ // exists, but it will fail if the user lacks permissions to create namespaces. Thus, we cannot set this
128
+ // to true every time, because it might fail for managed multi-tenant clusters where a user's permissions
129
+ // are limited.
130
+ install .CreateNamespace = createNamespace
126
131
127
132
install .Wait = cc .Wait
128
133
install .Timeout = cc .Timeout
@@ -376,6 +381,7 @@ func reinstallHelmChart(
376
381
cc * ChartConfig ,
377
382
settings * cli.EnvSettings ,
378
383
config * action.Configuration ,
384
+ createNamespace bool ,
379
385
) (* release.Release , error ) {
380
386
jetlog .Logger (ctx ).BoldPrintf ("Could not upgrade. Reinstalling...\n " )
381
387
uninstall := action .NewUninstall (config )
@@ -384,5 +390,5 @@ func reinstallHelmChart(
384
390
if err != nil {
385
391
return nil , errorutil .CombinedError (err , errUserReinstallFail )
386
392
}
387
- return installHelmChart (ctx , cc , settings , config )
393
+ return installHelmChart (ctx , cc , settings , config , createNamespace )
388
394
}
0 commit comments