From 360b4d135703cdf3f882a7320ae08aefdabe4106 Mon Sep 17 00:00:00 2001
From: Michael Jerger <michael.jerger@meissa-gmbh.de>
Date: Mon, 17 Feb 2025 13:23:09 +0100
Subject: [PATCH] add jicofo

---
 build.py                                      |  2 +-
 src/main/cljc/dda/c4k_jitsi/core.cljc         |  1 +
 src/main/cljc/dda/c4k_jitsi/jitsi.cljc        | 16 ++++-
 .../jitsi/jicofo-config-defaults-cm.yaml      | 14 ++++
 .../jitsi/jicofo-config-deployment.yaml       | 70 +++++++++++++++++++
 .../jitsi/jicofo-config-envs-cm.yaml          | 13 ++++
 .../jitsi/jicofo-config-init-cm.yaml          | 11 +++
 src/test/cljc/dda/c4k_jitsi/jitsi_test.cljc   |  6 ++
 8 files changed, 130 insertions(+), 3 deletions(-)
 create mode 100644 src/main/resources/jitsi/jicofo-config-defaults-cm.yaml
 create mode 100644 src/main/resources/jitsi/jicofo-config-deployment.yaml
 create mode 100644 src/main/resources/jitsi/jicofo-config-envs-cm.yaml
 create mode 100644 src/main/resources/jitsi/jicofo-config-init-cm.yaml

diff --git a/build.py b/build.py
index 14045cf..1500086 100644
--- a/build.py
+++ b/build.py
@@ -165,12 +165,12 @@ def lint(project):
 @task
 def inst(project):
     package_uberjar(project)
-    package_native(project)
     run(
         f"sudo install -m=755 target/uberjar/{project.name}-standalone.jar /usr/local/bin/{project.name}-standalone.jar",
         shell=True,
         check=True,
     )
+    package_native(project)
     run(
         f"sudo install -m=755 target/graalvm/{project.name} /usr/local/bin/{project.name}",
         shell=True,
diff --git a/src/main/cljc/dda/c4k_jitsi/core.cljc b/src/main/cljc/dda/c4k_jitsi/core.cljc
index 4eb4548..84281b9 100644
--- a/src/main/cljc/dda/c4k_jitsi/core.cljc
+++ b/src/main/cljc/dda/c4k_jitsi/core.cljc
@@ -34,6 +34,7 @@
           (cm/concat-vec
            (ns/generate resolved-config)
            (jitsi/prosody-config resolved-config)
+           (jitsi/jicofo-config resolved-config)
            (jitsi/jitsi-config resolved-config)
            (jitsi/jibri-config resolved-config)
           ;;  [(jitsi/generate-jvb-service config)
diff --git a/src/main/cljc/dda/c4k_jitsi/jitsi.cljc b/src/main/cljc/dda/c4k_jitsi/jitsi.cljc
index 5bb4f8d..b2c504b 100644
--- a/src/main/cljc/dda/c4k_jitsi/jitsi.cljc
+++ b/src/main/cljc/dda/c4k_jitsi/jitsi.cljc
@@ -153,7 +153,7 @@
       (cm/replace-all-matching "JITSI_FQDN" fqdn))
      (load-and-adjust-namespace "jitsi/prosody-config-default-cm.yaml" namespace)
      (load-and-adjust-namespace "jitsi/prosody-config-envs-cm.yaml" namespace)
-     (load-and-adjust-namespace "jitsi/prosody-config-init-cm.yaml"namespace)
+     (load-and-adjust-namespace "jitsi/prosody-config-init-cm.yaml" namespace)
      (load-and-adjust-namespace "jitsi/prosody-config-stateful-set.yaml" namespace)
      (load-and-adjust-namespace "jitsi/prosody-config-service.yaml" namespace)
      (load-and-adjust-namespace "jitsi/prosody-config-test-deployment.yaml" namespace)]))
@@ -174,6 +174,16 @@
     (load-and-adjust-namespace "jitsi/prosody-auth-jvb-secret.yaml" namespace)
     (cm/replace-key-value :JVB_AUTH_PASSWORD (b64/encode jvb-auth-password)))]))
 
+(defn-spec jicofo-config cp/map-or-seq?
+  [config config?]
+  (let [{:keys [namespace]} config]
+    [(load-and-adjust-namespace "jitsi/jicofo-config-defaults-cm.yaml" namespace)
+     (->
+      (load-and-adjust-namespace "jitsi/jicofo-config-envs-cm.yaml" namespace)
+      (cm/replace-key-value :XMPP_SERVER (str "prosody." namespace ".svc.cluster.local")))
+     (load-and-adjust-namespace "jitsi/jicofo-config-init-cm.yaml" namespace)
+     (load-and-adjust-namespace "jitsi/jicofo-config-deployment.yaml" namespace)]))
+
 (defn-spec jitsi-config cp/map-or-seq?
   [config config?]
   (let [{:keys [fqdn namespace]} config]
@@ -184,7 +194,9 @@
   (let [{:keys [fqdn namespace]} config]
     [(load-and-adjust-namespace "jitsi/jitsi-config-serviceaccount.yaml" namespace)
      (load-and-adjust-namespace "jitsi/jibri-config-default-cm.yaml" namespace)
-     (load-and-adjust-namespace "jitsi/jibri-config-envs.yaml" namespace)
+     (->
+      (load-and-adjust-namespace "jitsi/jibri-config-envs.yaml" namespace)
+      (cm/replace-key-value :XMPP_SERVER (str "prosody." namespace ".svc.cluster.local")))
      (load-and-adjust-namespace "jitsi/jibri-config-init-cm.yaml" namespace)
      (load-and-adjust-namespace "jitsi/jibri-config-service.yaml" namespace)
      (load-and-adjust-namespace "jitsi/jibri-config-deployment.yaml" namespace)]))
diff --git a/src/main/resources/jitsi/jicofo-config-defaults-cm.yaml b/src/main/resources/jitsi/jicofo-config-defaults-cm.yaml
new file mode 100644
index 0000000..e5c8478
--- /dev/null
+++ b/src/main/resources/jitsi/jicofo-config-defaults-cm.yaml
@@ -0,0 +1,14 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: jitsi-meet-jicofo-defaults
+  namespace: NAMESPACE
+  labels:
+    app.kubernetes.io/name: jitsi-meet
+    app.kubernetes.io/component: jicofo
+data:
+  jicofo.conf: |
+    # Using jicofo /default/jicofo.conf from container image
+    
+  logging.properties: |
+    # Using jicofo /default/logging.properties from container image
\ No newline at end of file
diff --git a/src/main/resources/jitsi/jicofo-config-deployment.yaml b/src/main/resources/jitsi/jicofo-config-deployment.yaml
new file mode 100644
index 0000000..7bf78b5
--- /dev/null
+++ b/src/main/resources/jitsi/jicofo-config-deployment.yaml
@@ -0,0 +1,70 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: jitsi-meet-jicofo
+  namespace: NAMESPACE
+  labels:
+    app.kubernetes.io/name: jitsi-meet
+    app.kubernetes.io/component: jicofo
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app.kubernetes.io/name: jitsi-meet
+      app.kubernetes.io/component: jicofo
+  template:
+    metadata:
+      labels:
+        app.kubernetes.io/name: jitsi-meet
+        app.kubernetes.io/component: jicofo
+    spec:
+      serviceAccountName: jitsi-meet
+      securityContext:
+        {}
+      volumes:
+      - name: config
+        emptyDir: {}
+      - name: custom-cont-inits
+        configMap:
+          defaultMode: 493
+          name: jitsi-meet-jicofo-cont-inits
+          items:
+            - key: 10-config
+              path: 10-config
+      - name: custom-defaults
+        configMap:
+          name: jitsi-meet-jicofo-defaults
+          items:
+            - key: jicofo.conf
+              path: jicofo.conf
+            - key: logging.properties
+              path: logging.properties
+      containers:
+        - name: jitsi-meet
+          securityContext:
+            {}
+          image: "jitsi/jicofo:stable-9646"
+          imagePullPolicy: IfNotPresent
+          envFrom:
+          - secretRef:
+              name: prosody-jicofo
+          - configMapRef:
+              name: prosody-common
+          - configMapRef:
+              name: jitsi-meet-jicofo
+          ports:
+            - name: http
+              containerPort: 80
+              protocol: TCP
+          livenessProbe:
+            tcpSocket:
+              port: 8888
+          readinessProbe:
+            tcpSocket:
+              port: 8888
+          resources:
+            {}
+          volumeMounts:
+          # to support readOnlyRootFilesystem
+          - name: config
+            mountPath: /config
\ No newline at end of file
diff --git a/src/main/resources/jitsi/jicofo-config-envs-cm.yaml b/src/main/resources/jitsi/jicofo-config-envs-cm.yaml
new file mode 100644
index 0000000..39cb597
--- /dev/null
+++ b/src/main/resources/jitsi/jicofo-config-envs-cm.yaml
@@ -0,0 +1,13 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: jitsi-meet-jicofo
+  namespace: NAMESPACE
+  labels:
+    app.kubernetes.io/name: jitsi-meet
+    app.kubernetes.io/component: jicofo
+data:
+  JVB_BREWERY_MUC: 'jvbbrewery'
+  XMPP_SERVER: 'prosody.NAMESPACE.svc.cluster.local'
+  JIBRI_BREWERY_MUC: 'jibribrewery'
+  JIBRI_PENDING_TIMEOUT: '90'
\ No newline at end of file
diff --git a/src/main/resources/jitsi/jicofo-config-init-cm.yaml b/src/main/resources/jitsi/jicofo-config-init-cm.yaml
new file mode 100644
index 0000000..cadd09a
--- /dev/null
+++ b/src/main/resources/jitsi/jicofo-config-init-cm.yaml
@@ -0,0 +1,11 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: jitsi-meet-jicofo-cont-inits
+  namespace: NAMESPACE
+  labels:
+    app.kubernetes.io/name: jitsi-meet
+    app.kubernetes.io/component: jicofo
+data:
+  10-config: |
+    # Using jicofo /etc/cont-init.d/10-config from container image
\ No newline at end of file
diff --git a/src/test/cljc/dda/c4k_jitsi/jitsi_test.cljc b/src/test/cljc/dda/c4k_jitsi/jitsi_test.cljc
index 89ca2c8..41f1734 100644
--- a/src/test/cljc/dda/c4k_jitsi/jitsi_test.cljc
+++ b/src/test/cljc/dda/c4k_jitsi/jitsi_test.cljc
@@ -138,6 +138,12 @@
                   :jicofo-auth-password "jicofo-auth"
                   :jicofo-component-secret "jicofo-comp"})))))
 
+(deftest should-generate-jicofo
+  (is (= 4
+         (count (cut/jicofo-config
+                 {:fqdn "xy.xy.xy"
+                  :namespace "jitsi"})))))
+
 (deftest should-generate-jitsi
   (is (= 1
          (count (cut/jitsi-config