Solved: Kustomize Unable to Parse SM or JSON Patch


Recently I noticed that my ArgoCD manifests I used to patch using kustomize don’t work with latest version of kustomize anymore. The error I got looks like:

kustomize build argocd
Error: trouble configuring builtin PatchTransformer with config: `
path: patch.yaml
`: unable to parse SM or JSON patch from [---
apiVersion: apps/v1
kind: Deployment
...

# version check
kustomize version
{Version:kustomize/v4.4.0 ...}

My patch.yaml had something like this:

---
apiVersion: apps/v1
kind: Deployment
...

---
apiVersion: v1
kind: ConfigMap
...

---
apiVersion: v1
kind: ConfigMap

There’s no syntax error in my files as this worked before. I tried to remove sections from the patch file and see if this changes anything. There were 3 resources in the patch file, and after I removed 2 of them the kustomize build command became working again – doesn’t matter which one is left.

So it’s kinda clear that for some reason there should only be 1 resource per patch file. Easy fix! I split my patch file into 3 seperate files and referred to them in the kustomization.yaml like this:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
...

patches:
  - path: patch-deploy.yaml
  - path: patch-cm.yaml
  - path: patch-cm2.yaml

It worked again.

This thread probably is relevant: https://github.com/kubernetes-sigs/kustomize/issues/5049

🙂

,