2

I am using a JSON patch in my overlay kustomization file in order to set the image to use for my pods.

The patch itself is pretty generic:

- op: replace
  path: /spec/template/spec/containers/0/image
  value: myRegistry/myImage:myTag

And in my kustomization.yml:

patchesJson6902:
  - target:
      group: apps
      version: v1
      kind: Deployment
      name: myDeployment
    path: patch_image.yml

By using this method, I have to use a different patch for each deployment that uses a different image. Is there a way to move the patch value field up to the kustomization.yml file, where I could do something like:

patchesJson6902:
  - target:
      group: apps
      version: v1
      kind: Deployment
      name: myDeploymentA
    path: patch_image.yml
    value: myRegistry/myImageA:myTag
  - target:
      group: apps
      version: v1
      kind: Deployment
      name: myDeploymentB
    path: patch_image.yml
    value: myRegistry/myImageB:myTag
ITChap
  • 4,057
  • 1
  • 21
  • 46
  • I just found that y exact example can be solved with https://github.com/kubernetes-sigs/kustomize/tree/master/examples/transformerconfigs#images-transformer but the problem of patch reuse is still not solved. – ITChap Jun 04 '19 at 08:02
  • You seem to want parameterized patches, and that is not possible with kustomize. You could write the whole patch inline but the `op` and `path` would have to be part of it. – chicocvenancio Jan 24 '22 at 12:38

0 Answers0