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

patches not working like patchesStrategicMerge when deleting manifests #5373

Open
mtrin opened this issue Oct 10, 2023 · 4 comments
Open

patches not working like patchesStrategicMerge when deleting manifests #5373

mtrin opened this issue Oct 10, 2023 · 4 comments
Labels
kind/bug Categorizes issue or PR as related to a bug. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.

Comments

@mtrin
Copy link

mtrin commented Oct 10, 2023

What happened?

patches:
  - |-
    kind: ConfigMap
    apiVersion: v1
    metadata:
      name: foo
      namespace: bar
    $patch: delete

Gives

Error: invalid Kustomization: json: cannot unmarshal string into Go struct field Kustomization.patches of type types.Patch

patchesStrategicMerge:
  - |-
    kind: ConfigMap
    apiVersion: v1
    metadata:
      name: foo
      namespace: bar
    $patch: delete

it works with the warning

Warning: 'patchesStrategicMerge' is deprecated. Please use 'patches' instead. Run 'kustomize edit fix' to update your Kustomization automatically

What did you expect to happen?

patches to behave like patchesStrategicMerge

How can we reproduce it (as minimally and precisely as possible)?

as above

Expected output

No response

Actual output

No response

Kustomize version

v5.1.1

Operating system

Linux

@mtrin mtrin added the kind/bug Categorizes issue or PR as related to a bug. label Oct 10, 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 Oct 10, 2023
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

SIG CLI takes a lead on issue triage for this repo, but any Kubernetes member can accept issues by applying the triage/accepted label.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@craiggunson
Copy link

also have this issue where patches: does not action $delete the same way patchesStrategicMerge did, meaning even if I split everytihng into different yaml, it's rather busted.

@duritong
Copy link

Well the issue is as followed.

given the following structure:

$ cat resources.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: example-config-1
data:
  # example of a simple property defined using --from-literal
  example.property.1: hello
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: example-config-2
data:
  # example of a simple property defined using --from-literal
  example.property.2: world
$ cat kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- resources.yaml

patches:
- |-
  $patch: delete
  kind: ConfigMap
  apiVersion: v1
  metadata:
    name: example-config-2

We get the following error:

$ ../kustomize build .
Error: invalid Kustomization: json: cannot unmarshal string into Go struct field Kustomization.patches of type types.Patch

Even with the latest kustomize version (5.4.0).

If we changes this to a patchesStrategicMerge, then it works, but we get a warning:

 ../kustomize build .
# Warning: 'patchesStrategicMerge' is deprecated. Please use 'patches' instead. Run 'kustomize edit fix' to update your Kustomization automatically.
apiVersion: v1
data:
  example.property.1: hello
kind: ConfigMap
metadata:
  name: example-config-1

If we do what the warning recommends, we get an actually working version:

$ cp kustomization.yaml kustomization.yaml.old
$ ../kustomize edit fix
# Warning: 'patchesStrategicMerge' is deprecated. Please use 'patches' instead. Run 'kustomize edit fix' to update your Kustomization automatically.

Fixed fields:
  patchesJson6902 -> patches
  patchesStrategicMerge -> patches
  commonLabels -> labels

To convert vars -> replacements, run the command `kustomize edit fix --vars`

WARNING: Converting vars to replacements will potentially overwrite many resource files
and the resulting files may not produce the same output when `kustomize build` is run.
We recommend doing this in a clean git repository where the change is easy to undo.

$ ../kustomize build .
apiVersion: v1
data:
  example.property.1: hello
kind: ConfigMap
metadata:
  name: example-config-1


$ diff -Naur kustomization.yaml.old kustomization.yaml
--- kustomization.yaml.old	2024-02-27 21:46:14.268610306 +0100
+++ kustomization.yaml	2024-02-27 21:46:24.702542924 +0100
@@ -4,10 +4,10 @@
 resources:
 - resources.yaml

-patchesStrategicMerge:
-- |-
-  $patch: delete
-  kind: ConfigMap
-  apiVersion: v1
-  metadata:
-    name: example-config-2
+patches:
+- patch: |-
+    $patch: delete
+    kind: ConfigMap
+    apiVersion: v1
+    metadata:
+      name: example-config-2

Now what is the trick? patches: needs each patch to start with patch: and not directly the patch as a structure.

So I think this works as intended.

@k8s-triage-robot
Copy link

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

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 27, 2024
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. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.
Projects
None yet
Development

No branches or pull requests

5 participants