使用字符串文字定制补丁:双引号替换为单引号
将 kustomize 补丁添加到 kustomization.yaml 时,双引号会替换为单引号,这会导致错误
我正在使用以下内容:
kustomize edit add patch --patch "- op: add\n path: /metadata/annotations/argocd.argoproj.io~1sync-wave\n. value: 1" --kind Deployment
转换为
- patch: '- op: add\n path: /metadata/annotations/argocd.argoproj.io~1sync-wave\n value: 1'
target:
kind: Deployment
在 kustomization.yaml 中
当您执行 kustomize build
时,这会导致以下错误:
Error: trouble configuring builtin PatchTransformer with config: `
patch: ‘- op: add\n path: /metadata/annotations/argocd.argoproj.io~1sync-wave\n value:
1’
target:
kind: Deployment
`: unable to parse SM or JSON patch from [- op: add\n path: /metadata/annotations/argocd.argoproj.io~1sync-wave\n value: 1]
如何确保 kustomization.yaml
中的补丁有双引号?
When adding a kustomize patch to a kustomization.yaml
the double quotes are replaced with single quotes that lead to error
I am using the following:
kustomize edit add patch --patch "- op: add\n path: /metadata/annotations/argocd.argoproj.io~1sync-wave\n. value: 1" --kind Deployment
is converted to
- patch: '- op: add\n path: /metadata/annotations/argocd.argoproj.io~1sync-wave\n value: 1'
target:
kind: Deployment
in the kustomization.yaml
This leads to the following error when you do kustomize build
Error: trouble configuring builtin PatchTransformer with config: `
patch: ‘- op: add\n path: /metadata/annotations/argocd.argoproj.io~1sync-wave\n value:
1’
target:
kind: Deployment
`: unable to parse SM or JSON patch from [- op: add\n path: /metadata/annotations/argocd.argoproj.io~1sync-wave\n value: 1]
How do I make sure that the patch in kustomization.yaml
has double quotes instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于我有数百个 kustomization 文件需要使用 ArgoCD 同步波的注释进行更新,因此我通过使用
commonAnnotations
来解决这个问题(我相信这也是正确的方法) )。因此,我没有添加补丁,而是执行了以下操作:这会将注释添加到所有对象。其中
$wave
是波数,--force
会覆盖注释(如果文件中已存在)。Since I had hundreds of kustomization files that needed to be updated with the annotations for ArgoCD sync-waves, I worked around the problem by using
commonAnnotations
instead (I believe this is the right way of doing it as well). So instead of adding a patch, I did the following:This will add the annotation to all objects. Where
$wave
was the wave number and--force
overwrites the annotation if it already exists in the file.就我而言,注释不是一个选项,因此我必须提供序列化为操作数组的补丁定义:
In my case annotations were not an option, so I had to provide the patch definition serialized as an array of ops: