Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unexpected error using $patch: delete #5095

Open
ChristopherFry opened this issue Mar 17, 2023 · 3 comments
Open

unexpected error using $patch: delete #5095

ChristopherFry opened this issue Mar 17, 2023 · 3 comments
Labels
kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. priority/backlog Higher priority than priority/awaiting-more-evidence.

Comments

@ChristopherFry
Copy link
Contributor

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

@ChristopherFry ChristopherFry added the kind/bug Categorizes issue or PR as related to a bug. label Mar 17, 2023
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Mar 17, 2023
@cailynse
Copy link
Contributor

I was able to reproduce this bug.

/triage accepted
/priority backlog

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Apr 11, 2023
@k8s-triage-robot
Copy link

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

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. and removed triage/accepted Indicates an issue or PR is ready to be actively worked on. labels Apr 10, 2024
@twelho
Copy link

twelho commented Jun 1, 2024

Reproduced as well, Kustomize doesn't seem to be able to delete scalar nodes (fields) with a strategic merge patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. priority/backlog Higher priority than priority/awaiting-more-evidence.
Projects
Development

No branches or pull requests

5 participants