经过一番搜索后,我无法找到使用任何策略在 Patch 上执行的 golang Kube 客户端示例...我正在寻找执行此操作的 golang 示例:
kubectl patch pod valid-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]'
我在用着https://github.com/kubernetes/client-go https://github.com/kubernetes/client-go v2.0.0
谁能给我举个例子吗?谢谢。
所以,我认为在挖掘 kubectl 资源 helper.go 代码后我有一个可以工作的示例,如下所示:
首先,创建一个像这样的结构:
type ThingSpec struct {
Op string `json:"op"`
Path string `json:"path"`
Value string `json:"value"`
}
然后创建一个数组:
things := make([]ThingSpec, 1)
things[0].Op = "replace"
things[0].Path = "/spec/ccpimagetag"
things[0].Value = "newijeff"
然后将数组转换为保存 JSON 版本的字节数组
数据结构:
patchBytes, err4 := json.Marshal(things)
最后,调用此 API 来执行此类补丁:
result, err6 := tprclient.Patch(api.JSONPatchType).
Namespace(api.NamespaceDefault).
Resource("pgupgrades").
Name("junk").
Body(patchBytes).
Do().
Get()
这大致相当于这个 kubectl 命令:
kubectl patch pgupgrades junk --type='json' -p='[{"op":"replace", "path":"/spec/ccpimagetag","value":"newimage"}]'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)