From f1774082c06943cdbe512fe0fc143f5ab2dfce7a Mon Sep 17 00:00:00 2001
From: Leah Tacke genannt Unterberg <leah.tgu@pads.rwth-aachen.de>
Date: Tue, 15 Apr 2025 17:04:49 +0200
Subject: [PATCH] helm chart is finally deployable

---
 helm/superset-mitm-service/Chart.lock         |  4 ++--
 .../templates/deployment.yaml                 | 10 ++++++++
 .../templates/postgresql-auth-secret.yaml     |  8 +++----
 helm/superset-mitm-service/values.yaml        | 12 ++++++++--
 justfile                                      | 23 ++++++++++++++++---
 test/http-client.env.json                     |  4 ++++
 test/upload.http                              |  5 ++++
 7 files changed, 54 insertions(+), 12 deletions(-)

diff --git a/helm/superset-mitm-service/Chart.lock b/helm/superset-mitm-service/Chart.lock
index a1e5059..d0f0b4b 100644
--- a/helm/superset-mitm-service/Chart.lock
+++ b/helm/superset-mitm-service/Chart.lock
@@ -2,5 +2,5 @@ dependencies:
 - name: postgresql
   repository: https://charts.bitnami.com/bitnami
   version: 16.5.0
-digest: sha256:5d40b9c5bdd615dc56524d8ee9cba1d2d79ff4c711b44f3c5507e378823f1323
-generated: "2025-03-17T17:12:51.0781795+01:00"
+digest: sha256:4d3a7a3e13e6cf1645433630c4c9721164bbebdac49984acf9bb76485eb5b40f
+generated: "2025-04-14T12:12:50.190808+02:00"
diff --git a/helm/superset-mitm-service/templates/deployment.yaml b/helm/superset-mitm-service/templates/deployment.yaml
index 0a964a4..85b8524 100644
--- a/helm/superset-mitm-service/templates/deployment.yaml
+++ b/helm/superset-mitm-service/templates/deployment.yaml
@@ -32,6 +32,16 @@ spec:
       securityContext:
         {{- toYaml . | nindent 8 }}
       {{- end }}
+      initContainers:
+        - name: wait-for-db
+          image: postgres:17-alpine
+          command: [ "sh", "-c" ]
+          args:
+            - |
+              until pg_isready -h {{ tpl .Values.mitmDB.mitm_database_host . }} -p {{ .Values.mitmDB.mitm_database_port }}; do
+                echo "Waiting for postgres DB...";
+                sleep 2;
+              done
       containers:
         - name: {{ .Chart.Name }}
           {{- with .Values.securityContext }}
diff --git a/helm/superset-mitm-service/templates/postgresql-auth-secret.yaml b/helm/superset-mitm-service/templates/postgresql-auth-secret.yaml
index 5d62658..f759443 100644
--- a/helm/superset-mitm-service/templates/postgresql-auth-secret.yaml
+++ b/helm/superset-mitm-service/templates/postgresql-auth-secret.yaml
@@ -25,9 +25,7 @@ metadata:
   namespace: {{ .Release.Namespace }}
 type: Opaque
 stringData:
-  postgres-user: {{.Values.mitmDB.mitm_database_user  | quote }}
+  username: {{.Values.mitmDB.mitm_database_user  | quote }}
+  password: {{.Values.mitmDB.mitm_database_password  | quote }}
   postgres-password: {{.Values.mitmDB.mitm_database_password  | quote }}
-  postgres-database: {{.Values.mitmDB.mitm_database_db  | quote }}
-  # POSTGRES_USER: {{.Values.mitmDB.mitm_database_user  | quote }}
-  # POSTGRES_PASSWORD: {{.Values.mitmDB.mitm_database_password  | quote }}
-  # POSTGRES_DATABASE: {{.Values.mitmDB.mitm_database_db  | quote }}
+  database: {{.Values.mitmDB.mitm_database_db  | quote }}
diff --git a/helm/superset-mitm-service/values.yaml b/helm/superset-mitm-service/values.yaml
index ad95f31..b13369e 100644
--- a/helm/superset-mitm-service/values.yaml
+++ b/helm/superset-mitm-service/values.yaml
@@ -165,10 +165,18 @@ mitm-postgresql:
   #   tag: latest-pg16
 
   auth:
+    username: "mitm-pg-user"
+    database: "mitm_db"
+
+    # apparently this does *not* override the username and database setting which is annoying
     existingSecret: '{{ .Values.global.postgresql.configPrefix }}-postgresql-auth-env'
 
+  serviceAccount:
+    automountServiceAccountToken: true
 
   primary:
+    podAnnotations:
+      sidecar.istio.io/inject: "false"
     ##
     ## Persistent Volume Storage configuration.
     ## ref: https://kubernetes.io/docs/user-guide/persistent-volumes
@@ -179,15 +187,15 @@ mitm-postgresql:
       ##
       ## Persistent class
       # storageClass: classname
+      size: 1Gi
       ##
       ## Access modes:
       accessModes:
         - ReadWriteOnce
     ## PostgreSQL port
     service:
-
       ports:
-        postgresql: 5432
+        postgresql: "5432"
 
   # initScripts:
   #   timescaledb: |
diff --git a/justfile b/justfile
index 5f3fb10..835a43c 100644
--- a/justfile
+++ b/justfile
@@ -24,10 +24,27 @@ down:
     docker compose down
 
 helm-package:
-    helm package helm/superset-mitm-service helm/
+    cd helm/ && helm package superset-mitm-service
 
 helm-push a: helm-package
     # helm registry login registry-1.docker.io -u leahtgu
-    helm push {{a}} oci://registry-1.docker.io/leahtgu
+    cd helm/ && helm push {{a}} oci://registry-1.docker.io/leahtgu
 
-kube:
+helm-install:
+    helm --kube-context c4c -n mdata install superset-mitm-service helm/superset-mitm-service
+
+helm-install-dry:
+    helm --kube-context c4c -n mdata install superset-mitm-service helm/superset-mitm-service --dry-run > dryrun.yaml
+
+helm-uninstall:
+    helm --kube-context c4c -n mdata uninstall superset-mitm-service
+
+kube-forward:
+    #! powershell
+    $POD_NAME = kubectl --context=c4c get pods --namespace mdata -l "app.kubernetes.io/name=superset-mitm-service,app.kubernetes.io/instance=superset-mitm-service" -o jsonpath="{.items[0].metadata.name}"
+    $CONTAINER_PORT = kubectl --context=c4c get pod --namespace mdata $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}"
+    Write-Output "Visit http://127.0.0.1:8080 to use your application"
+    kubectl --context=c4c --namespace mdata port-forward $POD_NAME 8080:$CONTAINER_PORT
+
+kube *arg:
+    kubectl --context=c4c -n mdata {{arg}}
\ No newline at end of file
diff --git a/test/http-client.env.json b/test/http-client.env.json
index 5139377..6816d22 100644
--- a/test/http-client.env.json
+++ b/test/http-client.env.json
@@ -10,5 +10,9 @@
   "superset": {
     "port": "8180",
     "uuid":  "b4004d6a-bcaa-4a48-aa54-271b074109ca"
+  },
+  "kubernetes": {
+    "port": "8080",
+    "uuid":  "b4004d6a-bcaa-4a48-aa54-271b074109ca"
   }
 }
\ No newline at end of file
diff --git a/test/upload.http b/test/upload.http
index 90bb544..a1ca8ae 100644
--- a/test/upload.http
+++ b/test/upload.http
@@ -1,3 +1,7 @@
+###
+
+# @name Upload MAED dataset
+# @connection-timeout 180
 POST http://localhost:{{port}}/mitm_dataset/upload?dataset_name=myname_0&mitm=MAED
 Accept: application/json
 Content-Type: multipart/form-data; boundary=WebAppBoundary
@@ -15,6 +19,7 @@ GET http://localhost:{{port}}/mitm_dataset/
 
 ###
 
+
 POST http://localhost:{{port}}/mitm_dataset/upload?dataset_name=myname_1&mitm=MAED
 Accept: application/json
 Content-Type: multipart/form-data; boundary=WebAppBoundary
-- 
GitLab