Q: 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?

A: 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.

A: In my case annotations were not an option, so I had to provide the patch definition serialized as an array of ops:
kustomize edit add patch --patch '[{"op": "replace", "path": "/spec/template/spec/containers/0/ports/0/containerPort", "value": 8080}]' --kind Deployment

