how to set image name/tag for container images specified in CRDs through the kustomization.yaml using the images field?
The images field works well when the container images are specified in either Deployment or StatefulSet, but not transform a CRD resource from:
apiVersion: foo.example.com/v1alpha1
kind: Application
spec:
image: xxxTo:
apiVersion: foo.example.com/v1alpha1
kind: Application
spec:
image: new-image:tagYour task can be solved easily using yq. The command depends on the yq implementation you are using:
IMAGE="new-image:tag" yq e '.spec.image = strenv(IMAGE)'
yq -y --arg IMAGE "new-image:tag" '.spec.image |= $IMAGE'
This is a working example of using the ImageTagTransformer.
Given below yaml files:
<!-- language: yaml --># transformer_1.yaml
---
apiVersion: builtin
kind: ImageTagTransformer
metadata:
name: not-important-here
imageTag:
name: xxx
newName: new-image
newTag: tag
fieldSpecs:
- path: spec/image
kind: Application
# application.yaml
---
apiVersion: foo.example.com/v1alpha1
kind: Application
spec:
image: xxx
# kustomization.yaml
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- application.yaml
transformers:
- transformer_1.yamlRun this command:
<!-- language: yaml -->$ kustomize build ./ | kpt cfg grep "kind=Application"
apiVersion: foo.example.com/v1alpha1
kind: Application
spec:
image: new-image:tagHowever, I still need to figure out ways to get it work with skaffold workflow.
the feedback from skaffold community said it doesn't support rewriting manifests except those are in an allowlist. So the lesson learn is, skaffold doesn't support rewriting any CRDs yet.