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