Kustomize 在 helmreleases 上使用战略合并补丁

发布于 2025-01-14 17:05:51 字数 1371 浏览 2 评论 0原文

我们将 HelmReleases 保存在 Flux 存储库中。我们使用 Kustomize 编辑 HelmReleases 中的一些键。我尝试使用战略合并补丁将一个值附加到列表中,但列表被覆盖(这似乎是默认值..)

有没有办法使用 战略合并补丁 HelmReleases 的方式允许我将值附加到列表(补丁 - 合并)?

我的 base.yaml 是:

apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: MyReleaseX
spec:
  releaseName: serviceXRelease
  chart:
    spec:
      chart: serviceXchart
      sourceRef:
        kind: HelmRepository
        name: my-repo
      valuesFiles:
        - values.yaml
  values:
     env:
        - name: ACCOUNT
          value: "x5" 

覆盖目录下的我的 kustomization 文件:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - ../base/serviceX
patchesStrategicMerge:
  - serviceX.yaml

我想在覆盖中添加另一个环境变量(我不想覆盖它现有的环境)。

当我在overlay/ServiceX.yaml中尝试以下操作时,列表被覆盖,并且我只有一个值:

apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: serviceXRelease
spec:

  values:
     env:
       - name: NEW_ENV
         value: "val"

是我唯一的选择,使用json补丁而不是像建议的战略合并补丁这里(只需使用合并而不是替换)?

We keep in our Flux repo our HelmReleases. We use Kustomize to edit some of the keys in the HelmReleases. I tried using Strategic Merge patch in order to append a value into a list but instead the list was overwritten (which is the default it seems..)

Is there a way to use Strategic Merge Patch on HelmReleases in a way that will allow me to append values to a list (patch - merge) ?

My base.yaml is :

apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: MyReleaseX
spec:
  releaseName: serviceXRelease
  chart:
    spec:
      chart: serviceXchart
      sourceRef:
        kind: HelmRepository
        name: my-repo
      valuesFiles:
        - values.yaml
  values:
     env:
        - name: ACCOUNT
          value: "x5" 

My kustomization file under overlay dir:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - ../base/serviceX
patchesStrategicMerge:
  - serviceX.yaml

I want to add in my overlay another env variable (I don't want to overwrite it the existing env).

When I tried the following in my overlay/ServiceX.yaml the list was overwritten and I had only one value:

apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: serviceXRelease
spec:

  values:
     env:
       - name: NEW_ENV
         value: "val"

Is my only option using json patches instead of Strategic Merge patch like suggested here (just use merge instead of replace) ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

韶华倾负 2025-01-21 17:05:51

就我个人而言,我更喜欢@The Fool建议的解决方案。但是,就我而言,该解决方案不起作用,可能与 Kustomize 的版本或我使用的 apiVersion (v4.4.1) 有关。

以下是我使用的解决方案(json 补丁):

我的 base/servicex.yaml 与我发布的保持相同。

自定义文件

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - ../base/serviceX # 

patches:
  - path: patch-env.yaml
    target:
      group: helm.toolkit.fluxcd.io
      version: v2beta1
      kind: HelmRelease
      name: MyReleaseX

补丁文件:

- op: add
  path: "/spec/values/env/0"
  value:
    name: NEW_ENV
    value: VAL

Personally, I prefer the solution @The Fool suggested. However, in my case that solution didn't work, might be related to Kustomize's version or the apiVersion I used (v4.4.1).

The following is the solution I used (json patches) :

My base/servicex.yaml is kept the same as i posted.

The kustomization file

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - ../base/serviceX # 

patches:
  - path: patch-env.yaml
    target:
      group: helm.toolkit.fluxcd.io
      version: v2beta1
      kind: HelmRelease
      name: MyReleaseX

The patch file :

- op: add
  path: "/spec/values/env/0"
  value:
    name: NEW_ENV
    value: VAL
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文