kustomize
kustomize copied to clipboard
unexpected error using `$patch: delete`
What happened?
I see the following error I attempt to build my configuration using kustomize build .
:
Error: wrong node kind: expected ScalarNode but got MappingNode: node contents:
$patch: delete
Essentially I am trying to apply two patches to a CRD resource. The first patch sets adds the preserveUnknownFields field to the spec, setting to false, and the second patch removes the creationTimestamp field.
The interesting part is if I reverse the order of the patches in the kustomization.yaml file, the error no longer occurs and I the results I expect.
What did you expect to happen?
No error occurs and I see the resulting yaml.
How can we reproduce it (as minimally and precisely as possible)?
This can be reproduced with the resources created by this script and executing kustomize build .
within the newly created kustomize-test directory.
mkdir kustomize-test
cat <<EOF> kustomize-test/kustomization.yaml
resources:
- crd.yaml
patches:
- path: set-preserve-fields.yaml
- path: remove-creation-timestamp.yaml
EOF
cat <<EOF> kustomize-test/skip-suffix.yaml
nameSuffix:
- path: metadata/name
apiVersion: apps/v1
kind: Deployment
EOF
cat <<EOF> kustomize-test/crd.yaml
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
creationTimestamp: null
name: mycrd.domain.dev
spec:
group: my-group.com
names:
kind: MyCRD
listKind: MyCRDList
plural: mycrds
singular: mycrd
scope: Namespaced
EOF
cat <<EOF> kustomize-test/remove-creation-timestamp.yaml
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: mycrd.domain.dev
creationTimestamp:
\$patch: delete
EOF
cat <<EOF> kustomize-test/set-preserve-fields.yaml
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: mycrd.domain.dev
spec:
preserveUnknownFields: false
EOF
Note with the patches order reversed in the kustomization.yaml file, I am able to get the expected results.
Expected output
> kustomize build .
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: mycrd.domain.dev
spec:
group: my-group.com
names:
kind: MyCRD
listKind: MyCRDList
plural: mycrds
singular: mycrd
preserveUnknownFields: false
scope: Namespaced
Actual output
> kustomize build .
Error: wrong node kind: expected ScalarNode but got MappingNode: node contents:
$patch: delete
Kustomize version
v5.0.1
Operating system
MacOS
I was able to reproduce this bug.
/triage accepted /priority backlog
This issue has not been updated in over 1 year, and should be re-triaged.
You can:
- Confirm that this issue is still relevant with
/triage accepted
(org members only) - Close this issue with
/close
For more details on the triage process, see https://www.kubernetes.dev/docs/guide/issue-triage/
/remove-triage accepted
Reproduced as well, Kustomize doesn't seem to be able to delete scalar nodes (fields) with a strategic merge patch.
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
- After 90d of inactivity,
lifecycle/stale
is applied - After 30d of inactivity since
lifecycle/stale
was applied,lifecycle/rotten
is applied - After 30d of inactivity since
lifecycle/rotten
was applied, the issue is closed
You can:
- Mark this issue as fresh with
/remove-lifecycle stale
- Close this issue with
/close
- Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale