It could be done the following way:
persVolC := client.CoreV1().PersistentVolumeClaims("default")
data := `
[
{ "op": "add", "path": "/metadata/labels/mylabel", "value": "myvalue" }
]
`
updatedPvc, err := persVolC.Patch(ctx, "name-of-pvc", types.JSONPatchType, []byte(data), meta_v1.PatchOptions{})
if err != nil {
log.Fatal(err)
}
Full example at go playground.
And here you can read about JSON patch standard.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…