Update apps/demo-nginx/Jenkinsfile
This commit is contained in:
106
apps/demo-nginx/Jenkinsfile
vendored
106
apps/demo-nginx/Jenkinsfile
vendored
@@ -440,10 +440,9 @@ EOF
|
|||||||
when { branch 'main' }
|
when { branch 'main' }
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
echo "✅ Verifying deployment and pod status..."
|
echo "✅ Verifying deployment and pod status..."
|
||||||
|
|
||||||
try {
|
sh '''#!/bin/bash
|
||||||
def verifyResult = sh(script: """#!/bin/bash
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo "================================================"
|
echo "================================================"
|
||||||
@@ -453,27 +452,28 @@ EOF
|
|||||||
# 1. Check deployment status
|
# 1. Check deployment status
|
||||||
echo ""
|
echo ""
|
||||||
echo "1. Checking deployment status..."
|
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}"
|
READY_PODS=$(kubectl get deployment "${APP_NAME}" -n "${NAMESPACE}" -o jsonpath='{.status.readyReplicas}')
|
||||||
echo " Updated replicas: \${UPDATED_PODS}"
|
DESIRED_PODS=$(kubectl get deployment "${APP_NAME}" -n "${NAMESPACE}" -o jsonpath='{.spec.replicas}')
|
||||||
echo " Ready replicas: \${READY_PODS}"
|
UPDATED_PODS=$(kubectl get deployment "${APP_NAME}" -n "${NAMESPACE}" -o jsonpath='{.status.updatedReplicas}')
|
||||||
echo " Available replicas: \${AVAILABLE_PODS}"
|
AVAILABLE_PODS=$(kubectl get deployment "${APP_NAME}" -n "${NAMESPACE}" -o jsonpath='{.status.availableReplicas}')
|
||||||
|
|
||||||
if [ "\${READY_PODS}" != "\${DESIRED_PODS}" ]; then
|
echo " Desired replicas: ${DESIRED_PODS}"
|
||||||
echo " ⌠FAILED: Not all pods are ready!"
|
echo " Updated replicas: ${UPDATED_PODS}"
|
||||||
echo " Expected: \${DESIRED_PODS}, Got: \${READY_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
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo " ✅ All pods ready"
|
echo " ✅ All pods ready"
|
||||||
|
|
||||||
|
|
||||||
# 2. Verify pod images (source of truth)
|
# 2. Verify pod images (source of truth)
|
||||||
echo ""
|
echo ""
|
||||||
echo "2. Checking running pod images..."
|
echo "2. Checking running pod images..."
|
||||||
|
|
||||||
POD_IMAGES=$(kubectl get pods -n "${NAMESPACE}" -l app="${APP_NAME}" \
|
POD_IMAGES=$(kubectl get pods -n "${NAMESPACE}" -l app="${APP_NAME}" \
|
||||||
-o jsonpath='{.items[*].spec.containers[0].image}')
|
-o jsonpath='{.items[*].spec.containers[0].image}')
|
||||||
|
|
||||||
@@ -486,67 +486,67 @@ EOF
|
|||||||
fi
|
fi
|
||||||
echo " ✅ All pods are running expected image"
|
echo " ✅ All pods are running expected image"
|
||||||
|
|
||||||
|
|
||||||
# 3. CRITICAL: Verify actual running pod images
|
# 3. CRITICAL: Verify actual running pod images
|
||||||
echo ""
|
echo ""
|
||||||
echo "3. Checking actual running pod images..."
|
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}')
|
|
||||||
|
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 " Running pod images:"
|
||||||
echo "\${POD_IMAGES}" | while read -r img; do
|
while read -r img; do
|
||||||
echo " - \${img}"
|
echo " - ${img}"
|
||||||
done
|
if [[ "${img}" != *"${IMAGE_TAG}"* ]]; then
|
||||||
|
echo " ❌ Pod running wrong image: ${img}"
|
||||||
# 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
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo " ✅ All pods running correct image"
|
done <<< "${POD_IMAGES}"
|
||||||
|
|
||||||
|
echo " ✅ All pods running correct image"
|
||||||
|
|
||||||
# 4. Check pod readiness
|
# 4. Check pod readiness
|
||||||
echo ""
|
echo ""
|
||||||
echo "4. Checking pod readiness probes..."
|
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
|
NOT_READY=$(kubectl get pods -n "${NAMESPACE}" -l app="${APP_NAME}" \
|
||||||
echo " âš ï¸ WARNING: \${NOT_READY} pod(s) not in Running state"
|
--field-selector=status.phase!=Running --no-headers 2>/dev/null | wc -l)
|
||||||
kubectl get pods -n ${NAMESPACE} -l app=${APP_NAME}
|
|
||||||
|
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
|
else
|
||||||
echo " ✅ All pods in Running state"
|
echo " ✅ All pods in Running state"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 5. Check container restart count
|
# 5. Check container restart count
|
||||||
echo ""
|
echo ""
|
||||||
echo "5. Checking for container restarts..."
|
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}"
|
RESTART_COUNTS=$(kubectl get pods -n "${NAMESPACE}" -l app="${APP_NAME}" \
|
||||||
if [ "\${MAX_RESTARTS}" -gt 3 ]; then
|
-o jsonpath='{range .items[*]}{.status.containerStatuses[0].restartCount}{"\n"}{end}')
|
||||||
echo " âš ï¸ WARNING: High restart count detected"
|
|
||||||
|
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
|
else
|
||||||
echo " ✅ Restart count acceptable"
|
echo " ✅ Restart count acceptable"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "================================================"
|
echo "================================================"
|
||||||
echo "✅ ALL VERIFICATION CHECKS PASSED!"
|
echo "✅ ALL VERIFICATION CHECKS PASSED!"
|
||||||
echo "================================================"
|
echo "================================================"
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
|
||||||
""", returnStdout: true).trim()
|
""", returnStdout: true).trim()
|
||||||
|
|
||||||
echo verifyResult
|
echo verifyResult
|
||||||
|
|||||||
Reference in New Issue
Block a user