7272 configMapKeyRef :
7373 name : {{ include "osmosis-fullnode.fullname" . }}-sentinel-config
7474 key : max-node-restart-count
75+ - name : ARGOCD_ENABLED
76+ valueFrom :
77+ configMapKeyRef :
78+ name : {{ include "osmosis-fullnode.fullname" . }}-sentinel-config
79+ key : argocd-enabled
80+ - name : ARGOCD_SERVER
81+ valueFrom :
82+ configMapKeyRef :
83+ name : {{ include "osmosis-fullnode.fullname" . }}-sentinel-config
84+ key : argocd-server
7585 command :
7686 - bash
7787 - -c
@@ -101,28 +111,88 @@ spec:
101111 fi
102112 }
103113
114+ # Function to check if ArgoCD is available
115+ check_argocd_available() {
116+ if [ "${ARGOCD_ENABLED:-true}" != "true" ]; then
117+ echo "📴 ArgoCD integration is disabled via configuration"
118+ return 1
119+ fi
120+
121+ # Check if ArgoCD namespace exists
122+ if ! kubectl get namespace argocd >/dev/null 2>&1; then
123+ echo "⚠️ ArgoCD namespace not found, skipping ArgoCD operations"
124+ return 1
125+ fi
126+
127+ # Check if the ArgoCD application exists
128+ if ! kubectl get application "$ARGOCD_APPLICATION" -n argocd >/dev/null 2>&1; then
129+ echo "⚠️ ArgoCD application '$ARGOCD_APPLICATION' not found, skipping ArgoCD operations"
130+ return 1
131+ fi
132+
133+ echo "✅ ArgoCD is available and configured"
134+ return 0
135+ }
136+
137+ # Function to pause ArgoCD auto-sync
138+ pause_argocd_sync() {
139+ if check_argocd_available; then
140+ echo "⏸️ Pausing ArgoCD auto-sync for application: $ARGOCD_APPLICATION"
141+ if argocd app set "$ARGOCD_APPLICATION" --sync-policy none; then
142+ echo "✅ ArgoCD auto-sync paused successfully"
143+ return 0
144+ else
145+ echo "❌ Failed to pause ArgoCD auto-sync, continuing without ArgoCD management"
146+ return 1
147+ fi
148+ else
149+ echo "ℹ️ Skipping ArgoCD pause operation"
150+ return 1
151+ fi
152+ }
153+
154+ # Function to resume ArgoCD auto-sync
155+ resume_argocd_sync() {
156+ if check_argocd_available; then
157+ echo "▶️ Resuming ArgoCD auto-sync for application: $ARGOCD_APPLICATION"
158+ if argocd app set "$ARGOCD_APPLICATION" --sync-policy automated; then
159+ echo "✅ ArgoCD auto-sync resumed successfully"
160+ else
161+ echo "⚠️ Failed to resume ArgoCD auto-sync, but cleanup completed"
162+ fi
163+ else
164+ echo "ℹ️ Skipping ArgoCD resume operation"
165+ fi
166+ }
167+
104168 # Function to handle StatefulSet scaling and cleanup
105169 handle_cleanup() {
106170 local namespace=$1
107171 local osmosis_app=$2
108172 local osmosis_pod=$3
109173
110- # Pause ArgoCD auto-sync
111- echo "⏸️ Pausing ArgoCD auto-sync"
112- if ! kubectl patch application $ARGOCD_APPLICATION -n argocd --type merge -p "{\"spec\":{\"syncPolicy\":null}}"; then
113- echo "❌ Failed to pause ArgoCD auto-sync"
114- exit 1
174+ # Track if we paused ArgoCD to know if we should resume it
175+ local argocd_was_paused=false
176+
177+ # Pause ArgoCD auto-sync (if available)
178+ if pause_argocd_sync; then
179+ argocd_was_paused=true
115180 fi
116- echo "✅ ArgoCD auto-sync paused successfully"
117181
118182 # Scale down the StatefulSet to 0 replicas
183+ echo "📉 Scaling down StatefulSet $osmosis_app to 0 replicas"
119184 kubectl scale statefulset $osmosis_app -n $namespace --replicas=0
120185
121186 # Wait for the pod to terminate
187+ echo "⏳ Waiting for pod $osmosis_pod to terminate..."
122188 kubectl wait --for=delete pod/$osmosis_pod -n $namespace --timeout=600s
123189
124190 if kubectl get pod $osmosis_pod -n $namespace &>/dev/null; then
125191 echo "❌ Pod $osmosis_pod is still running after timeout"
192+ # Try to resume ArgoCD if we paused it
193+ if [ "$argocd_was_paused" = true ]; then
194+ resume_argocd_sync
195+ fi
126196 exit 1
127197 fi
128198
@@ -132,13 +202,15 @@ spec:
132202 cleanup_folders $(hostname) $namespace $MONITOR_PATH
133203
134204 # Scale the StatefulSet back to 1 replica
205+ echo "📈 Scaling StatefulSet $osmosis_app back to 1 replica"
135206 kubectl scale statefulset $osmosis_app -n $namespace --replicas=1
136207
137- # Resume ArgoCD auto-sync
138- echo "▶️ Resuming ArgoCD auto-sync"
139- kubectl patch application $ARGOCD_APPLICATION -n argocd --type merge -p '{"spec":{"syncPolicy":{"automated":{"prune":true,"selfHeal":true}}}}' || true
208+ # Resume ArgoCD auto-sync (if we paused it)
209+ if [ "$argocd_was_paused" = true ]; then
210+ resume_argocd_sync
211+ fi
140212
141- echo "🔄 Cleanup completed"
213+ echo "🔄 Cleanup completed successfully "
142214 }
143215
144216 # Install required packages quietly
@@ -149,6 +221,23 @@ spec:
149221 echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | tee /etc/apt/sources.list.d/kubernetes.list
150222 apt-get update -qq && apt-get install -y -qq kubectl > /dev/null 2>&1
151223
224+ # Install ArgoCD CLI
225+ curl -sSL -o /usr/local/bin/argocd https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
226+ chmod +x /usr/local/bin/argocd
227+ echo "✅ ArgoCD CLI installed"
228+
229+ # Configure ArgoCD authentication using service account token
230+ if [ "${ARGOCD_ENABLED:-true}" = "true" ]; then
231+ export ARGOCD_SERVER="${ARGOCD_SERVER:-argocd-server.argocd.svc.cluster.local:80}"
232+ export ARGOCD_AUTH_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
233+ # Test ArgoCD connection
234+ if argocd cluster list >/dev/null 2>&1; then
235+ echo "✅ ArgoCD authentication configured successfully"
236+ else
237+ echo "⚠️ ArgoCD authentication failed, will skip ArgoCD operations"
238+ fi
239+ fi
240+
152241 # Get pod info
153242 NAMESPACE=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)
154243 echo "🔍 Namespace: $NAMESPACE"
@@ -165,6 +254,15 @@ spec:
165254 echo "🔍 Osmosis App: $OSMOSIS_APP"
166255 echo "🔍 Osmosis Pod: $OSMOSIS_POD"
167256
257+ # Display ArgoCD configuration status
258+ echo "🔍 ArgoCD Integration: ${ARGOCD_ENABLED:-true}"
259+ if [ "${ARGOCD_ENABLED:-true}" = "true" ]; then
260+ echo "🔍 ArgoCD Application: $ARGOCD_APPLICATION"
261+ check_argocd_available || echo "⚠️ ArgoCD not available in this environment"
262+ else
263+ echo "📴 ArgoCD integration is disabled"
264+ fi
265+
168266 # Check if pod exists and get its status
169267 if ! kubectl get pod $OSMOSIS_POD -n $NAMESPACE &>/dev/null; then
170268 echo "❌ Pod $OSMOSIS_POD not found"
0 commit comments