kustomize "no matches for ... " patch target in CI
A patch, replacement, or transformer targets a resource by group/kind/name, but no resource in the built output matches that target selector. kustomize refuses to silently drop the patch and reports the unmatched id.
What this error means
kustomize build fails with "no matches for Id Deployment.v1.apps/api.default; failed to find unique target for patch" naming the patch and the target it could not match.
Error: no matches for Id Deployment.v1.apps/api.[noNs]; failed to find unique
target for patch Deployment.v1.apps/api.[noNs]Common causes
The target name or kind does not match a resource
The patch target names a resource that is not in the base, or whose name differs after a namePrefix or namespace transformer ran.
A namePrefix/suffix changed the name before the patch
A transformer renamed the resource, so the patch target selector no longer matches the transformed name.
How to fix it
Match the patch target to the real resource
- Run
kustomize buildon the base to see the actual names and kinds. - Set the patch
target:to match the resource exactly. - Account for any prefix/suffix the overlay applies before the patch.
patches:
- path: patch.yaml
target:
kind: Deployment
name: apiUse a label selector for renamed resources
Target by labelSelector instead of name so transformers that rename resources do not break the match.
patches:
- path: patch.yaml
target:
kind: Deployment
labelSelector: app=apiHow to prevent it
- Build the base first to learn exact resource names.
- Prefer labelSelector targets when prefixes or suffixes are in play.
- Keep patch targets in sync when renaming resources.