Kustomize is a template-free declarative management tool for Kubernetes resources. Kustomize has 2 main concepts: Generators and Transformers. In short, the first able to create K8s manifests, and the second is able to manipulate K8s manifests. In this post, I'm interested in the Kustomize Transformers.
In Kustomize, "everything is a transformer"! In fact, the transformers have a general generative power too! But always remember that transformers run after generators. Anyway, this is not the topic of this post. I just wanted to highlight how powerful Kustomize transformers are.
---
Kustomize has a bunch of default/builtin transformers like namePrefix, nameSuffix, commonAnnotations, and commonLabels (you probably used one of them if you just used Kustomize before). Those builtin transformers are global by default which means they are applied to all resources managed by Kustomize.
The question is, what if you want to apply a change like namePrefix to a specific resource?
You can apply any of Kustomize builtin transformers to certain resources. Here is an example:
# kustomization.yaml transformers: - |- apiVersion: builtin kind: PrefixSuffixTransformer metadata: name: my-service prefix: dev- fieldSpecs: - path: metadata/name
It works exactly like namePrefix but on a single resource called my-service which will be transformed to dev-my-service.
That's it! :-)