如何替换xxx
为yyy
?
{
"spec": {
"template": {
"spec": {
"containers": [{
"args": [
"proxy",
"router",
"--domain",
"$(POD_NAMESPACE).svc.cluster.local",
"--proxyLogLevel=warning",
"--proxyComponentLogLevel=misc:error",
"--log_output_level=default:info",
"--serviceCluster",
"istio-ingressgateway"
],
"env": [{
"name": "JWT_POLICY",
"value": "third-party-jwt"
},
{
"name": "ISTIO_META_OWNER",
"value": "kubernetes://apis/apps/v1/namespaces/istio-system/deployments/xxx"
}
]
}]
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
以下是您可以使用以下方法专门更改.spec.template.spec.containers[].env[].value
ISTIO_META_OWNER 的方法:|= sub()
下面是替换的应用方式:
jq -r '.spec.template.spec.containers[].env[] | (select(.name=="ISTIO_META_OWNER") |.value |= sub("xxx$"; "yyy"))' kubernetes_spec_example.json
Run Code Online (Sandbox Code Playgroud)
结果如下:
{
"name": "ISTIO_META_OWNER",
"value": "kubernetes://apis/apps/v1/namespaces/istio-system/deployments/yyy"
}
Run Code Online (Sandbox Code Playgroud)