From aabcf491d8b80f934db874acab712988ed8b4b52 Mon Sep 17 00:00:00 2001
From: Varac <varac@varac.net>
Date: Tue, 23 Nov 2021 08:49:02 +0100
Subject: [PATCH] Configure dashboard with flux2

Closes: #1040
---
 .gitlab/issue_templates/new_app.md            |  6 ++-
 .../base/dashboard/dashboard-release.yaml     | 34 +++++++++++++
 .../dashboard/dashboard-values-configmap.yaml | 49 +++++++++++++++++++
 .../dashboard/dashboard-values-secret.yaml    |  9 ++++
 flux2/core/base/dashboard/kustomization.yaml  |  8 +++
 flux2/infrastructure/sources/dashboard.yaml   |  4 +-
 .../infrastructure/sources/kustomization.yaml |  1 +
 .../stackspin-dashboard-variables.yaml.jinja  |  7 +++
 8 files changed, 115 insertions(+), 3 deletions(-)
 create mode 100644 flux2/core/base/dashboard/dashboard-release.yaml
 create mode 100644 flux2/core/base/dashboard/dashboard-values-configmap.yaml
 create mode 100644 flux2/core/base/dashboard/dashboard-values-secret.yaml
 create mode 100644 flux2/core/base/dashboard/kustomization.yaml
 create mode 100644 install/templates/stackspin-dashboard-variables.yaml.jinja

diff --git a/.gitlab/issue_templates/new_app.md b/.gitlab/issue_templates/new_app.md
index c6b2a20d6..296f6852a 100644
--- a/.gitlab/issue_templates/new_app.md
+++ b/.gitlab/issue_templates/new_app.md
@@ -6,7 +6,6 @@
 * [ ] Create new source if needed in `flux2/infrastructure/sources/APP.yaml`
 * [ ] Include `APP.yaml` in `flux2/infrastructure/sources/kustomization.yaml`
 * [ ] Add app secret: `install/templates/stackspin-APP-variables.yaml.jinja`
-* Add `Kustomizations`:
    * [ ] `flux2/cluster/optional/APP/APP.yaml`
    * [ ] `flux2/apps/APP/kustomization.yaml`
    * [ ] If needed, add PVCs in `flux2/apps/APP/pvc.yaml`
@@ -72,3 +71,8 @@ Add the following elements to `.gitlab-ci.yml`:
   * [ ] `docs/installation_instructions.rst`
   * [ ] `docs/testing_instructions.rst`
   * [ ] `docs/usage.rst`
+
+## Etc
+
+* [ ] Create follow-up issue with:
+  * [ ] Fine-tune CPU and mem limits (https://open.greenhost.net/stackspin/stackspin/-/  issues/1027)
diff --git a/flux2/core/base/dashboard/dashboard-release.yaml b/flux2/core/base/dashboard/dashboard-release.yaml
new file mode 100644
index 000000000..2ee33f5b1
--- /dev/null
+++ b/flux2/core/base/dashboard/dashboard-release.yaml
@@ -0,0 +1,34 @@
+---
+apiVersion: helm.toolkit.fluxcd.io/v2beta1
+kind: HelmRelease
+metadata:
+  name: dashboard
+spec:
+  releaseName: dashboard
+  dependsOn:
+    - name: nginx
+  chart:
+    spec:
+      chart: ./deployment/helmchart/
+      # NOTE: Change the GitRepository yaml file if you want a different version
+      sourceRef:
+        kind: GitRepository
+        name: dashboard
+        namespace: flux-system
+  interval: 1h
+  install:
+    remediation:
+      retries: 3
+    timeout: 10m
+  valuesFrom:
+    - kind: ConfigMap
+      name: stackspin-dashboard-values
+    - kind: Secret
+      name: stackspin-dashboard-values
+    # Allow overriding values by ConfigMap or Secret
+    - kind: ConfigMap
+      name: stackspin-dashboard-override
+      optional: true
+    - kind: Secret
+      name: stackspin-dashboard-override
+      optional: true
diff --git a/flux2/core/base/dashboard/dashboard-values-configmap.yaml b/flux2/core/base/dashboard/dashboard-values-configmap.yaml
new file mode 100644
index 000000000..c5070f6df
--- /dev/null
+++ b/flux2/core/base/dashboard/dashboard-values-configmap.yaml
@@ -0,0 +1,49 @@
+---
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: stackspin-dashboard-values
+data:
+  values.yaml: |
+    dashboard:
+      image:
+        registry: open.greenhost.net:4567
+        repository: stackspin/dashboard/dashboard
+        tag: main
+        pullPolicy: Always
+      host: dashboard.${domain}
+      resources:
+        limits:
+          cpu: 20m
+          memory: 32Mi
+        requests:
+          cpu: 10m
+          memory: 16Mi
+    backend:
+      image:
+        registry: open.greenhost.net:4567
+        repository: stackspin/dashboard-backend/dashboard-backend
+        tag: main
+        pullPolicy: Always
+      smtp:
+        enabled: ${outgoing_mail_enabled}
+        user: "${outgoing_mail_smtp_user}"
+        password: "${outgoing_mail_smtp_password}"
+        host: "${outgoing_mail_smtp_host}"
+        port: "${outgoing_mail_smtp_port}"
+      kratosUrl: single-sign-on-kratos-admin
+      resources:
+        limits:
+          cpu: 40m
+          memory: 256Mi
+        requests:
+          cpu: 20m
+          memory: 128Mi
+    ingress:
+      certManager: true
+      enabled: true
+      hostname: dashboard.${domain}
+      tls:
+      - hosts:
+        - dashboard.${domain}
+        secretName: stackspin-dashboard
diff --git a/flux2/core/base/dashboard/dashboard-values-secret.yaml b/flux2/core/base/dashboard/dashboard-values-secret.yaml
new file mode 100644
index 000000000..310cc9236
--- /dev/null
+++ b/flux2/core/base/dashboard/dashboard-values-secret.yaml
@@ -0,0 +1,9 @@
+apiVersion: v1
+kind: Secret
+metadata:
+  name: stackspin-dashboard-values
+data:
+  values.yaml: |
+    backend:
+      secretKey: ${backend_secretkey}
+      password: ${backend_password}
diff --git a/flux2/core/base/dashboard/kustomization.yaml b/flux2/core/base/dashboard/kustomization.yaml
new file mode 100644
index 000000000..21e17cdce
--- /dev/null
+++ b/flux2/core/base/dashboard/kustomization.yaml
@@ -0,0 +1,8 @@
+---
+apiVersion: kustomize.config.k8s.io/v1beta1
+kind: Kustomization
+namespace: stackspin
+resources:
+  - ./dashboard-release.yaml
+  - ./dashboard-values-configmap.yaml
+  - ./dashboard-values-secret.yaml
diff --git a/flux2/infrastructure/sources/dashboard.yaml b/flux2/infrastructure/sources/dashboard.yaml
index cee812b25..beaef5d74 100644
--- a/flux2/infrastructure/sources/dashboard.yaml
+++ b/flux2/infrastructure/sources/dashboard.yaml
@@ -6,6 +6,6 @@ metadata:
   namespace: stackspin
 spec:
   interval: 1h
-  url: https://open.greenhost.net/stackspin/admin-frontend
+  url: https://open.greenhost.net/stackspin/dashboard
   ref:
-    commit: 25a82b08c85d7f2b64919efe1084dd2f847d91f1
+    commit: f87849771b085eed5dee2e49ff8cfd720fc32c23
diff --git a/flux2/infrastructure/sources/kustomization.yaml b/flux2/infrastructure/sources/kustomization.yaml
index c86eee7c8..8832ade33 100644
--- a/flux2/infrastructure/sources/kustomization.yaml
+++ b/flux2/infrastructure/sources/kustomization.yaml
@@ -17,3 +17,4 @@ resources:
   - wikimedia.yaml
   - wordpress.yaml
   - zulip.yaml
+  - dashboard.yaml
diff --git a/install/templates/stackspin-dashboard-variables.yaml.jinja b/install/templates/stackspin-dashboard-variables.yaml.jinja
new file mode 100644
index 000000000..11b72cb83
--- /dev/null
+++ b/install/templates/stackspin-dashboard-variables.yaml.jinja
@@ -0,0 +1,7 @@
+apiVersion: v1
+kind: Secret
+metadata:
+  name: stackspin-wekan-variables
+data:
+  backend_secretkey: "{{ 32 | generate_password | b64encode }}"
+  backend_password: "{{ 32 | generate_password | b64encode }}"
-- 
GitLab