kustomize: Kustomize fails to find object in base modified with nameSuffix

Consider the following directory structure:

.
├── aggregate                // contains guestbook-a and guestbook-b as bases.
│   ├── kustomization.yaml   // also applies a patch on guestbook-a
│   └── patch-a.yaml
├── guestbook-a              // contains template as base with nameSuffix: -a
│   └── kustomization.yaml
├── guestbook-b              // contains template as base with nameSuffix: -b
│   └── kustomization.yaml
└── template                 // single resource
    ├── guestbook.yaml
    └── kustomization.yaml

When attempting to build the aggregate, it fails with error:

$ kustomize build aggregate
Error: failed to find an object with ~G_v1_Pod|guestbook-a to apply the patch
  • aggregate/kustomization.yaml
bases:
- ../guestbook-a
- ../guestbook-b
patchesStrategicMerge:
- patch-a.yaml
  • aggregate/patch-a.yaml
apiVersion: v1
kind: Pod
metadata:
  name: guestbook-a
spec:
  containers:
  - name: nginx
    env:
    - name: FOO
      value: bar
  • guestbook-a/kustomization.yaml
bases:
- ../template
nameSuffix: -a
  • template/kustomization.yaml
resources:
- guestbook.yaml

I made this available here: https://github.com/jessesuen/k8s-deployments/tree/master/kustomize-suffix-failed-find-obj

I expect patching to work on objects in the base, even after name transformation using namePrefix or nameSuffix. However, it does not find the object transformed with nameSuffix. Interestingly, if I modify patch-a.yaml to reference the name of the resource without the suffix, it gets the following error:

$ kustomize build aggregate
Error: found multiple objects []resid.ResId{resid.ResId{gvKind:gvk.Gvk{Group:"", Version:"v1", Kind:"Pod"}, name:"guestbook", prefix:"", suffix:"-b", namespace:""}, resid.ResId{gvKind:gvk.Gvk{Group:"", Version:"v1", Kind:"Pod"}, name:"guestbook", prefix:"", suffix:"-a", namespace:""}} targeted by patch resid.ResId{gvKind:gvk.Gvk{Group:"", Version:"v1", Kind:"Pod"}, name:"guestbook", prefix:"", suffix:"", namespace:""} (ambiguous)

This is reproducible with both v2.0.3 and tip of master from today (f9c631e9).

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 18 (7 by maintainers)

Most upvoted comments

This makes kustomize unsuitable for my use case - reusing base layers to describe similar app configuration. Is it possible to put a notice on kubectl docs about this issue?

I’d rather avoid a two-pass build. I like the approach of matching to both base name and to name prefix/suffix. Is this something that is on the roadmap?

Calling this fixed by #1183, which is in v2.1.0.

Added a test to cover in #1278

How this should work exactly is open for debate, but the behavior is

  • a patch is defined, and must have a unique target (NsGVKN).
  • try to find an exact match by the original name, e.g. ConfigMap/foo (frees user from having to do a mental kustomization of the base)
  • failing that, try to find by the anticipated final name, e.g. ConfigMap/prefix-foo

a feature allowing a patch to have multiple targets is coming soon.