I have a demo golang program to list Pods without a particular label. I want to modify it so it also can add a label to each pod.
(I\'m using the AWS hosted Kubernetes s
I was trying to add a new label to a node using client-go, based on OP's code snippet, the shortest path that I used is as follow.
labelPatch := fmt.Sprintf(`[{"op":"add","path":"/metadata/labels/%s","value":"%s" }]`, labelkey, labelValue)
_, err = kc.CoreV1().Nodes().Patch(node.Name, types.JSONPatchType, []byte(labelPatch))
Note: add
to /metadata/labels
will overwrite all existing labels, so I choose the path to /metadata/labels/${LABEL_KEY}
to only add the new label