kubernetes go client patch example -
after searching i'm unable find golang kube client example performs @ patch using strategy...i'm looking golang example of doing this:
kubectl patch pod valid-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]'
i'm using https://github.com/kubernetes/client-go v2.0.0
can point me example? thanks.
so, think have example working after digging thru kubectl resource helper.go code, here is:
first, create structure this:
type thingspec struct { op string `json:"op"` path string `json:"path"` value string `json:"value"` }
then create array of those:
things := make([]thingspec, 1) things[0].op = "replace" things[0].path = "/spec/ccpimagetag" things[0].value = "newijeff"
then convert array bytes array holding json version of data structure:
patchbytes, err4 := json.marshal(things)
lastly, make api call perform type of patch:
result, err6 := tprclient.patch(api.jsonpatchtype). namespace(api.namespacedefault). resource("pgupgrades"). name("junk"). body(patchbytes). do(). get()
this equivalent kubectl command:
kubectl patch pgupgrades junk --type='json' -p='[{"op":"replace", "path":"/spec/ccpimagetag","value":"newimage"}]'
Comments
Post a Comment