jef*_*ick 3 kubernetes-go-client
经过一番搜索后,我无法找到使用任何策略在 Patch 上执行的 golang Kube 客户端示例……我正在寻找执行此操作的 golang 示例:
kubectl patch pod valid-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]'
Run Code Online (Sandbox Code Playgroud)
我正在使用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"`
}
Run Code Online (Sandbox Code Playgroud)
然后创建一个数组:
things := make([]ThingSpec, 1)
things[0].Op = "replace"
things[0].Path = "/spec/ccpimagetag"
things[0].Value = "newijeff"
Run Code Online (Sandbox Code Playgroud)
然后将数组转换为包含数据结构的 JSON 版本的字节数组:
patchBytes, err4 := json.Marshal(things)
Run Code Online (Sandbox Code Playgroud)
最后,调用这个 API 来执行这种类型的补丁:
result, err6 := tprclient.Patch(api.JSONPatchType).
Namespace(api.NamespaceDefault).
Resource("pgupgrades").
Name("junk").
Body(patchBytes).
Do().
Get()
Run Code Online (Sandbox Code Playgroud)
这大致相当于这个 kubectl 命令:
kubectl patch pgupgrades junk --type='json' -p='[{"op":"replace", "path":"/spec/ccpimagetag","value":"newimage"}]'
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4881 次 |
最近记录: |