Closed rob8714 closed 3 years ago
That is how json patch works. To add label please use LabelTransformer
This assumes that I want to add the label to all the resources... I want to add the label to just one resource so using the commonLabel is not really an option, what I provided in the above was a simple example. It also assumes that the base layer needs to cater for possibilities that may be added in the overlays.
I will work around by adding label: {}, but it would be great if the documentation could be updated to clarify on this behavior since, in my opinion, this is not clear.
If you want to use json patch, I assume you have clear understanding of it. Please take a look at the specification of add
operation: https://tools.ietf.org/html/rfc6902#section-4.1.
Thanks for clarifying, I wasn't looking at the RFC but now I read through the section and understand :)
For folks that find this bug and are looking for a quick solution, something like:
patches:
- target:
kind: ConfigMap
name: example
patch: |-
- op: add
path: /metadata/labels
value: {"example": "value"}
One gotcha with the quick solution above, it replaces the labels. If instead you do want to add a label and you're wondering why kustomize is gas-lighting you with op: add
replacing instead of adding , then try this:
patches:
- target:
kind: Deployment
name: httpbin
patch: |-
- op: add
path: "/spec/template/metadata/labels/sidecar.istio.io~1inject"
value: "true"
Hi
Came across a problem adding a label with the following files:
service.yml
kustomization.yaml
Running kustomize build . gives an error:
Error: add operation does not apply: doc is missing path: "/metadata/labels/testLabel": missing value
Expected output
Actual output
Error: add operation does not apply: doc is missing path: "/metadata/labels/testLabel": missing value
Kustomize version
v3.8.9
Platform
macOS
Additional context
Adding
labels: {}
in service.yml solves the problem, however understanding is that this should not fail especially since we are adding adding objects.