From 368600d173f3e0d16cab4f64554d370097681ef0 Mon Sep 17 00:00:00 2001
From: Alex ubuntu vm <alexdecb@yahoo.es>
Date: Wed, 24 Jan 2024 16:17:27 +0100
Subject: [PATCH] deployment: Added readiness checks and initContainers

Implemented readinessProbe in l2sm-controller Deployment and added initContainers in l2sm-operator Deployment to ensure proper synchronization with l2sm-controller pod status before starting.

This change ensures that l2sm-operator does not start until l2sm-controller pod is in the Running state.
---
 deployments/custom-installation/deployController.yaml | 10 +++++-----
 deployments/custom-installation/deployOperator.yaml   | 10 ++++++++--
 deployments/custom-installation/deploySwitch.yaml     |  2 +-
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/deployments/custom-installation/deployController.yaml b/deployments/custom-installation/deployController.yaml
index 6a42776..aafae85 100644
--- a/deployments/custom-installation/deployController.yaml
+++ b/deployments/custom-installation/deployController.yaml
@@ -14,11 +14,11 @@ spec:
     spec:
       containers:
       - name: l2sm-controller
-        image: alexdecb/l2sm-controller:latest
-        # readinessProbe:
-        #   httpGet:
-        #     path: /onos/v1/l2sm/networks/status   
-        #     port: 8181   
+        image: alexdecb/l2sm-controller:2.2
+        readinessProbe:
+          httpGet:
+            path: /onos/ui
+            port: 8181   
         ports:
         - containerPort: 6633
         - containerPort: 8181
diff --git a/deployments/custom-installation/deployOperator.yaml b/deployments/custom-installation/deployOperator.yaml
index f88b81f..1617be8 100644
--- a/deployments/custom-installation/deployOperator.yaml
+++ b/deployments/custom-installation/deployOperator.yaml
@@ -15,13 +15,19 @@ spec:
         l2sm-component: l2sm-opt
     spec:
       serviceAccountName: l2sm-operator
+      initContainers:
+      - name: wait-for-l2sm-controller
+        image: busybox:1.31
+        command: ["/bin/sh", "-c", "set -x; while true; do status_code=$(wget --spider -S http://l2sm-controller-service:8181/onos/ui 2>&1 | grep 'HTTP/' | awk '{print $2}'); [ -z $status_code ] && sleep 15 || [ $status_code -eq 200 ] && break || sleep 15; done"]     
       containers:
-      - image: alexdecb/l2sm-operator:2.1
+      - name: wait-test
+        image: busybox:1.31
+        command: ["sleep","infinity"]
+      - image: alexdecb/l2sm-operator:2.2
         name: l2sm-opt-pod
         env:
           - name: CONTROLLER_IP
             value: l2sm-controller-service
-        #command: ["sleep","infinity"]
       - image: mysql/mysql-server:5.7
         name: mysql
         env:
diff --git a/deployments/custom-installation/deploySwitch.yaml b/deployments/custom-installation/deploySwitch.yaml
index 039dad1..d8109f4 100644
--- a/deployments/custom-installation/deploySwitch.yaml
+++ b/deployments/custom-installation/deploySwitch.yaml
@@ -24,7 +24,7 @@ spec:
         effect: NoSchedule
       containers:
       - name: l2sm-switch
-        image: alexdecb/l2sm-switch:2.1
+        image: alexdecb/l2sm-switch:2.2
         command: ["sleep","infinity"]
         #args: ["setup_switch.sh && sleep infinity"]
         env:
-- 
GitLab