Skip to content

Commit 4827d99

Browse files
committed
Add example for generatorOptions
1 parent d718fe3 commit 4827d99

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

docs/kustomization.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,24 @@ secretGenerator:
102102
envCommand: printf \"DB_USERNAME=admin\nDB_PASSWORD=somepw\"
103103
type: Opaque
104104

105+
# generatorOptions modify behavior of all ConfigMap and Secret generators
106+
generatorOptions:
107+
# labels to add to all generated resources
108+
labels:
109+
kustomize.generated.resources: somevalue
110+
# annotations to add to all generated resources
111+
annotations:
112+
kustomize.generated.resource: somevalue
113+
# timeoutSeconds specifies the timeout for commands
114+
timeoutSeconds: 30
115+
# shell and arguments to use as a context for commands used in resource
116+
# generation. Default at time of writing: ["sh", "-c"]
117+
shell: ["sh", "-c"]
118+
# disableNameSuffixHash is true disables the default behavior of adding a
119+
# suffix to the names of generated resources that is a hash of
120+
# the resource contents.
121+
disableNameSuffixHash: true
122+
105123
# Each entry in this list should resolve to a directory
106124
# containing a kustomization file, else the
107125
# customization fails.

examples/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ go get sigs.k8s.io/kustomize
2929

3030
* [configGenerations](configGeneration.md) -
3131
Rolling update when ConfigMapGenerator changes
32+
33+
* [generatorOptions](generatorOptions.md) - Modifying behavior of all ConfigMap and Secret generators.
3234

3335
* [breakfast](breakfast.md) - Customize breakfast for
3436
Alice and Bob.

examples/generatorOptions.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Generator Options
2+
3+
Kustomize provides options to modify the behavior of ConfigMap and Secret generators. These options include
4+
5+
- disable appending a content has suffix to the names of generated resources
6+
- adding labels to generated resources
7+
- adding annotations to generated resources
8+
- changing shell and arguments for getting data from commands
9+
- changing timeout for executing commands
10+
11+
This demo shows how to use these options. First create a workspace.
12+
```
13+
DEMO_HOME=$(mkdir -d)
14+
```
15+
16+
Create a kustomization and add a ConfigMap generator to it.
17+
18+
<!-- @createCMGenerator @test -->
19+
```
20+
cat > $DEMO_HOME/kustomization.yaml << EOF
21+
configMapGenerator:
22+
- name: my-configmap
23+
literals:
24+
- foo=bar
25+
- baz=qux
26+
EOF
27+
```
28+
29+
Add following generatorOptions
30+
<!-- @addGeneratorOptions @test -->
31+
```
32+
cat >> $DEMO_HOME/kustomization.yaml << EOF
33+
generatorOptions:
34+
disableNameSuffixHash: true
35+
labels:
36+
kustomize.generated.resource: somevalue
37+
annotations:
38+
annotations.only.for.generated: othervalue
39+
EOF
40+
```
41+
Run `kustomize build` and make sure that the generated ConfigMap
42+
43+
- doesn't have name suffix
44+
<!-- @verify @test -->
45+
```
46+
test 1 == \
47+
$(kustomize build $DEMO_HOME | grep "name: my-configmap$" | wc -l); \
48+
echo $?
49+
```
50+
- has label `kustomize.generated.resource: somevalue`
51+
```
52+
test 1 == \
53+
$(kustomize build $DEMO_HOME | grep -A 1 "labels" | grep "kustomize.generated.resource" | wc -l); \
54+
echo $?
55+
```
56+
- has annotation `annotations.only.for.generated: othervalue`
57+
```
58+
test 1 == \
59+
$(kustomize build $DEMO_HOME | grep -A 1 "annotations" | grep "annotations.only.for.generated" | wc -l); \
60+
echo $?
61+
```
62+

0 commit comments

Comments
 (0)