Kustomize: Merging generator fails when namespace of base and overlay differ

Created on 20 Jun 2019  路  11Comments  路  Source: kubernetes-sigs/kustomize

How to reproduce:

  • Kustomize v2.1.0 (works in v2.0.3).
  • base/kustomization.yaml:
namespace: default

configMapGenerator:
- name: testCase
  literals:
    - base=true
  • overlay/kustomization.yaml:
resources:
- ../base

namespace: test

configMapGenerator:
- name: testCase
  behavior: merge
  literals:
    - overlay=true
./kustomize build overlay
Error: merging from generator &{0xc00011c000 0xc0000a06f8 {map[] map[] false} {{ testCase merge {[overlay=true] [] [] }}}}: cannot find resource with id ~G_v1_ConfigMap|~X|testCase to replace

Removing namespace: default from base resolves the issue.

kinbug

Most helpful comment

I'm still getting this problem in v3.2.1 when the base config map has no namespace and the overlay tries to add one.
base ConfigMap (from https://github.com/argoproj/argo-cd/blob/master/manifests/base/config/argocd-cm.yaml):

apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-cm
  labels:
    app.kubernetes.io/name: argocd-cm
    app.kubernetes.io/part-of: argocd

Kustomize version:

位 kustomize version
Version: {Version:3.2.1 GitCommit:d89b448c745937f0cf1936162f26a5aac688f840 BuildDate:2019-10-03T19:25:14+01:00 GoOs:darwin GoArch:amd64}

Overlay:

apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-cm
  namespace: argocd  
  labels:
    app.kubernetes.io/name: argocd-cm
    app.kubernetes.io/part-of: argocd

When I run kustomize build:

Error: no matches for OriginalId ~G_v1_ConfigMap|argocd|argocd-cm; no matches for CurrentId ~G_v1_ConfigMap|argocd|argocd-cm; failed to find unique target for patch ~G_v1_ConfigMap|argocd-cm

Removing the namespace from my overlay fixes the issue

All 11 comments

This should be fixed by #1221

@Liujingfang1 #1221 looks included in v2.1.0, but @ptemmer tells he faces this problem with v2.1.0.
I think it's not fixed now. I'm also suffered from the same problem of v2.1.0 (tried v3.0.0 too, but still doesn't work).
Please rethink about this issue.

v3.0.0 still doesn't solve this issue.

getting same issue with v3.0.0. For my case, it doesn't matter what namespace the overlay is using, it will work only when base is using default namespace.

Same, v3.0.0 still doesn't resolve the issue

If I manually add the same namespace field to both base configmap and the overlay it works:

# Base
namespace: mynamespace
configMapGenerator:
- name: my-config
  # added
  namespace: mynamespace
  literals:
    ...  

# Overlay
namespace: mynamespace
configMapGenerator:
- name: my-config
  # added
  namespace: mynamespace
  behavior: merge
  literals:
    ...

In 2.0.3 the nested namespace wasn't required.

@anarcher @xyhuang @capyvara I tried this test case with 3.0.0 and it worked. Can you create your field tests?

Installed from brew: Version: {KustomizeVersion:3.0.0 GitCommit:e0bac6ad192f33d993f11206e24f6cda1d04c4ec BuildDate:2019-07-05T06:00:59+01:00 GoOs:darwin GoArch:amd64}

To repro:

base/kustomization.yaml

namespace: mynamespace
configMapGenerator:
- name: my-config
  literals:
    - base=true

overlay/kustomization.yaml

namespace: mynamespace
resources:
  - ../base
configMapGenerator:
- name: my-config
  behavior: merge
  literals:
    - overlay=true
kustomize build overlay
Error: merging from generator &{0xc0000aa660 0xc000130238 { } {map[] map[] false} {{ my-config merge {[overlay=true] [] [] }}}}: cannot find resource with id ~G_v1_ConfigMap|~X|my-config to replace

However if I remove the behavior field:

kustomize build overlay
Error: merging from generator &{0xc0000c8840 0xc000010188 { } {map[] map[] false} {{ my-config  {[overlay=true] [] [] }}}}: id resid.ResId{Gvk:gvk.Gvk{Group:"", Version:"v1", Kind:"ConfigMap"}, Name:"my-config", Namespace:""} exists; must merge or replace

So it somehow founds only when no behavior field is present.

Adding the same namespace nested field to both generators (as my previous post) yield the right result:

kustomize build overlay
apiVersion: v1
data:
  base: "true"
  overlay: "true"
kind: ConfigMap
metadata:
  annotations: {}
  labels: {}
  name: my-config-k2992tmt2m
  namespace: mynamespace

@capyvara Thank you. I see where the problem is. When the namespace from the base is not default, we see this failure.

Just to add a note to this for other unfortunate souls who may spend hours debugging their patches...

I had a mismatch in the API version between my base file and my patch.

Base file:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: foo
  namespace: foospace
...

(don't ask me why that apiVersion was specified -- I inherited this YAML)

Patch file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: foo
  namespace: foospace
...

Here's the error message I got:

Error: no matches for OriginalId apps_v1_Deployment|foospace|foo; no matches for CurrentId apps_v1_Deployment|foospace|foo; failed to find unique target for patch apps_v1_Deployment|foo

Two major problems with this error message:

  • it doesn't show the namespace in the last part of the message; this led me to think that perhaps I was not specifying the namespace correctly
  • it doesn't show "extensions_v1beta1" in any of the IDs

The second is the worse of the two problems, IMHO. As it stands, the message is completely confusing. It looks like the OriginalId and CurrentId are the same, so why do they both say "no matches"?

If it had displayed "extensions_v1beta1" for the OriginalID, I would have immediately seen why there was no match.

I'm still getting this problem in v3.2.1 when the base config map has no namespace and the overlay tries to add one.
base ConfigMap (from https://github.com/argoproj/argo-cd/blob/master/manifests/base/config/argocd-cm.yaml):

apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-cm
  labels:
    app.kubernetes.io/name: argocd-cm
    app.kubernetes.io/part-of: argocd

Kustomize version:

位 kustomize version
Version: {Version:3.2.1 GitCommit:d89b448c745937f0cf1936162f26a5aac688f840 BuildDate:2019-10-03T19:25:14+01:00 GoOs:darwin GoArch:amd64}

Overlay:

apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-cm
  namespace: argocd  
  labels:
    app.kubernetes.io/name: argocd-cm
    app.kubernetes.io/part-of: argocd

When I run kustomize build:

Error: no matches for OriginalId ~G_v1_ConfigMap|argocd|argocd-cm; no matches for CurrentId ~G_v1_ConfigMap|argocd|argocd-cm; failed to find unique target for patch ~G_v1_ConfigMap|argocd-cm

Removing the namespace from my overlay fixes the issue

Was this page helpful?
0 / 5 - 0 ratings