From 4cfcbd729fea22dd9d72eccaf182ed493d428855 Mon Sep 17 00:00:00 2001 From: kostovicmb Date: Thu, 31 Jul 2025 13:14:46 +0000 Subject: [PATCH] feat(deployment): support further initContainers The following patch intoduce the dictionaries pre and postExtraInitContainers. The dictionaries can be used to specify further initContainers before and after the gitea initializing process. For example: ```yaml postExtraInitContainers: - name: foo image: docker.io/library/busybox:latest preExtraInitContainers: - name: bar image: docker.io/library/busybox:latest ``` --- README.md | 4 +- templates/gitea/deployment.yaml | 10 +++- .../helm/deployment/extraInitContainers.yaml | 59 +++++++++++++++++++ values.yaml | 14 ++++- 4 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 unittests/helm/deployment/extraInitContainers.yaml diff --git a/README.md b/README.md index 3c90fb1..9ce3ee6 100644 --- a/README.md +++ b/README.md @@ -950,7 +950,7 @@ To comply with the Gitea helm chart definition of the digest parameter, a "custo | `global.imagePullSecrets` | global image pull secrets override; can be extended by `imagePullSecrets` | `[]` | | `global.storageClass` | global storage class override | `""` | | `global.hostAliases` | global hostAliases which will be added to the pod's hosts files | `[]` | -| `namespace` | An explicit namespace to deploy Gitea into. Defaults to the release namespace if not specified | `""` | +| `namespace` | An explicit namespace to deploy gitea into. Defaults to the release namespace if not specified | `""` | | `replicaCount` | number of replicas for the deployment | `1` | ### strategy @@ -1072,6 +1072,8 @@ To comply with the Gitea helm chart definition of the digest parameter, a "custo | `persistence.subPath` | Subdirectory of the volume to mount at | `nil` | | `persistence.volumeName` | Name of persistent volume in PVC | `""` | | `extraContainers` | Additional sidecar containers to run in the pod | `[]` | +| `preExtraInitContainers` | Additional init containers to run in the pod before gitea runs it owns init containers. | `[]` | +| `postExtraInitContainers` | Additional init containers to run in the pod after gitea runs it owns init containers. | `[]` | | `extraVolumes` | Additional volumes to mount to the Gitea deployment | `[]` | | `extraContainerVolumeMounts` | Mounts that are only mapped into the Gitea runtime/main container, to e.g. override custom templates. | `[]` | | `extraInitVolumeMounts` | Mounts that are only mapped into the init-containers. Can be used for additional preconfiguration. | `[]` | diff --git a/templates/gitea/deployment.yaml b/templates/gitea/deployment.yaml index 87e1bbb..40ad134 100644 --- a/templates/gitea/deployment.yaml +++ b/templates/gitea/deployment.yaml @@ -59,6 +59,9 @@ spec: securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} initContainers: + {{- if .Values.preExtraInitContainers }} + {{- toYaml .Values.preExtraInitContainers | nindent 8 }} + {{- end }} - name: init-directories image: "{{ include "gitea.image" . }}" imagePullPolicy: {{ .Values.image.pullPolicy }} @@ -98,7 +101,7 @@ spec: - name: init-app-ini image: "{{ include "gitea.image" . }}" imagePullPolicy: {{ .Values.image.pullPolicy }} - command: + command: - "{{ .Values.initContainersScriptsVolumeMountPath }}/config_environment.sh" env: - name: GITEA_APP_INI @@ -143,7 +146,7 @@ spec: {{- if .Values.signing.enabled }} - name: configure-gpg image: "{{ include "gitea.image" . }}" - command: + command: - "{{ .Values.initContainersScriptsVolumeMountPath }}/configure_gpg_environment.sh" imagePullPolicy: {{ .Values.image.pullPolicy }} securityContext: @@ -272,6 +275,9 @@ spec: {{- include "gitea.init-additional-mounts" . | nindent 12 }} resources: {{- toYaml .Values.initContainers.resources | nindent 12 }} + {{- if .Values.postExtraInitContainers }} + {{- toYaml .Values.postExtraInitContainers | nindent 8 }} + {{- end }} terminationGracePeriodSeconds: {{ .Values.deployment.terminationGracePeriodSeconds }} containers: - name: {{ .Chart.Name }} diff --git a/unittests/helm/deployment/extraInitContainers.yaml b/unittests/helm/deployment/extraInitContainers.yaml new file mode 100644 index 0000000..6b2c032 --- /dev/null +++ b/unittests/helm/deployment/extraInitContainers.yaml @@ -0,0 +1,59 @@ +suite: deployment template +release: + name: gitea-unittests + namespace: testing +templates: +- templates/gitea/deployment.yaml +- templates/gitea/config.yaml +tests: +- it: Render the deployment (default) + asserts: + - hasDocuments: + count: 1 + template: templates/gitea/deployment.yaml + - lengthEqual: + path: spec.template.spec.initContainers + count: 3 + template: templates/gitea/deployment.yaml + +- it: Render the deployment (signing) + set: + signing.enabled: true + asserts: + - hasDocuments: + count: 1 + template: templates/gitea/deployment.yaml + - lengthEqual: + path: spec.template.spec.initContainers + count: 4 + template: templates/gitea/deployment.yaml + +- it: Render the deployment (extraInitContainers) + set: + postExtraInitContainers: + - name: foo + image: docker.io/library/busybox:latest + preExtraInitContainers: + - name: bar + image: docker.io/library/busybox:latest + signing.enabled: true + asserts: + - hasDocuments: + count: 1 + template: templates/gitea/deployment.yaml + - lengthEqual: + path: spec.template.spec.initContainers + count: 6 + template: templates/gitea/deployment.yaml + - contains: + path: spec.template.spec.initContainers + content: + name: foo + image: docker.io/library/busybox:latest + template: templates/gitea/deployment.yaml + - contains: + path: spec.template.spec.initContainers + content: + name: bar + image: docker.io/library/busybox:latest + template: templates/gitea/deployment.yaml diff --git a/values.yaml b/values.yaml index c2eaced..4f323cb 100644 --- a/values.yaml +++ b/values.yaml @@ -279,7 +279,19 @@ persistence: extraContainers: [] # - name: sidecar-bob # image: busybox -# command: [/bin/sh, -c, 'echo "Hello world"; sleep 86400'] +# command: [/bin/sh, -c, 'echo "Hello world"'] + +## @param preExtraInitContainers Additional init containers to run in the pod before gitea runs it owns init containers. +preExtraInitContainers: [] +# - name: pre-init-container +# image: docker.io/library/busybox +# command: [ /bin/sh, -c, 'echo "Hello world! I am a pre init container."' ] + +## @param postExtraInitContainers Additional init containers to run in the pod after gitea runs it owns init containers. +postExtraInitContainers: [] +# - name: post-init-container +# image: docker.io/library/busybox +# command: [ /bin/sh, -c, 'echo "Hello world! I am a post init container."' ] ## @param extraVolumes Additional volumes to mount to the Gitea deployment extraVolumes: []