-
Couldn't load subscription status.
- Fork 2.3k
Description
What happened?
Setting an annotation or label to null in a strategic merge patch when using target sets the value to "null" instead of removing the annotation.
Any combination of target selectors causes the issue.
This issue prevents using a single patch to target multiple resources for removal of annotations and labels.
What did you expect to happen?
Annotations and labels are removed by setting their value to null in a strategic merge patch.
Removing target and using default name reference behavior removes the annotation or label as expected.
e.g. this kustomization.yaml works.
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- sa.yaml
patches:
- patch: |
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
unwanted: null
name: sa
How can we reproduce it (as minimally and precisely as possible)?
sa.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
unwanted: "true"
name: sa
kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- sa.yaml
patches:
- patch: |
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
unwanted: null
name: sa
target:
version: v1
kind: ServiceAccount
name: sa
Expected output
unwanted label removed.
apiVersion: v1
kind: ServiceAccount
metadata:
labels: {}
name: sa
Actual output
unwanted label retained, with value set to "null"
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
unwanted: "null"
name: sa
Kustomize version
5.7.1 (in kubectl 1.34.1)
Operating system
MacOS