For a recent kustomization project, I’ve noticed lots of redundancy in my transformers.
Consider the follwing kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base
configMapGenerator:
- literals:
- CUSTOMER=customerx
name: settings
transformers:
- transform-customer.yaml
which references the following transform-customer.yaml
:
---
apiVersion: builtin
kind: PrefixTransformer
metadata:
name: customer-prefix
prefix: customerx-
fieldSpecs:
- path: metadata/name
---
apiVersion: builtin
kind: LabelTransformer
metadata:
name: customer-label
labels:
customer: customerx
fieldSpecs:
- path: metadata/labels
Even for this small example, you can see that the customer name customerx
is referenced 3 times, once in the ConfigMap
and then again for each transformer.
Is there any way of transforming the transformers, so I can inject the customer name from the ConfigMap
(note that the 1st transformer needs a trailing -
for the prefix property)?
As variables are deprecated I took a look at the ReplacementTransformer
(corresponding to the replacements
YAML key), but neither could it just replace a part of the target property, nor could I get it to transform my transformers, only regular Kubernetes resources.
Do you have any idea how I can get rid of the redundancy? Please note that this is only a minimal example, there are more values and transformations that need to be handled in the same way.