使用字符串文字定制补丁:双引号替换为单引号

发布于 2025-01-10 12:21:52 字数 952 浏览 0 评论 0原文

将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一直在等你来 2025-01-17 12:21:52

由于我有数百个 kustomization 文件需要使用 ArgoCD 同步波的注释进行更新,因此我通过使用 commonAnnotations 来解决这个问题(我相信这也是正确的方法) )。因此,我没有添加补丁,而是执行了以下操作:

kustomize edit add annotation argocd.argoproj.io/sync-wave:$wave --force

这会将注释添加到所有对象。其中 $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:

kustomize edit add annotation argocd.argoproj.io/sync-wave:$wave --force

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.

赠佳期 2025-01-17 12:21:52

就我而言,注释不是一个选项,因此我必须提供序列化为操作数组的补丁定义:

kustomize edit add patch --patch '[{"op": "replace", "path": "/spec/template/spec/containers/0/ports/0/containerPort", "value": 8080}]' --kind Deployment

In my case annotations were not an option, so I had to provide the patch definition serialized as an array of ops:

kustomize edit add patch --patch '[{"op": "replace", "path": "/spec/template/spec/containers/0/ports/0/containerPort", "value": 8080}]' --kind Deployment
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文