Skip to content

Commit 6605d1b

Browse files
committed
feat(helm-namespace): add example for Helm namespace inheritance and related resources
1 parent ebf0063 commit 6605d1b

File tree

9 files changed

+95
-0
lines changed

9 files changed

+95
-0
lines changed

examples/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Advanced Usage
4242
* [last mile helm](chart.md) - Make last mile modifications to
4343
a helm chart.
4444

45+
* [helm namespace inheritance](helmNamespace/README.md) - Verify that an overlay namespace fills unset namespaces in Helm output without overwriting explicit chart namespaces.
46+
4547
* [secret generation](secretGeneratorPlugin.md) - Generating secrets from a plugin.
4648

4749
* [remote sources](goGetterGeneratorPlugin.md) - Generating from remote sources.

examples/helmNamespace/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Helm Namespace Example
2+
3+
This example exercises namespace transformation on resources generated from a local Helm chart.
4+
5+
The example kustomization sets a namespace for Helm-generated resources that do not already declare one, while preserving any namespace explicitly emitted by the chart.
6+
7+
## Build the example
8+
9+
This example defines the `helm` command as:
10+
11+
<!-- @defineHelmCommand @testHelm -->
12+
```sh
13+
helmCommand=${MYGOBIN:-~/go/bin}/helmV3
14+
```
15+
16+
Use the checked-in example:
17+
18+
<!-- @defineExampleHome @testHelm -->
19+
```sh
20+
EXAMPLE_HOME=examples/helmNamespace
21+
```
22+
23+
Build the example with Helm enabled:
24+
25+
<!-- @buildOverlay @testHelm -->
26+
```sh
27+
output=$(kustomize build \
28+
--enable-helm \
29+
--helm-command "$helmCommand" \
30+
"$EXAMPLE_HOME")
31+
printf '%s\n' "$output"
32+
```
33+
34+
The Service is emitted by the chart without a namespace, so the example namespace should be applied:
35+
36+
<!-- @checkMissingNamespaceFilled @testHelm -->
37+
```sh
38+
printf '%s\n' "$output" | grep -A4 'name: chart-service' | grep 'namespace: top-level-ns'
39+
```
40+
41+
The ConfigMap is emitted by the chart with an explicit namespace, so that value should be preserved:
42+
43+
<!-- @checkExistingNamespacePreserved @testHelm -->
44+
```sh
45+
printf '%s\n' "$output" | grep -A4 'name: chart-config' | grep 'namespace: chart-owned-ns'
46+
```
47+
48+
The Secret is emitted by the chart with an release namespace, so that value should be preserved:
49+
50+
<!-- @checkExistingNamespacePreserved @testHelm -->
51+
```sh
52+
printf '%s\n' "$output" | grep -A4 'name: chart-secret' | grep 'namespace: chart-ns'
53+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: v2
2+
name: namespace-fill
3+
version: 0.1.0
4+
type: application
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: chart-config
5+
namespace: chart-owned-ns
6+
data:
7+
owner: helm-chart
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: chart-secret
5+
namespace: {{ .Release.Namespace }}
6+
data:
7+
.secret-file: dmFsdWUtMg0KDQo=
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: chart-service
5+
spec:
6+
selector:
7+
app: chart-service
8+
ports:
9+
- port: 80
10+
targetPort: 8080

examples/helmNamespace/charts/namespace-fill/values.yaml

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
namespace: top-level-ns
5+
6+
helmGlobals:
7+
chartHome: charts
8+
9+
helmCharts:
10+
- name: namespace-fill
11+
namespace: chart-ns

hack/testExamplesAgainstKustomize.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ if onLinuxAndNotOnRemoteCI; then
3939
echo "On linux, and not on remote CI. Running helm tests."
4040
make $MYGOBIN/helmV3
4141
mdrip --mode test --label testHelm examples/chart.md
42+
mdrip --mode test --label testHelm examples/helmNamespace/README.md
4243
else
4344
echo "Skipping helm tests against $version."
4445
echo "Helm chart inflator has new features (includeCRD) only in HEAD."

0 commit comments

Comments
 (0)