kustomize: Json Patch fails on v3.0.0

kustomize version
Version: {KustomizeVersion:3.0.0 GitCommit:e0bac6ad192f33d993f11206e24f6cda1d04c4ec BuildDate:2019-07-03T18:21:24Z GoOs:linux GoArch:amd64}

Observed that a jsonPatch that works for bundled kustomize 2.0.3 and 2.1.0 fails to build with 3.0.0. The error returned is

Error: no matches for OriginalId extensions_v1beta1_Deployment|~X|external-dns; no matches for CurrentId extensions_v1beta1_Deployment|~X|external-dns; failed to find unique target for patch extensions_v1beta1_Deployment|external-dns

My deployment base contains:

---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: external-dns
  namespace: kube-system
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: external-dns
      annotations:
        iam.amazonaws.com/role: changeme
    spec:
      serviceAccountName: external-dns
      containers:
      - name: external-dns
        image: registry.opensource.zalan.do/teapot/external-dns:latest
        args:
        - --source=service
        - --source=ingress

My overlay kustomization

resources:
- ../base

patchesJson6902:
- target:
    group: extensions
    version: v1beta1
    kind: Deployment
    name: external-dns
  path: deployment-patch.yaml

My jsonPatch

- op: replace
  path: /spec/template/metadata/annotations/iam.amazonaws.com~1role
  value: arn:aws:iam::123456:role/ExternalDNS

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Try

patchesJson6902:
- target:
    group: extensions
    version: v1beta1
    kind: Deployment
    name: external-dns
+   namespace: kube-system
  path: deployment-patch.yaml

That’s funny because with kustomize v2.1.0, if you specify the namespace on the patch, and the namespace isn’t specified in the resource but only in the kustomization.yml (or if you specify a namespace in the resource that is not the same as the one in the kustomization.yml, like a place holder for instance), then you get an error

Error: couldn't find target apps_v1_Deployment|resourceFoo|namespaceBar for json patch

With kustomize v3.0.0 :

  • if you don’t have a namespace in the resource, but only in the kustomization.yml, you don’t have to specify the namespace in the patch
  • if you have a namespace in the resource (the final one or a placehoder), and the final one in the kustomization.yml, you have to specify the namespace in the patch or you get error :
Error: no matches for OriginalId apps_v1_Deployment|~X|resourceFoo; no matches for CurrentId apps_v1_Deployment|~X|resourceFoo; failed to find unique target for patch apps_v1_Deployment|resourceFoo

I didn’t see anything related to that change in the patch behaviour regarding namespaces in the changelog (but I may have missed it)

ok so turns out that

  • patch ADD does NOT add resources
  • You HAVE to add placeholders in the base resources
imagePullSecrets: []
volumes: []
...

this … could be a bit clearer

Oops I figured it out. The correct namespace is kubeflow, as specified in the base - now I’m on to the next bug 😃

I’m getting the same bug trying to follow through the MNIST example in the end-to-end Kubeflow Guide. How would I change that file? Simply adding “namespace: kube-system” didn’t do it 😦