From db21fa2e1a3ad0b59235a5b8557a2b026cd4a580 Mon Sep 17 00:00:00 2001 From: Son Date: Tue, 21 May 2024 10:22:09 -0400 Subject: [PATCH 1/5] chart: add support for multiline and multiple existing secrets --- charts/sogo/templates/deployment.yaml | 23 ++++++++++++++--------- charts/sogo/values.yaml | 4 ++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/charts/sogo/templates/deployment.yaml b/charts/sogo/templates/deployment.yaml index c6e1c70..4bf7458 100644 --- a/charts/sogo/templates/deployment.yaml +++ b/charts/sogo/templates/deployment.yaml @@ -226,10 +226,12 @@ spec: - name: {{ template "sogo.fullname" . }}-tmp mountPath: /secrets {{- if .Values.sogo.existingSecrets }} - - name: existing-secrets - mountPath: /existing-secrets + {{- range .Values.sogo.existingSecrets }} + - name: {{ printf "existing-secrets-%s" (kebabcase .) }} + mountPath: {{ printf "/existing-secrets/%s" (kebabcase .) }} readOnly: true {{- end }} + {{- end }} command: - "sh" - "-c" @@ -245,14 +247,15 @@ spec: > "$output_file" # Loop through each file in the directory - for file in /existing-secrets/*; do + # Find all files within the existing-secrets directory and its subdirectories + find /existing-secrets -type f | while read -r file; do # Get the filename without the directory path filename=$(basename "$file") - # Read the content of the file - content=$(cat "$file") - # Append the filename and content to the YAML file + # Read the content of the file and indent each line with two spaces + content=$(sed 's/^/ /' "$file") + # Append the filename and content to the YAML file if the content is not empty if [ -n "$content" ]; then - echo "$filename: $content" >> "$output_file" + echo -e "$filename: |-\n$content" >> "$output_file" fi done EOF @@ -358,9 +361,11 @@ spec: secretName: {{ template "sogo.fullname" . }}-secret {{- end }} {{- if .Values.sogo.existingSecrets }} - - name: existing-secrets + {{- range .Values.sogo.existingSecrets }} + - name: {{ printf "existing-secrets-%s" (kebabcase .) }} secret: - secretName: {{ .Values.sogo.existingSecrets }} + secretName: {{ . }} + {{- end }} {{- end }} - name: {{ template "sogo.fullname" . }}-tmp emptyDir: {} diff --git a/charts/sogo/values.yaml b/charts/sogo/values.yaml index ddf5fb7..47ef240 100644 --- a/charts/sogo/values.yaml +++ b/charts/sogo/values.yaml @@ -84,8 +84,8 @@ sogo: # OCSStoreURL: "mysql://sogo:pass@db:3306/sogo/sogo_store" # OCSAclURL: "mysql://sogo:pass@db:3306/sogo/sogo_acl" - # Name of Secret containing the configurations - existingSecrets: + # Array of secret names containing the configurations + existingSecrets: [] ## SOGo Custom Theming ## NOTE: SOGoUIxDebugEnabled is automatically set to YES when only .sogo.theme.js is set From 9a7977e5dd31e28475de1cc02cd814fc235bfed8 Mon Sep 17 00:00:00 2001 From: Son Date: Tue, 21 May 2024 10:22:32 -0400 Subject: [PATCH 2/5] chart: bump version to 0.1.6 --- charts/sogo/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/sogo/Chart.yaml b/charts/sogo/Chart.yaml index 29cfe44..a0aef2a 100644 --- a/charts/sogo/Chart.yaml +++ b/charts/sogo/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: sogo -version: 0.1.5 +version: 0.1.6 description: A helm chart for the docker-sogo docker image type: application keywords: From fe2467387a643aef8a28ea7cb84d8ead6e70db52 Mon Sep 17 00:00:00 2001 From: Son Date: Tue, 21 May 2024 10:31:07 -0400 Subject: [PATCH 3/5] chart: fix existingSecrets test format --- charts/sogo/ci/existing-secrets-values.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/charts/sogo/ci/existing-secrets-values.yaml b/charts/sogo/ci/existing-secrets-values.yaml index a90fac6..2a0f81a 100644 --- a/charts/sogo/ci/existing-secrets-values.yaml +++ b/charts/sogo/ci/existing-secrets-values.yaml @@ -12,4 +12,5 @@ sogo: SOGoLanguage: English SOGoTimeZone: America/Montreal WOWorkersCount: 5 - existingSecrets: test-secret + existingSecrets: + - test-secret From 4412a1c844bc40967857d65c583720873f7ef211 Mon Sep 17 00:00:00 2001 From: Son Date: Tue, 21 May 2024 10:48:07 -0400 Subject: [PATCH 4/5] chart: use while IFS over content instead of sed --- charts/sogo/templates/deployment.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/charts/sogo/templates/deployment.yaml b/charts/sogo/templates/deployment.yaml index 4bf7458..44cc518 100644 --- a/charts/sogo/templates/deployment.yaml +++ b/charts/sogo/templates/deployment.yaml @@ -252,10 +252,13 @@ spec: # Get the filename without the directory path filename=$(basename "$file") # Read the content of the file and indent each line with two spaces - content=$(sed 's/^/ /' "$file") + content=$(cat "$file") # Append the filename and content to the YAML file if the content is not empty if [ -n "$content" ]; then - echo -e "$filename: |-\n$content" >> "$output_file" + echo "$filename: |-" >> "$output_file" + while IFS= read -r line; do + echo " $line" >> "$output_file" + done <<< "$content" fi done EOF From f1ff33f01bf39bae22e202a3988f62edd55d0e40 Mon Sep 17 00:00:00 2001 From: Son Date: Tue, 21 May 2024 11:08:06 -0400 Subject: [PATCH 5/5] chart: convert existing secrets script to bash --- charts/sogo/templates/deployment.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/sogo/templates/deployment.yaml b/charts/sogo/templates/deployment.yaml index 44cc518..b99f7fa 100644 --- a/charts/sogo/templates/deployment.yaml +++ b/charts/sogo/templates/deployment.yaml @@ -241,7 +241,7 @@ spec: touch "$tmp_script" cat << 'EOF' > "$tmp_script" - #!/bin/sh + #!/bin/bash output_file="/secrets/existing-secrets.yaml" > "$output_file" @@ -266,7 +266,7 @@ spec: chmod +x "$tmp_script" # Generation of config file - sh "$tmp_script" + bash "$tmp_script" {{- if or .Values.mariadb.enabled (eq (include "sogo.db.parsed.type" .) "mysql") }} - name: mariadb-isalive