kubernetes / client-go

Go client for Kubernetes.
Apache License 2.0
8.79k stars 2.91k forks source link

Annotate PVC with string instead of map #1225

Closed aleksrosz closed 1 year ago

aleksrosz commented 1 year ago

Hi I want to annotate PVC with a string instead of a map.

This function: stringTest := "{\"application\": \"foo\", \"namespace\": \"bar\"}" pvcs.Items[0].ObjectMeta.Annotations["foo/tags"] = stringTest

_, err = clientset.CoreV1().PersistentVolumeClaims(namespace).Update(context.Background(), &pvcs.Items[0], metav1.UpdateOptions{})

Adds annotation to PVC like that: annotations: foo/tags: '{"application": "foo", "namespace": "bar"}'

It is interpreted by Kubernetes as a map. I need to add it as a string which requires that it will look like that: annotations: foo/tags: | {"application": "foo", "namespace": "bar"}

If I add | and \n inside stringTest, it will be wrongly interpreted.

How can I achieve that?