File: generatorOptions.md

package info (click to toggle)
kustomize 5.6.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,572 kB
  • sloc: makefile: 162; sh: 123
file content (60 lines) | stat: -rw-r--r-- 1,601 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Generator Options

Kustomize 提供了修改 ConfigMapGenerator 和 SecretGenerator 行为的选项,这些选项包括:
 
 - 不再将基于内容生成的哈希后缀添加到资源名称后
 - 为生成的资源添加 labels
 - 为生成的资源添加 annotations
 
这个示例将展示如何运用这些选项,首先创建一个工作空间:
```bash
DEMO_HOME=$(mktemp -d)
```

创建 kustomization 并且为其添加一个 ConfigMapGenerator

<!-- @createCMGenerator @test -->
```bash
cat > $DEMO_HOME/kustomization.yaml << EOF
configMapGenerator:
- name: my-configmap
  literals:	
  - foo=bar
  - baz=qux
EOF
```

添加如下 generatorOptions
<!-- @addGeneratorOptions @test -->
```bash
cat >> $DEMO_HOME/kustomization.yaml << EOF
generatorOptions:
 disableNameSuffixHash: true
 labels:
   kustomize.generated.resource: somevalue
 annotations:
   annotations.only.for.generated: othervalue
EOF
```
运行 `kustomize build` 并且确定生成的 ConfigMap 。
 
 - 确定没有名称后缀
    <!-- @verify @test -->
    ```
    test 1 == \
    $(kustomize build $DEMO_HOME | grep "name: my-configmap$" | wc -l); \
    echo $?
    ```
 - 确定 label `kustomize.generated.resource: somevalue`
     ```
     test 1 == \
     $(kustomize build $DEMO_HOME | grep -A 1 "labels" | grep "kustomize.generated.resource" | wc -l); \
     echo $?
     ```
 - 确定 annotation `annotations.only.for.generated: othervalue`
      ```
      test 1 == \
      $(kustomize build $DEMO_HOME | grep -A 1 "annotations" | grep "annotations.only.for.generated" | wc -l); \
      echo $?
      ```