I am using Kustomize to manage multiple variations of the same cluster. I am using nameSuffix
option to add a suffix to all my resources:
nameSuffix: -mysfx
My problem is that everything works fine but adding this suffix only to one Service resource cause me an issue. My problem is that the application (Patroni) interact with a service that must be called:
CLUSTER-NAME-config
so I want to exclude this single resource from the nameSuffix
. I know this is not possible due to how this feature was designed. I read several articles here on StackOverflow and on the web. I know I can skip the use of nameSuffix
for a category of resources. So I tried to put in my kustomization.yaml
the rows:
configurations:
- kustomize-config/kustomize-config.yaml
to skip all the Service resources. Then in the file kustomize-config/kustomize-config.yaml
nameSuffix:
- path: metadata/name
apiVersion: v1
kind: Service
skip: true
but this doesn't work.
Does anyone know what's wrong with this configuration?
Then suppose I am able now to skip the use of nameSuffix
for only Service resources, I have other two Services where I want to add this suffix. What do I have to do to add nameSuffix
to these two Services and not the one mentioned above?
If there is a better solution for this, please let me know.
CodePudding user response:
Skipping selected kind
s doesn't work because this feature wasn't implemented - from this comment on GitHub issue 519.
Also this is an example how it was supposed to be (what you tried)
Based on this comment, it works on kind
s that were explicitly mentioned:
The plugin's config is currently oriented towards specifying which kinds to modify, ignoring others.
Also based on some tests I performed, it looks for kind
s only, it doesn't look for names or anything, so only the whole kind
can be included. Hence second part of your question is I'm afraid not possible (well, using kustomize, you can use sed
for instance and modify everything you need on the go).
I created a simple structure and tested it:
$ tree
.
├── cm1.yaml
├── cm2.yaml
├── kustomization.yaml
├── kustomizeconfig
│ └── skip-prefix.yaml
├── pod.yaml
├── secret.yaml
└── storageclass.yaml
1 directory, 7 files
There are two configmaps, pod, secret and storageclass, total 5 objects.
$ cat kustomization.yaml
namePrefix: prefix-
nameSuffix: -suffix
resources:
- cm1.yaml
- cm2.yaml
- secret.yaml
- pod.yaml
- storageclass.yaml
configurations:
- ./kustomizeconfig/skip-prefix.yaml
And configuration (specified explicitly all kinds except for configmaps). Also it's called namePrefix
, however it works for both: prefix
and suffix
:
$ cat kustomizeconfig/skip-prefix.yaml
namePrefix:
- path: metadata/name
apiVersion: v1
kind: Secret
- path: metadata/name
apiVersion: v1
kind: Pod
- path: metadata/name
apiVersion: v1
kind: StorageClass
Eventually kustomize build .
looks like:
$ kustomize build .
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: prefix-local-storage-suffix # modified
provisioner: kubernetes.io/no-provisioner
---
apiVersion: v1
kind: ConfigMap
metadata:
name: cm1 # skipped
---
apiVersion: v1
kind: ConfigMap
metadata:
name: cm2 # skipped
---
apiVersion: v1
kind: Secret
metadata:
name: prefix-secret-suffix # modified
---
apiVersion: v1
kind: Pod
metadata:
name: prefix-pod-suffix # modified
spec:
containers:
- image: image
name: pod
Another potential option is to use PrefixSuffixTransformer
plugin - it works differently in terms of specifying what prefix
and/or suffix
should be added and fieldSpec
s where.
Please find an example and final results below within this Feature Test for Issue 0519_b.
Also there's already a good answer on StackOverflow about using PrefixSuffixTransformer
.