mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 10:00:56 +00:00
Merge pull request #501 from Liujingfang1/generatoroptions
Add example for generatorOptions
This commit is contained in:
@@ -102,6 +102,24 @@ secretGenerator:
|
|||||||
envCommand: printf \"DB_USERNAME=admin\nDB_PASSWORD=somepw\"
|
envCommand: printf \"DB_USERNAME=admin\nDB_PASSWORD=somepw\"
|
||||||
type: Opaque
|
type: Opaque
|
||||||
|
|
||||||
|
# generatorOptions modify behavior of all ConfigMap and Secret generators
|
||||||
|
generatorOptions:
|
||||||
|
# labels to add to all generated resources
|
||||||
|
labels:
|
||||||
|
kustomize.generated.resources: somevalue
|
||||||
|
# annotations to add to all generated resources
|
||||||
|
annotations:
|
||||||
|
kustomize.generated.resource: somevalue
|
||||||
|
# timeoutSeconds specifies the timeout for commands
|
||||||
|
timeoutSeconds: 30
|
||||||
|
# shell and arguments to use as a context for commands used in resource
|
||||||
|
# generation. Default at time of writing: ["sh", "-c"]
|
||||||
|
shell: ["sh", "-c"]
|
||||||
|
# disableNameSuffixHash is true disables the default behavior of adding a
|
||||||
|
# suffix to the names of generated resources that is a hash of
|
||||||
|
# the resource contents.
|
||||||
|
disableNameSuffixHash: true
|
||||||
|
|
||||||
# Each entry in this list should resolve to a directory
|
# Each entry in this list should resolve to a directory
|
||||||
# containing a kustomization file, else the
|
# containing a kustomization file, else the
|
||||||
# customization fails.
|
# customization fails.
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ go get sigs.k8s.io/kustomize
|
|||||||
* [configGenerations](configGeneration.md) -
|
* [configGenerations](configGeneration.md) -
|
||||||
Rolling update when ConfigMapGenerator changes
|
Rolling update when ConfigMapGenerator changes
|
||||||
|
|
||||||
|
* [generatorOptions](generatorOptions.md) - Modifying behavior of all ConfigMap and Secret generators.
|
||||||
|
|
||||||
* [breakfast](breakfast.md) - Customize breakfast for
|
* [breakfast](breakfast.md) - Customize breakfast for
|
||||||
Alice and Bob.
|
Alice and Bob.
|
||||||
|
|
||||||
|
|||||||
62
examples/generatorOptions.md
Normal file
62
examples/generatorOptions.md
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
# Generator Options
|
||||||
|
|
||||||
|
Kustomize provides options to modify the behavior of ConfigMap and Secret generators. These options include
|
||||||
|
|
||||||
|
- disable appending a content hash suffix to the names of generated resources
|
||||||
|
- adding labels to generated resources
|
||||||
|
- adding annotations to generated resources
|
||||||
|
- changing shell and arguments for getting data from commands
|
||||||
|
- changing timeout for executing commands
|
||||||
|
|
||||||
|
This demo shows how to use these options. First create a workspace.
|
||||||
|
```
|
||||||
|
DEMO_HOME=$(mkdir -d)
|
||||||
|
```
|
||||||
|
|
||||||
|
Create a kustomization and add a ConfigMap generator to it.
|
||||||
|
|
||||||
|
<!-- @createCMGenerator @test -->
|
||||||
|
```
|
||||||
|
cat > $DEMO_HOME/kustomization.yaml << EOF
|
||||||
|
configMapGenerator:
|
||||||
|
- name: my-configmap
|
||||||
|
literals:
|
||||||
|
- foo=bar
|
||||||
|
- baz=qux
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
Add following generatorOptions
|
||||||
|
<!-- @addGeneratorOptions @test -->
|
||||||
|
```
|
||||||
|
cat >> $DEMO_HOME/kustomization.yaml << EOF
|
||||||
|
generatorOptions:
|
||||||
|
disableNameSuffixHash: true
|
||||||
|
labels:
|
||||||
|
kustomize.generated.resource: somevalue
|
||||||
|
annotations:
|
||||||
|
annotations.only.for.generated: othervalue
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
Run `kustomize build` and make sure that the generated ConfigMap
|
||||||
|
|
||||||
|
- doesn't have name suffix
|
||||||
|
<!-- @verify @test -->
|
||||||
|
```
|
||||||
|
test 1 == \
|
||||||
|
$(kustomize build $DEMO_HOME | grep "name: my-configmap$" | wc -l); \
|
||||||
|
echo $?
|
||||||
|
```
|
||||||
|
- has label `kustomize.generated.resource: somevalue`
|
||||||
|
```
|
||||||
|
test 1 == \
|
||||||
|
$(kustomize build $DEMO_HOME | grep -A 1 "labels" | grep "kustomize.generated.resource" | wc -l); \
|
||||||
|
echo $?
|
||||||
|
```
|
||||||
|
- has annotation `annotations.only.for.generated: othervalue`
|
||||||
|
```
|
||||||
|
test 1 == \
|
||||||
|
$(kustomize build $DEMO_HOME | grep -A 1 "annotations" | grep "annotations.only.for.generated" | wc -l); \
|
||||||
|
echo $?
|
||||||
|
```
|
||||||
|
|
||||||
Reference in New Issue
Block a user