Kustomize 在 helmreleases 上使用战略合并补丁
我们将 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就我个人而言,我更喜欢@The Fool建议的解决方案。但是,就我而言,该解决方案不起作用,可能与 Kustomize 的版本或我使用的 apiVersion (v4.4.1) 有关。
以下是我使用的解决方案(json 补丁):
我的
base/servicex.yaml
与我发布的保持相同。自定义文件
补丁文件:
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
The patch file :