Support Helm's NS creation for TargetNamespace
This adds support for creating the target release namespace if it is not present which can be be useful in certain scenarios. Note that when the release is uninstalled, the namespace is not removed and remains on the cluster, and managing your namespace _outside_ of the HelmRelease is advised. Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit is contained in:
parent
32ecdfa356
commit
5e4bd8fe80
|
@ -94,6 +94,15 @@ jobs:
|
||||||
kubectl -n default get deployment default-targetnamespace-podinfo
|
kubectl -n default get deployment default-targetnamespace-podinfo
|
||||||
|
|
||||||
kubectl -n helm-system delete -f config/testdata/targetnamespace
|
kubectl -n helm-system delete -f config/testdata/targetnamespace
|
||||||
|
- name: Run install create target namespace test
|
||||||
|
run: |
|
||||||
|
kubectl -n helm-system apply -f config/testdata/install-create-target-ns
|
||||||
|
kubectl -n helm-system wait helmreleases/install-create-target-ns --for=condition=ready --timeout=4m
|
||||||
|
|
||||||
|
# Confirm release in "install-create-target-ns" namespace
|
||||||
|
kubectl -n install-create-target-ns get deployment install-create-target-ns-install-create-target-ns-podinfo
|
||||||
|
|
||||||
|
kubectl -n helm-system delete -f config/testdata/install-create-target-ns
|
||||||
- name: Run install fail test
|
- name: Run install fail test
|
||||||
run: |
|
run: |
|
||||||
test_name=install-fail
|
test_name=install-fail
|
||||||
|
|
|
@ -290,6 +290,12 @@ type Install struct {
|
||||||
// CRDs are installed if not already present.
|
// CRDs are installed if not already present.
|
||||||
// +optional
|
// +optional
|
||||||
SkipCRDs bool `json:"skipCRDs,omitempty"`
|
SkipCRDs bool `json:"skipCRDs,omitempty"`
|
||||||
|
|
||||||
|
// CreateNamespace tells the Helm install action to create the
|
||||||
|
// HelmReleaseSpec.TargetNamespace if it does not exist yet.
|
||||||
|
// On uninstall, the namespace will not be garbage collected.
|
||||||
|
// +optional
|
||||||
|
CreateNamespace bool `json:"createNamespace,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTimeout returns the configured timeout for the Helm install action,
|
// GetTimeout returns the configured timeout for the Helm install action,
|
||||||
|
|
|
@ -131,6 +131,11 @@ spec:
|
||||||
description: Install holds the configuration for Helm install actions
|
description: Install holds the configuration for Helm install actions
|
||||||
for this HelmRelease.
|
for this HelmRelease.
|
||||||
properties:
|
properties:
|
||||||
|
createNamespace:
|
||||||
|
description: CreateNamespace tells the Helm install action to
|
||||||
|
create the HelmReleaseSpec.TargetNamespace if it does not exist
|
||||||
|
yet. On uninstall, the namespace will not be garbage collected.
|
||||||
|
type: boolean
|
||||||
disableHooks:
|
disableHooks:
|
||||||
description: DisableHooks prevents hooks from running during the
|
description: DisableHooks prevents hooks from running during the
|
||||||
Helm install action.
|
Helm install action.
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
apiVersion: helm.toolkit.fluxcd.io/v2beta1
|
||||||
|
kind: HelmRelease
|
||||||
|
metadata:
|
||||||
|
name: install-create-target-ns
|
||||||
|
spec:
|
||||||
|
interval: 5m
|
||||||
|
install:
|
||||||
|
createNamespace: true
|
||||||
|
chart:
|
||||||
|
spec:
|
||||||
|
chart: podinfo
|
||||||
|
version: '>=4.0.0 <5.0.0'
|
||||||
|
sourceRef:
|
||||||
|
kind: HelmRepository
|
||||||
|
name: podinfo
|
||||||
|
interval: 1m
|
||||||
|
targetNamespace: install-create-target-ns
|
|
@ -1119,6 +1119,20 @@ bool
|
||||||
CRDs are installed if not already present.</p>
|
CRDs are installed if not already present.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<code>createNamespace</code><br>
|
||||||
|
<em>
|
||||||
|
bool
|
||||||
|
</em>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<em>(Optional)</em>
|
||||||
|
<p>CreateNamespace tells the Helm install action to create the
|
||||||
|
HelmReleaseSpec.TargetNamespace if it does not exist yet.
|
||||||
|
On uninstall, the namespace will not be garbage collected.</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -185,6 +185,12 @@ type Install struct {
|
||||||
// CRDs are installed if not already present.
|
// CRDs are installed if not already present.
|
||||||
// +optional
|
// +optional
|
||||||
SkipCRDs bool `json:"skipCRDs,omitempty"`
|
SkipCRDs bool `json:"skipCRDs,omitempty"`
|
||||||
|
|
||||||
|
// CreateNamespace tells the Helm install action to create the
|
||||||
|
// HelmReleaseSpec.TargetNamespace if it does not exist yet.
|
||||||
|
// On uninstall, the namespace will not be garbage collected.
|
||||||
|
// +optional
|
||||||
|
CreateNamespace bool `json:"createNamespace,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InstallRemediation holds the configuration for Helm install remediation.
|
// InstallRemediation holds the configuration for Helm install remediation.
|
||||||
|
|
|
@ -60,6 +60,10 @@ func (r *Runner) Install(hr v2.HelmRelease, chart *chart.Chart, values chartutil
|
||||||
install.Replace = hr.Spec.GetInstall().Replace
|
install.Replace = hr.Spec.GetInstall().Replace
|
||||||
install.SkipCRDs = hr.Spec.GetInstall().SkipCRDs
|
install.SkipCRDs = hr.Spec.GetInstall().SkipCRDs
|
||||||
|
|
||||||
|
if hr.Spec.TargetNamespace != "" {
|
||||||
|
install.CreateNamespace = hr.Spec.GetInstall().CreateNamespace
|
||||||
|
}
|
||||||
|
|
||||||
return install.Run(chart, values.AsMap())
|
return install.Run(chart, values.AsMap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue