Search code examples
kuberneteskubectlkustomize

Kustomize patch with string literal: Double quotes replaced with single quotes


When adding a kustomize patch to a kustomization.yaml the double quotes are replaced with single quotes that lead to error

I am using the following:

kustomize edit add patch --patch "- op: add\n  path: /metadata/annotations/argocd.argoproj.io~1sync-wave\n. value: 1" --kind Deployment

is converted to

- patch: '- op: add\n  path: /metadata/annotations/argocd.argoproj.io~1sync-wave\n value: 1'
  target:
    kind: Deployment

in the kustomization.yaml

This leads to the following error when you do kustomize build

Error: trouble configuring builtin PatchTransformer with config: `
patch: ‘- op: add\n path: /metadata/annotations/argocd.argoproj.io~1sync-wave\n  value:
  1’
target:
  kind: Deployment
`: unable to parse SM or JSON patch from [- op: add\n path: /metadata/annotations/argocd.argoproj.io~1sync-wave\n  value: 1]

How do I make sure that the patch in kustomization.yaml has double quotes instead?


Solution

  • Since I had hundreds of kustomization files that needed to be updated with the annotations for ArgoCD sync-waves, I worked around the problem by using commonAnnotations instead (I believe this is the right way of doing it as well). So instead of adding a patch, I did the following:

    kustomize edit add annotation argocd.argoproj.io/sync-wave:$wave --force
    

    This will add the annotation to all objects. Where $wave was the wave number and --force overwrites the annotation if it already exists in the file.