From 80acabff9ba56fe0d6624b67ba1b9c136244b22d Mon Sep 17 00:00:00 2001
From: Michael Jerger <michael.jerger@meissa-gmbh.de>
Date: Tue, 18 Feb 2025 15:13:05 +0100
Subject: [PATCH] restart cron now might work

---
 src/main/cljc/dda/c4k_jitsi/core.cljc           |  2 +-
 src/main/cljc/dda/c4k_jitsi/jitsi.cljc          | 17 ++++++++++++++++-
 .../resources/jitsi/restart-config-cron.yaml    | 11 +++--------
 src/test/cljc/dda/c4k_jitsi/jitsi_test.cljc     |  8 ++++----
 4 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/src/main/cljc/dda/c4k_jitsi/core.cljc b/src/main/cljc/dda/c4k_jitsi/core.cljc
index 9eb7149..a7c92ee 100644
--- a/src/main/cljc/dda/c4k_jitsi/core.cljc
+++ b/src/main/cljc/dda/c4k_jitsi/core.cljc
@@ -39,7 +39,7 @@
            (jitsi/jicofo-config resolved-config)
            (jitsi/web-config resolved-config)
            (jitsi/jvb-config resolved-config)
-           (jitsi/jibri-config resolved-config)
+           ;(jitsi/jibri-config resolved-config)
            (jitsi/restart-config resolved-config)
            (jitsi/etherpad-config resolved-config)
            (jitsi/excalidraw-config resolved-config)
diff --git a/src/main/cljc/dda/c4k_jitsi/jitsi.cljc b/src/main/cljc/dda/c4k_jitsi/jitsi.cljc
index 7841dea..d8f0f8f 100644
--- a/src/main/cljc/dda/c4k_jitsi/jitsi.cljc
+++ b/src/main/cljc/dda/c4k_jitsi/jitsi.cljc
@@ -127,7 +127,22 @@
       (cm/replace-key-value :resourceNames ["etherpad", "excalidraw"]))
      (->
       (load-and-adjust-namespace "jitsi/restart-config-cron.yaml" namespace)
-      (cm/replace-key-value :resourceNames))]))
+      (cm/replace-all-matching "CRON_NAME" "restart-etherpad")
+      (cm/replace-key-value :schedule "0 2 * * *")
+      (cm/replace-key-value 
+       :command 
+       ["bash"
+        "-c"
+        "kubectl rollout restart deployment/etherpad && kubectl rollout status deployment/etherpad"]))
+     (->
+      (load-and-adjust-namespace "jitsi/restart-config-cron.yaml" namespace)
+      (cm/replace-all-matching "CRON_NAME" "restart-excalidraw")
+      (cm/replace-key-value :schedule "0 1 * * *")
+      (cm/replace-key-value
+       :command
+       ["bash"
+        "-c"
+        "kubectl rollout restart deployment/excalidraw && kubectl rollout status deployment/excalidraw"]))]))
 
 (defn-spec etherpad-config cp/map-or-seq?
   [config config?]
diff --git a/src/main/resources/jitsi/restart-config-cron.yaml b/src/main/resources/jitsi/restart-config-cron.yaml
index a96b3c4..2df74a9 100644
--- a/src/main/resources/jitsi/restart-config-cron.yaml
+++ b/src/main/resources/jitsi/restart-config-cron.yaml
@@ -1,11 +1,11 @@
 apiVersion: batch/v1
 kind: CronJob
 metadata:
-  name: deployment-restart
+  name: CRON_NAME
   namespace: NAMESPACE
 spec:
   concurrencyPolicy: Forbid
-  schedule: SCHEDULE_REPLACE_Me
+  schedule: SCHEDULE_REPLACE_ME
   jobTemplate:
     spec:
       backoffLimit: 2
@@ -17,9 +17,4 @@ spec:
           containers:
             - name: kubectl
               image: bitnami/kubectl
-          command:
-          - bash
-          - -c
-          - >-
-            kubectl rollout restart deployment/<YOUR DEPLOYMENT NAME> &&
-            kubectl rollout status deployment/<YOUR DEPLOYMENT NAME>
+          command: COMMAND_REPLACE_ME
diff --git a/src/test/cljc/dda/c4k_jitsi/jitsi_test.cljc b/src/test/cljc/dda/c4k_jitsi/jitsi_test.cljc
index 252fef0..8a65e0d 100644
--- a/src/test/cljc/dda/c4k_jitsi/jitsi_test.cljc
+++ b/src/test/cljc/dda/c4k_jitsi/jitsi_test.cljc
@@ -140,10 +140,10 @@
               2)))
   (is (= {:apiVersion "batch/v1",
           :kind "CronJob",
-          :metadata {:name "deployment-restart", :namespace "jitsi"},
+          :metadata {:name "restart-etherpad", :namespace "jitsi"},
           :spec
           {:concurrencyPolicy "Forbid",
-           :schedule "SCHEDULE_REPLACE_Me",
+           :schedule "0 2 * * *",
            :jobTemplate
            {:spec
             {:backoffLimit 2,
@@ -156,12 +156,12 @@
                :command
                ["bash"
                 "-c"
-                "kubectl rollout restart deployment/<YOUR DEPLOYMENT NAME> && kubectl rollout status deployment/<YOUR DEPLOYMENT NAME>"]}}}}}}
+                "kubectl rollout restart deployment/etherpad && kubectl rollout status deployment/etherpad"]}}}}}}
          (nth (cut/restart-config
                {:fqdn "xy.xy.xy"
                 :namespace "jitsi"})
               3)))
-  (is (= 4
+  (is (= 5
          (count (cut/restart-config
                  {:fqdn "xy.xy.xy"
                   :namespace "jitsi"})))))