<p>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..)</p>
<p>Is there a way to use <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/strategic-merge-patch.md" rel="nofollow noreferrer">Strategic Merge Patch</a> on HelmReleases in a way that will allow me to append values to a list (patch - merge) ?</p>
<p>My base.yaml is :</p>
<pre><code>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: &quot;x5&quot; 
</code></pre>
<p>My kustomization file under overlay dir:</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - ../base/serviceX
patchesStrategicMerge:
  - serviceX.yaml
</code></pre>
<p>I want to add in my overlay another env variable (I don't want to overwrite it the existing env).</p>
<p>When I tried the following in my overlay/ServiceX.yaml the list was overwritten and I had only one value:</p>
<pre><code>apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: serviceXRelease
spec:

  values:
     env:
       - name: NEW_ENV
         value: &quot;val&quot;
</code></pre>
<p>Is my only option using json patches instead of Strategic Merge patch like suggested <a href="https://stackoverflow.com/questions/67917460/patching-list-in-kubernetes-manifest-with-kustomize">here</a> (just use merge instead of replace) ?</p>

JeyJ
<p>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).</p>
<p>The following is the solution I used (json patches) :</p>
<p>My <code>base/servicex.yaml</code> is kept the same as i posted.</p>
<p>The kustomization file</p>
<pre><code>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
</code></pre>
<p>The patch file :</p>
<pre><code>- op: add
  path: &quot;/spec/values/env/0&quot;
  value:
    name: NEW_ENV
    value: VAL
</code></pre>
