kustomize: Regression: Resource with generateName builds with 4.1.1, fails with anything later
Describe the bug
We’d like to reproduce the “slack notification” example from https://argo-cd.readthedocs.io/en/stable/user-guide/resource_hooks/, which involves the use of generateName. In the past, we’ve handled that by defining the resource like:
metadata:
name: name-prefix-
And then patching that in our kustomization.yaml:
patches:
- patch: |
op: move
from: /metadata/name
path: /metadata/generateName
This worked fine with 4.1.1, but in anything more recent kustomize
fails.
Files that can reproduce the issue
Resource manifests
In slack-notifications.yaml:
apiVersion: batch/v1
kind: Job
metadata:
name: app-slack-notification-
annotations:
argocd.argoproj.io/hook: PostSync
argocd.argoproj.io/hook-delete-policy: HookSucceeded
spec:
template:
spec:
containers:
- name: slack-notification
image: curlimages/curl
command:
- "curl"
- "-X"
- "POST"
- "--data-urlencode"
- "payload={\"channel\": \"#somechannel\", \"username\": \"hello\", \"text\": \"App Sync succeeded\", \"icon_emoji\": \":ghost:\"}"
- "https://hooks.slack.com/services/..."
restartPolicy: Never
backoffLimit: 2
---
apiVersion: batch/v1
kind: Job
metadata:
name: app-slack-notification-fail-
annotations:
argocd.argoproj.io/hook: SyncFail
argocd.argoproj.io/hook-delete-policy: HookSucceeded
spec:
template:
spec:
containers:
- name: slack-notification
image: curlimages/curl
command:
- "curl"
- "-X"
- "POST"
- "--data-urlencode"
- "payload={\"channel\": \"#somechannel\", \"username\": \"hello\", \"text\": \"App Sync failed\", \"icon_emoji\": \":ghost:\"}"
- "https://hooks.slack.com/services/..."
restartPolicy: Never
backoffLimit: 2
Kustomization.yaml
With this kustomization.yaml, 4.1.1 works, and 4.2.0 and later fail:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- slack-notification.yaml
patches:
- target:
group: batch
version: v1
kind: Job
name: app-slack-notification-
patch: |-
- op: move
from: /metadata/name
path: /metadata/generateName
- target:
group: batch
version: v1
kind: Job
name: app-slack-notification-fail-
patch: |-
- op: move
from: /metadata/name
path: /metadata/generateName
With kustomize 4.2.0 (and 4.3.0):
$ kustomize420 build
Error: expected match for sorting: multiple matches for Current batch_v2_Job|~X|~N
With kustomize 4.4.0:
$ kustomize440 build
Error: missing metadata.name in object {{batch/v1 Job} {{ } map[] map[argocd.argoproj.io/hook:PostSync argocd.argoproj.io/hook-delete-policy:HookSucceeded internal.config.kubernetes.io/previousKinds:Job internal.config.kubernetes.io/previousNames:app-slack-notification- internal.config.kubernetes.io/previousNamespaces:default]}}
Expected output
The expected output is produced by version 4.1.1:
apiVersion: batch/v1
kind: Job
metadata:
annotations:
argocd.argoproj.io/hook: PostSync
argocd.argoproj.io/hook-delete-policy: HookSucceeded
generateName: app-slack-notification-
spec:
backoffLimit: 2
template:
spec:
containers:
- command:
- curl
- -X
- POST
- --data-urlencode
- 'payload={"channel": "#somechannel", "username": "hello", "text": "App Sync
succeeded", "icon_emoji": ":ghost:"}'
- https://hooks.slack.com/services/...
image: curlimages/curl
name: slack-notification
restartPolicy: Never
---
apiVersion: batch/v1
kind: Job
metadata:
annotations:
argocd.argoproj.io/hook: SyncFail
argocd.argoproj.io/hook-delete-policy: HookSucceeded
generateName: app-slack-notification-fail-
spec:
backoffLimit: 2
template:
spec:
containers:
- command:
- curl
- -X
- POST
- --data-urlencode
- 'payload={"channel": "#somechannel", "username": "hello", "text": "App Sync
failed", "icon_emoji": ":ghost:"}'
- https://hooks.slack.com/services/...
image: curlimages/curl
name: slack-notification
restartPolicy: Never
Actual output
No output, kustomize fails with an error
Kustomize version
Tested with kustomize versions 4.1.1, 4.2.0, 4.3.0, and 4.4.0
Platform
Linux amd64
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 2
- Comments: 19 (4 by maintainers)
My solution is not to use kustomize.
We are actively discussing solutions on https://github.com/kubernetes-sigs/kustomize/issues/641. If anyone wants to propose a potential solution, please feel free to chime in there.
Any updates here? I’m facing the same problem here, and I didn’t figure out any workaround for that.
No, it is not doing the right thing. Resource without
metadata.nameare valid, as long asmetadata.generateNameis present. However such resources can only be used withkubectl createand notkubectl apply