From 75931b7bcc585b4b6dbb6bf7a34b35dad63c4d41 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 8 Jan 2026 10:02:50 +0000 Subject: [PATCH] Update apps/demo-nginx/Jenkinsfile --- apps/demo-nginx/Jenkinsfile | 208 ++++++++++++++++++------------------ 1 file changed, 104 insertions(+), 104 deletions(-) diff --git a/apps/demo-nginx/Jenkinsfile b/apps/demo-nginx/Jenkinsfile index f6fd9b7..b8bc3fb 100644 --- a/apps/demo-nginx/Jenkinsfile +++ b/apps/demo-nginx/Jenkinsfile @@ -440,113 +440,113 @@ EOF when { branch 'main' } steps { script { - echo "✅ Verifying deployment and pod status..." - - try { - def verifyResult = sh(script: """#!/bin/bash - set -e - - echo "================================================" - echo "DEPLOYMENT VERIFICATION" - echo "================================================" - - # 1. Check deployment status - echo "" - echo "1. Checking deployment status..." - READY_PODS=\$(kubectl get deployment ${APP_NAME} -n ${NAMESPACE} -o jsonpath='{.status.readyReplicas}') - DESIRED_PODS=\$(kubectl get deployment ${APP_NAME} -n ${NAMESPACE} -o jsonpath='{.spec.replicas}') - UPDATED_PODS=\$(kubectl get deployment ${APP_NAME} -n ${NAMESPACE} -o jsonpath='{.status.updatedReplicas}') - AVAILABLE_PODS=\$(kubectl get deployment ${APP_NAME} -n ${NAMESPACE} -o jsonpath='{.status.availableReplicas}') - - echo " Desired replicas: \${DESIRED_PODS}" - echo " Updated replicas: \${UPDATED_PODS}" - echo " Ready replicas: \${READY_PODS}" - echo " Available replicas: \${AVAILABLE_PODS}" - - if [ "\${READY_PODS}" != "\${DESIRED_PODS}" ]; then - echo " ❌ FAILED: Not all pods are ready!" - echo " Expected: \${DESIRED_PODS}, Got: \${READY_PODS}" - exit 1 - fi - echo " ✅ All pods ready" - - - # 2. Verify pod images (source of truth) - echo "" - echo "2. Checking running pod images..." - POD_IMAGES=$(kubectl get pods -n "${NAMESPACE}" -l app="${APP_NAME}" \ - -o jsonpath='{.items[*].spec.containers[0].image}') + echo "✅ Verifying deployment and pod status..." - echo " Pod images: ${POD_IMAGES}" - echo " Expected tag: ${IMAGE_TAG}" + sh '''#!/bin/bash + set -e - if [[ "${POD_IMAGES}" != *"${IMAGE_TAG}"* ]]; then - echo " ❌ FAILED: Pods are running wrong image!" - exit 1 - fi - echo " ✅ All pods are running expected image" + echo "================================================" + echo "DEPLOYMENT VERIFICATION" + echo "================================================" + + # 1. Check deployment status + echo "" + echo "1. Checking deployment status..." + + READY_PODS=$(kubectl get deployment "${APP_NAME}" -n "${NAMESPACE}" -o jsonpath='{.status.readyReplicas}') + DESIRED_PODS=$(kubectl get deployment "${APP_NAME}" -n "${NAMESPACE}" -o jsonpath='{.spec.replicas}') + UPDATED_PODS=$(kubectl get deployment "${APP_NAME}" -n "${NAMESPACE}" -o jsonpath='{.status.updatedReplicas}') + AVAILABLE_PODS=$(kubectl get deployment "${APP_NAME}" -n "${NAMESPACE}" -o jsonpath='{.status.availableReplicas}') + + echo " Desired replicas: ${DESIRED_PODS}" + echo " Updated replicas: ${UPDATED_PODS}" + echo " Ready replicas: ${READY_PODS}" + echo " Available replicas: ${AVAILABLE_PODS}" + + if [ "${READY_PODS}" != "${DESIRED_PODS}" ]; then + echo " ❌ FAILED: Not all pods are ready!" + echo " Expected: ${DESIRED_PODS}, Got: ${READY_PODS}" + exit 1 + fi + echo " ✅ All pods ready" + + # 2. Verify pod images (source of truth) + echo "" + echo "2. Checking running pod images..." + + POD_IMAGES=$(kubectl get pods -n "${NAMESPACE}" -l app="${APP_NAME}" \ + -o jsonpath='{.items[*].spec.containers[0].image}') + + echo " Pod images: ${POD_IMAGES}" + echo " Expected tag: ${IMAGE_TAG}" + + if [[ "${POD_IMAGES}" != *"${IMAGE_TAG}"* ]]; then + echo " ❌ FAILED: Pods are running wrong image!" + exit 1 + fi + echo " ✅ All pods are running expected image" + + # 3. CRITICAL: Verify actual running pod images + echo "" + echo "3. Checking actual running pod images..." + + POD_IMAGES=$(kubectl get pods -n "${NAMESPACE}" -l app="${APP_NAME}" \ + -o jsonpath='{range .items[*]}{.status.containerStatuses[0].image}{"\n"}{end}') + + echo " Running pod images:" + while read -r img; do + echo " - ${img}" + if [[ "${img}" != *"${IMAGE_TAG}"* ]]; then + echo " ❌ Pod running wrong image: ${img}" + exit 1 + fi + done <<< "${POD_IMAGES}" + + echo " ✅ All pods running correct image" + + # 4. Check pod readiness + echo "" + echo "4. Checking pod readiness..." + + NOT_READY=$(kubectl get pods -n "${NAMESPACE}" -l app="${APP_NAME}" \ + --field-selector=status.phase!=Running --no-headers 2>/dev/null | wc -l) + + if [ "${NOT_READY}" -gt 0 ]; then + echo " ⚠️ WARNING: ${NOT_READY} pod(s) not in Running state" + kubectl get pods -n "${NAMESPACE}" -l app="${APP_NAME}" + else + echo " ✅ All pods in Running state" + fi + + # 5. Check container restart count + echo "" + echo "5. Checking for container restarts..." + + RESTART_COUNTS=$(kubectl get pods -n "${NAMESPACE}" -l app="${APP_NAME}" \ + -o jsonpath='{range .items[*]}{.status.containerStatuses[0].restartCount}{"\n"}{end}') + + MAX_RESTARTS=0 + while read -r count; do + if [ "${count}" -gt "${MAX_RESTARTS}" ]; then + MAX_RESTARTS="${count}" + fi + done <<< "${RESTART_COUNTS}" + + echo " Max restart count: ${MAX_RESTARTS}" + + if [ "${MAX_RESTARTS}" -gt 3 ]; then + echo " ⚠️ WARNING: High restart count detected" + else + echo " ✅ Restart count acceptable" + fi + + echo "" + echo "================================================" + echo "✅ ALL VERIFICATION CHECKS PASSED!" + echo "================================================" + ''' +} - - # 3. CRITICAL: Verify actual running pod images - echo "" - echo "3. Checking actual running pod images..." - POD_IMAGES=\$(kubectl get pods -n ${NAMESPACE} -l app=${APP_NAME} -o jsonpath='{range .items[*]}{.status.containerStatuses[0].image}{"\\n"}{end}') - - echo " Running pod images:" - echo "\${POD_IMAGES}" | while read -r img; do - echo " - \${img}" - done - - # Check if all pods are running the correct image - WRONG_IMAGE_COUNT=0 - while IFS= read -r img; do - if [[ "\${img}" != *"${IMAGE_TAG}"* ]]; then - echo " ❌ Pod running wrong image: \${img}" - WRONG_IMAGE_COUNT=\$((WRONG_IMAGE_COUNT + 1)) - fi - done <<< "\${POD_IMAGES}" - - if [ \${WRONG_IMAGE_COUNT} -gt 0 ]; then - echo " ❌ FAILED: \${WRONG_IMAGE_COUNT} pod(s) running old image!" - echo " This is the ArgoCD sync bug - deployment updated but pods not rolled out" - exit 1 - fi - echo " ✅ All pods running correct image" - - # 4. Check pod readiness - echo "" - echo "4. Checking pod readiness probes..." - NOT_READY=\$(kubectl get pods -n ${NAMESPACE} -l app=${APP_NAME} --field-selector=status.phase!=Running --no-headers 2>/dev/null | wc -l) - - if [ "\${NOT_READY}" -gt 0 ]; then - echo " ⚠️ WARNING: \${NOT_READY} pod(s) not in Running state" - kubectl get pods -n ${NAMESPACE} -l app=${APP_NAME} - else - echo " ✅ All pods in Running state" - fi - - # 5. Check container restart count - echo "" - echo "5. Checking for container restarts..." - RESTART_COUNTS=\$(kubectl get pods -n ${NAMESPACE} -l app=${APP_NAME} -o jsonpath='{range .items[*]}{.status.containerStatuses[0].restartCount}{"\\n"}{end}') - MAX_RESTARTS=0 - while IFS= read -r count; do - if [ "\${count}" -gt "\${MAX_RESTARTS}" ]; then - MAX_RESTARTS=\${count} - fi - done <<< "\${RESTART_COUNTS}" - - echo " Max restart count: \${MAX_RESTARTS}" - if [ "\${MAX_RESTARTS}" -gt 3 ]; then - echo " ⚠️ WARNING: High restart count detected" - else - echo " ✅ Restart count acceptable" - fi - - echo "" - echo "================================================" - echo "✅ ALL VERIFICATION CHECKS PASSED!" - echo "================================================" """, returnStdout: true).trim() echo verifyResult