From e873f644058578dfedd7b66978a1e68ef7609b80 Mon Sep 17 00:00:00 2001
From: Andrej Shadura <andrew.shadura@collabora.co.uk>
Date: Wed, 27 Apr 2022 09:54:57 +0200
Subject: [PATCH] Add more settings, including SSO and msmtp

Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
---
 .../charts/frontend/templates/deployment.yaml | 20 +++++++++++++++++++
 .../frontend/templates/email-secret.yaml      | 11 ++++++++++
 .../charts/frontend/templates/sso-secret.yaml | 11 ++++++++++
 helm/open-build-service/values.yaml           | 11 ++++++++++
 4 files changed, 53 insertions(+)
 create mode 100644 helm/open-build-service/charts/frontend/templates/email-secret.yaml
 create mode 100644 helm/open-build-service/charts/frontend/templates/sso-secret.yaml

diff --git a/helm/open-build-service/charts/frontend/templates/deployment.yaml b/helm/open-build-service/charts/frontend/templates/deployment.yaml
index 4564b1889e..2f1082a694 100644
--- a/helm/open-build-service/charts/frontend/templates/deployment.yaml
+++ b/helm/open-build-service/charts/frontend/templates/deployment.yaml
@@ -88,6 +88,16 @@ spec:
               mountPath: /tmp
             - name: frontend-logs
               mountPath: /obs/src/api/log
+            {{- if (or .Values.global.frontend.msmtprc .Values.global.frontend.msmtprcExistingSecret) }}
+            - name: frontend-email-secret
+              mountPath: /run/secrets/msmtprc
+              subPath: msmtprc
+            {{- end }}
+            {{- if (or .Values.global.frontend.ssoauth .Values.global.frontend.ssoauthExistingSecret) }}
+            - name: frontend-sso-secret
+              mountPath: /run/secrets/ssoauth
+              subPath: ssoauth
+            {{- end }}
         - name: {{ .Chart.Name }}-weblog
           image: busybox
           args:
@@ -132,6 +142,16 @@ spec:
           emptyDir: {}
         - name: frontend-logs
           emptyDir: {}
+        {{- if (or .Values.global.frontend.msmtprc .Values.global.frontend.msmtprcExistingSecret) }}
+        - name: frontend-email-secret
+          secret:
+            secretName: {{ .Values.global.frontend.msmtprcExistingSecret | default (printf "%s-email" (include "frontend.fullname" .)) }}
+        {{- end }}
+        {{- if (or .Values.global.frontend.ssoauth .Values.global.frontend.ssoauthExistingSecret) }}
+        - name: frontend-sso-secret
+          secret:
+            secretName: {{ .Values.global.frontend.ssoauthExistingSecret | default (printf "%s-sso" (include "frontend.fullname" .)) }}
+        {{- end }}
       {{- with .Values.nodeSelector }}
       nodeSelector:
         {{- toYaml . | nindent 8 }}
diff --git a/helm/open-build-service/charts/frontend/templates/email-secret.yaml b/helm/open-build-service/charts/frontend/templates/email-secret.yaml
new file mode 100644
index 0000000000..cf81096220
--- /dev/null
+++ b/helm/open-build-service/charts/frontend/templates/email-secret.yaml
@@ -0,0 +1,11 @@
+{{- if (and .Values.global.frontend.msmtprc (not .Values.global.frontend.msmtprcExistingSecret)) -}}
+apiVersion: v1
+kind: Secret
+type: Opaque
+metadata:
+  name: {{ include "frontend.fullname" . }}-email
+  labels:
+    {{- include "frontend.labels" . | nindent 4 }}
+data:
+  msmtprc: {{ default "" .Values.global.frontend.msmtprc | b64enc | quote }}
+{{- end }}
diff --git a/helm/open-build-service/charts/frontend/templates/sso-secret.yaml b/helm/open-build-service/charts/frontend/templates/sso-secret.yaml
new file mode 100644
index 0000000000..0f6b39cffe
--- /dev/null
+++ b/helm/open-build-service/charts/frontend/templates/sso-secret.yaml
@@ -0,0 +1,11 @@
+{{- if (and .Values.global.frontend.ssoauth (not .Values.global.frontend.ssoauthExistingSecret)) -}}
+apiVersion: v1
+kind: Secret
+type: Opaque
+metadata:
+  name: {{ include "frontend.fullname" . }}-sso
+  labels:
+    {{- include "frontend.labels" . | nindent 4 }}
+data:
+  ssoauth: {{ default "" .Values.global.frontend.ssoauth | toYaml | b64enc | quote }}
+{{- end }}
diff --git a/helm/open-build-service/values.yaml b/helm/open-build-service/values.yaml
index e8c1f8e7f0..593e362c54 100644
--- a/helm/open-build-service/values.yaml
+++ b/helm/open-build-service/values.yaml
@@ -24,6 +24,17 @@ global:
   frontend:
     workers: 4
     # host: frontend
+    # msmtprc: |
+    #   ...
+    # ssoauth:
+    #   fdo-gitlab:
+    #     strategy: gitlab
+    #     description: Freedesktop.org GitLab
+    #     scope: read_user openid profile email
+    #     client_id: hexhexhexhex
+    #     client_secret: hexhexhexhex
+    #     client_options:
+    #       site: https://gitlab.freedesktop.org/api/v4
   backend: {}
     # host: backend
     # extraConfig: |
-- 
GitLab