Skip to content

Commit 8f701a0

Browse files
authored
Merge pull request #565 from zoncoen/name-suffix-3
Update docs, examples, comments, and test data for nameSuffix
2 parents 593f923 + 59df8a0 commit 8f701a0

File tree

14 files changed

+43
-22
lines changed

14 files changed

+43
-22
lines changed

docs/glossary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ Here's an [example](kustomization.yaml).
150150
A kustomization contains fields falling into these categories:
151151

152152
* _Customization operators_ for modifying operands, e.g.
153-
_namePrefix_, _commonLabels_, _patches_, etc.
153+
_namePrefix_, _nameSuffix_, _commonLabels_, _patches_, etc.
154154

155155
* _Customization operands_:
156156
* [resources] - completely specified k8s API objects,

docs/kustomization.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ namespace: my-namespace
4040
# "wordpress" becomes "alices-wordpress".
4141
namePrefix: alices-
4242

43+
# Value of this field is appended to the
44+
# names of all resources, e.g. a deployment named
45+
# "wordpress" becomes "wordpress-v2".
46+
# The suffix is appended before content hash
47+
# if resource type is ConfigMap or Secret.
48+
nameSuffix: -v2
49+
4350
# Labels to add to all resources and selectors.
4451
commonLabels:
4552
someName: someValue
@@ -205,9 +212,9 @@ patchesJson6902:
205212
# transformation for any objects in those types.
206213
#
207214
# Typical use case: A CRD object refers to a ConfigMap object.
208-
# In kustomization, the ConfigMap object name may change by adding namePrefix or hashing
215+
# In kustomization, the ConfigMap object name may change by adding namePrefix, nameSuffix, or hashing
209216
# The name reference for this ConfigMap object in CRD object need to be
210-
# updated with namePrefix or hashing in the same way.
217+
# updated with namePrefix, nameSuffix, or hashing in the same way.
211218
crds:
212219
- crds/typeA.yaml
213220
- crds/typeB.yaml

examples/combineConfigs.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ cat <<EOF >$OVERLAYS/development/kustomization.yaml
194194
bases:
195195
- ../../base
196196
namePrefix: dev-
197+
nameSuffix: -v1
197198
configMapGenerator:
198199
- name: my-configmap
199200
behavior: merge
@@ -215,11 +216,12 @@ kustomize build $OVERLAYS/development
215216
The name of the generated `ConfigMap` is visible in this
216217
output.
217218

218-
The name should be something like `dev-my-configmap-b5m75ck895`:
219+
The name should be something like `dev-my-configmap-v1-2gccmccgd5`:
219220

220221
* `"dev-"` comes from the `namePrefix` field,
221222
* `"my-configmap"` comes from the `configMapGenerator/name` field,
222-
* `"-b5m75ck895"` comes from a deterministic hash that `kustomize`
223+
* `"-v1"` comes from the `nameSuffix` field,
224+
* `"-2gccmccgd5"` comes from a deterministic hash that `kustomize`
223225
computes from the contents of the configMap.
224226

225227
The hash suffix is critical. If the configMap content

examples/configGeneration.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ mkdir -p $OVERLAYS/staging
6060

6161
cat <<'EOF' >$OVERLAYS/staging/kustomization.yaml
6262
namePrefix: staging-
63+
nameSuffix: -v1
6364
commonLabels:
6465
variant: staging
6566
org: acmeCorporation
@@ -150,13 +151,17 @@ The configMap name is prefixed by _staging-_, per the
150151
`namePrefix` field in
151152
`$OVERLAYS/staging/kustomization.yaml`.
152153
154+
The configMap name is suffixed by _-v1_, per the
155+
`nameSuffix` field in
156+
`$OVERLAYS/staging/kustomization.yaml`.
157+
153158
The suffix to the configMap name is generated from a
154159
hash of the maps content - in this case the name suffix
155-
is _hhhhkfmgmk_:
160+
is _k25m8k5k5m_:
156161
157162
<!-- @grepStagingHash @test -->
158163
```
159-
kustomize build $OVERLAYS/staging | grep hhhhkfmgmk
164+
kustomize build $OVERLAYS/staging | grep k25m8k5k5m
160165
```
161166
162167
Now modify the map patch, to change the greeting
@@ -183,20 +188,20 @@ kustomize build $OVERLAYS/staging |\
183188
```
184189
185190
Confirm that the change in configMap content resulted
186-
in three new names ending in _khk45ktkd9_ - one in the
191+
in three new names ending in _cd7kdh48fd_ - one in the
187192
configMap name itself, and two in the deployment that
188193
uses the map:
189194
190195
<!-- @countHashes @test -->
191196
```
192197
test 3 == \
193-
$(kustomize build $OVERLAYS/staging | grep khk45ktkd9 | wc -l); \
198+
$(kustomize build $OVERLAYS/staging | grep cd7kdh48fd | wc -l); \
194199
echo $?
195200
```
196201
197202
Applying these resources to the cluster will result in
198203
a rolling update of the deployments pods, retargetting
199-
them from the _hhhhkfmgmk_ maps to the _khk45ktkd9_
204+
them from the _k25m8k5k5m_ maps to the _cd7kdh48fd_
200205
maps. The system will later garbage collect the
201206
unused maps.
202207

examples/transformerconfigs/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Kustomize computes the resources by applying a series of transformers:
44
- namespace transformer
5-
- prefix transformer
5+
- prefix/suffix transformer
66
- label transformer
77
- annotation transformer
88
- name reference transformer
@@ -22,8 +22,8 @@ create: false
2222
```
2323
If `create` is set to true, it indicates the transformer to create the path if it is not found in the resources. This is most useful for label and annotation transformers, where the path for labels or annotations may not be set before the transformation.
2424

25-
## prefix transformer
26-
Name prefix transformer adds prefix to the `metadata/name` field for all resources with following configuration:
25+
## prefix/suffix transformer
26+
Name prefix suffix transformer adds prefix and suffix to the `metadata/name` field for all resources with following configuration:
2727
```
2828
namePrefix:
2929
- path: metadata/name

pkg/commands/build/testdata/testcase-multibases-conflict/base/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ resources:
22
- serviceaccount.yaml
33
- rolebinding.yaml
44
namePrefix: base-
5+
nameSuffix: -suffix

pkg/commands/build/testdata/testcase-multibases-conflict/overlays/a/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ bases:
22
- ../../base/
33

44
namePrefix: a-
5+
nameSuffix: -suffixA
56

67
resources:
78
- serviceaccount.yaml

pkg/commands/build/testdata/testcase-multibases-conflict/overlays/b/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ bases:
22
- ../../base/
33

44
namePrefix: b-
5+
nameSuffix: -suffixB

pkg/commands/build/testdata/testcase-multibases-nonconflict/base/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ resources:
22
- serviceaccount.yaml
33
- rolebinding.yaml
44
namePrefix: base-
5+
nameSuffix: -suffix
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
apiVersion: v1
22
kind: ServiceAccount
33
metadata:
4-
name: a-base-serviceaccount
4+
name: a-base-serviceaccount-suffix-suffixA
55
---
66
apiVersion: v1
77
kind: ServiceAccount
88
metadata:
9-
name: b-base-serviceaccount
9+
name: b-base-serviceaccount-suffix-suffixB
1010
---
1111
apiVersion: rbac.authorization.k8s.io/v1beta1
1212
kind: RoleBinding
1313
metadata:
14-
name: a-base-rolebinding
14+
name: a-base-rolebinding-suffix-suffixA
1515
roleRef:
1616
apiGroup: rbac.authorization.k8s.io
1717
kind: Role
1818
name: role
1919
subjects:
2020
- kind: ServiceAccount
21-
name: a-base-serviceaccount
21+
name: a-base-serviceaccount-suffix-suffixA
2222
---
2323
apiVersion: rbac.authorization.k8s.io/v1beta1
2424
kind: RoleBinding
2525
metadata:
26-
name: b-base-rolebinding
26+
name: b-base-rolebinding-suffix-suffixB
2727
roleRef:
2828
apiGroup: rbac.authorization.k8s.io
2929
kind: Role
3030
name: role
3131
subjects:
3232
- kind: ServiceAccount
33-
name: b-base-serviceaccount
33+
name: b-base-serviceaccount-suffix-suffixB

0 commit comments

Comments
 (0)