A pod needs to update its labels dynamically by making a call to the internal Kubernetes API.
In order to do so, the pod will send an authenticated PATCH request to: https://kubernetes.default.svc.cluster.local/api/v1/namespaces/<namespace>/pods/<pod>
with the following body:
[{"op": "replace", "path": "/metadata/labels/<label>", "value": "<value>"}]
According to the Kubernetes guidelines (https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set ), s should contain a DNS-like prefix followed by a slash (/) and the label name, such as example.domain.com/name=value
.
Unfortunately, when sending something similar to the aforementioned example, the Kubernetes API server will respond with an error 422 (Unprocessable Content), since the '/' in the label name is misinterpreted as resource sub-path rather than the actual label name.
Different escaping mechanisms (quoting, URL safe characters, …) don’t seem to work. How is it possible to update the label value as requested?