# Generator Options Kustomize 提供了修改 ConfigMapGenerator 和 SecretGenerator 行为的选项,这些选项包括: - 不再将基于内容生成的哈希后缀添加到资源名称后 - 为生成的资源添加 labels - 为生成的资源添加 annotations 这个示例将展示如何运用这些选项,首先创建一个工作空间: ```bash DEMO_HOME=$(mktemp -d) ``` 创建 kustomization 并且为其添加一个 ConfigMapGenerator ```bash cat > $DEMO_HOME/kustomization.yaml << EOF configMapGenerator: - name: my-configmap literals: - foo=bar - baz=qux EOF ``` 添加如下 generatorOptions ```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 。 - 确定没有名称后缀 ``` 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 $? ```