From eebb8c8d489ea41ce5ba388a14208c8e05cff67a Mon Sep 17 00:00:00 2001
From: Andrew Hamilton <ahamilton55@gmail.com>
Date: Sat, 9 Sep 2023 01:55:47 -0700
Subject: [PATCH] feat(argo-cd): adds toggle for helm-working-dir (#2249)

- Adds a toggle to be able to turn off the helm-working-dir for the
  repo server deployment. Using a shared helm repo storage directory can
  cause issues when multiple helm commands are being run in parallel.
  The repo server also has the ability to rebuild the repos and do
  updates in the normal flow for checking the status of an application
  so it won't cause issues if it's disabled.

Signed-off-by: Andrew Hamilton <ahamilton55@gmail.com>
---
 charts/argo-cd/Chart.yaml                                   | 4 ++--
 charts/argo-cd/README.md                                    | 1 +
 charts/argo-cd/templates/argocd-repo-server/deployment.yaml | 6 ++++++
 charts/argo-cd/values.yaml                                  | 3 +++
 4 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/charts/argo-cd/Chart.yaml b/charts/argo-cd/Chart.yaml
index 39ecaeb6..fcbd0642 100644
--- a/charts/argo-cd/Chart.yaml
+++ b/charts/argo-cd/Chart.yaml
@@ -3,7 +3,7 @@ appVersion: v2.8.3
 kubeVersion: ">=1.23.0-0"
 description: A Helm chart for Argo CD, a declarative, GitOps continuous delivery tool for Kubernetes.
 name: argo-cd
-version: 5.45.5
+version: 5.46.0
 home: https://github.com/argoproj/argo-helm
 icon: https://argo-cd.readthedocs.io/en/stable/assets/logo.png
 sources:
@@ -27,4 +27,4 @@ annotations:
     url: https://argoproj.github.io/argo-helm/pgp_keys.asc
   artifacthub.io/changes: |
     - kind: added
-      description: Documented scheduling parameters for redis-ha
+      description: added a toggle for the shared Helm working directory
diff --git a/charts/argo-cd/README.md b/charts/argo-cd/README.md
index 49abfcea..5b780b0b 100644
--- a/charts/argo-cd/README.md
+++ b/charts/argo-cd/README.md
@@ -655,6 +655,7 @@ NAME: my-release
 | repoServer.serviceAccount.name | string | `""` | Repo server service account name |
 | repoServer.tolerations | list | `[]` (defaults to global.tolerations) | [Tolerations] for use with node taints |
 | repoServer.topologySpreadConstraints | list | `[]` (defaults to global.topologySpreadConstraints) | Assign custom [TopologySpreadConstraints] rules to the repo server |
+| repoServer.useEphemeralHelmWorkingDir | bool | `true` | Toggle the usage of a ephemeral Helm working directory |
 | repoServer.volumeMounts | list | `[]` | Additional volumeMounts to the repo server main container |
 | repoServer.volumes | list | `[]` | Additional volumes to the repo server pod |
 
diff --git a/charts/argo-cd/templates/argocd-repo-server/deployment.yaml b/charts/argo-cd/templates/argocd-repo-server/deployment.yaml
index 61fb545a..3080c79f 100755
--- a/charts/argo-cd/templates/argocd-repo-server/deployment.yaml
+++ b/charts/argo-cd/templates/argocd-repo-server/deployment.yaml
@@ -231,12 +231,14 @@ spec:
                 key: reposerver.enable.git.submodule
                 name: argocd-cmd-params-cm
                 optional: true
+          {{- if .Values.repoServer.useEphemeralHelmWorkingDir }}
           - name: HELM_CACHE_HOME
             value: /helm-working-dir
           - name: HELM_CONFIG_HOME
             value: /helm-working-dir
           - name: HELM_DATA_HOME
             value: /helm-working-dir
+          {{- end }}
         {{- with .Values.repoServer.envFrom }}
         envFrom:
           {{- toYaml . | nindent 10 }}
@@ -255,8 +257,10 @@ spec:
           name: gpg-keyring
         - mountPath: /app/config/reposerver/tls
           name: argocd-repo-server-tls
+        {{- if .Values.repoServer.useEphemeralHelmWorkingDir }}
         - mountPath: /helm-working-dir
           name: helm-working-dir
+        {{- end }}
         - mountPath: /home/argocd/cmp-server/plugins
           name: plugins
         - mountPath: /tmp
@@ -349,8 +353,10 @@ spec:
       {{- with .Values.repoServer.volumes }}
         {{- toYaml . | nindent 6 }}
       {{- end }}
+      {{- if .Values.repoServer.useEphemeralHelmWorkingDir }}
       - name: helm-working-dir
         emptyDir: {}
+      {{- end }}
       - name: plugins
         emptyDir: {}
       - name: var-files
diff --git a/charts/argo-cd/values.yaml b/charts/argo-cd/values.yaml
index a9ab7ad6..22dcfcc6 100644
--- a/charts/argo-cd/values.yaml
+++ b/charts/argo-cd/values.yaml
@@ -2177,6 +2177,9 @@ repoServer:
   #  - name: cmp-tmp
   #    emptyDir: {}
 
+  # -- Toggle the usage of a ephemeral Helm working directory
+  useEphemeralHelmWorkingDir: true
+
   # -- Annotations to be added to repo server Deployment
   deploymentAnnotations: {}