From a7035ca4e56ed5cdff3e6130a83d9c1742b29ccf Mon Sep 17 00:00:00 2001 From: developerguy Date: Thu, 3 Apr 2025 18:03:13 +0000 Subject: [PATCH] feat: make it configurable of the initContainers volume mount path for scripts (#848) ### Description of the change Makes it configurable volume mount path for initContainers for init scripts ### Benefits Configurable initContainers volumeMount path for init scripts ### Possible drawbacks I don't think that there will be any drawbacks ### Applicable issues - Fixes #847 Signed-off-by: Batuhan Apaydin Reviewed-on: https://gitea.com/gitea/helm-gitea/pulls/848 Reviewed-by: justusbunsi Co-authored-by: developerguy Co-committed-by: developerguy --- README.md | 13 ++++++------ templates/gitea/deployment.yaml | 20 +++++++++++-------- unittests/helm/deployment/basic.yaml | 20 +++++++++++++++++++ .../helm/deployment/signing-enabled.yaml | 4 ++-- values.yaml | 2 ++ 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 9b6932e..fc055fa 100644 --- a/README.md +++ b/README.md @@ -1052,12 +1052,13 @@ To comply with the Gitea helm chart definition of the digest parameter, a "custo ### Init -| Name | Description | Value | -| ------------------------------------------ | ------------------------------------------------------------------------------------ | ------- | -| `initPreScript` | Bash shell script copied verbatim to the start of the init-container. | `""` | -| `initContainers.resources.limits` | initContainers.limits Kubernetes resource limits for init containers | `{}` | -| `initContainers.resources.requests.cpu` | initContainers.requests.cpu Kubernetes cpu resource limits for init containers | `100m` | -| `initContainers.resources.requests.memory` | initContainers.requests.memory Kubernetes memory resource limits for init containers | `128Mi` | +| Name | Description | Value | +| ------------------------------------------ | ------------------------------------------------------------------------------------ | ------------ | +| `initPreScript` | Bash shell script copied verbatim to the start of the init-container. | `""` | +| `initContainersScriptsVolumeMountPath` | Path to mount the scripts consumed from the Secrets | `/usr/sbinx` | +| `initContainers.resources.limits` | initContainers.limits Kubernetes resource limits for init containers | `{}` | +| `initContainers.resources.requests.cpu` | initContainers.requests.cpu Kubernetes cpu resource limits for init containers | `100m` | +| `initContainers.resources.requests.memory` | initContainers.requests.memory Kubernetes memory resource limits for init containers | `128Mi` | ### Signing diff --git a/templates/gitea/deployment.yaml b/templates/gitea/deployment.yaml index c6b3e10..87e1bbb 100644 --- a/templates/gitea/deployment.yaml +++ b/templates/gitea/deployment.yaml @@ -62,7 +62,8 @@ spec: - name: init-directories image: "{{ include "gitea.image" . }}" imagePullPolicy: {{ .Values.image.pullPolicy }} - command: ["/usr/sbin/init_directory_structure.sh"] + command: + - "{{ .Values.initContainersScriptsVolumeMountPath }}/init_directory_structure.sh" env: - name: GITEA_APP_INI value: /data/gitea/conf/app.ini @@ -81,7 +82,7 @@ spec: {{- end }} volumeMounts: - name: init - mountPath: /usr/sbin + mountPath: {{ .Values.initContainersScriptsVolumeMountPath }} - name: temp mountPath: /tmp - name: data @@ -97,7 +98,8 @@ spec: - name: init-app-ini image: "{{ include "gitea.image" . }}" imagePullPolicy: {{ .Values.image.pullPolicy }} - command: ["/usr/sbin/config_environment.sh"] + command: + - "{{ .Values.initContainersScriptsVolumeMountPath }}/config_environment.sh" env: - name: GITEA_APP_INI value: /data/gitea/conf/app.ini @@ -119,7 +121,7 @@ spec: {{- end }} volumeMounts: - name: config - mountPath: /usr/sbin + mountPath: {{ .Values.initContainersScriptsVolumeMountPath }} - name: temp mountPath: /tmp - name: data @@ -141,7 +143,8 @@ spec: {{- if .Values.signing.enabled }} - name: configure-gpg image: "{{ include "gitea.image" . }}" - command: ["/usr/sbin/configure_gpg_environment.sh"] + command: + - "{{ .Values.initContainersScriptsVolumeMountPath }}/configure_gpg_environment.sh" imagePullPolicy: {{ .Values.image.pullPolicy }} securityContext: {{- /* By default this container runs as user 1000 unless otherwise stated */ -}} @@ -157,7 +160,7 @@ spec: value: /raw/private.asc volumeMounts: - name: init - mountPath: /usr/sbin + mountPath: {{ .Values.initContainersScriptsVolumeMountPath }} - name: data mountPath: /data {{- if .Values.persistence.subPath }} @@ -174,7 +177,8 @@ spec: {{- end }} - name: configure-gitea image: "{{ include "gitea.image" . }}" - command: ["/usr/sbin/configure_gitea.sh"] + command: + - "{{ .Values.initContainersScriptsVolumeMountPath }}/configure_gitea.sh" imagePullPolicy: {{ .Values.image.pullPolicy }} securityContext: {{- /* By default this container runs as user 1000 unless otherwise stated */ -}} @@ -257,7 +261,7 @@ spec: {{- end }} volumeMounts: - name: init - mountPath: /usr/sbin + mountPath: {{ .Values.initContainersScriptsVolumeMountPath }} - name: temp mountPath: /tmp - name: data diff --git a/unittests/helm/deployment/basic.yaml b/unittests/helm/deployment/basic.yaml index 7ad8d29..bc77ed7 100644 --- a/unittests/helm/deployment/basic.yaml +++ b/unittests/helm/deployment/basic.yaml @@ -73,3 +73,23 @@ tests: requests: cpu: 100ms memory: 100Mi + - it: Init containers have correct volumeMount path + template: templates/gitea/deployment.yaml + set: + initContainersScriptsVolumeMountPath: "/custom/init/path" + asserts: + - equal: + path: spec.template.spec.initContainers[*].volumeMounts[?(@.name=="init")].mountPath + value: "/custom/init/path" + - equal: + path: spec.template.spec.initContainers[*].volumeMounts[?(@.name=="config")].mountPath + value: "/custom/init/path" + - it: Init containers have correct volumeMount path if there is no override + template: templates/gitea/deployment.yaml + asserts: + - equal: + path: spec.template.spec.initContainers[*].volumeMounts[?(@.name=="init")].mountPath + value: "/usr/sbinx" + - equal: + path: spec.template.spec.initContainers[*].volumeMounts[?(@.name=="config")].mountPath + value: "/usr/sbinx" diff --git a/unittests/helm/deployment/signing-enabled.yaml b/unittests/helm/deployment/signing-enabled.yaml index 60179be..47a05e7 100644 --- a/unittests/helm/deployment/signing-enabled.yaml +++ b/unittests/helm/deployment/signing-enabled.yaml @@ -18,7 +18,7 @@ tests: value: configure-gpg - equal: path: spec.template.spec.initContainers[2].command - value: ["/usr/sbin/configure_gpg_environment.sh"] + value: ["/usr/sbinx/configure_gpg_environment.sh"] - equal: path: spec.template.spec.initContainers[2].securityContext value: @@ -34,7 +34,7 @@ tests: path: spec.template.spec.initContainers[2].volumeMounts value: - name: init - mountPath: /usr/sbin + mountPath: /usr/sbinx - name: data mountPath: /data - name: gpg-private-key diff --git a/values.yaml b/values.yaml index 2a5c4d2..6f6fe9b 100644 --- a/values.yaml +++ b/values.yaml @@ -314,6 +314,8 @@ extraVolumeMounts: [] ## @section Init ## @param initPreScript Bash shell script copied verbatim to the start of the init-container. initPreScript: "" +## @param initContainersScriptsVolumeMountPath Path to mount the scripts consumed from the Secrets +initContainersScriptsVolumeMountPath: "/usr/sbinx" # # initPreScript: | # mkdir -p /data/git/.postgresql