#!/bin/bash # Test graceful termination of signal-aware Buildah container set -e NAMESPACE="apps--droneio--prd" DEPLOYMENT="buildah-external" echo "๐Ÿงช Testing Graceful Termination" echo "===============================" # Scale up to create a pod echo "๐Ÿ”ผ Scaling up deployment..." kubectl scale deployment $DEPLOYMENT --replicas=1 -n $NAMESPACE echo "โณ Waiting for pod to be ready..." kubectl wait --for=condition=ready pod -l app=buildah-external -n $NAMESPACE --timeout=60s POD_NAME=$(kubectl get pods -l app=buildah-external -n $NAMESPACE -o jsonpath='{.items[0].metadata.name}') echo "๐Ÿ“ฆ Testing pod: $POD_NAME" # Test that the container is responsive echo "๐Ÿ” Testing container responsiveness..." kubectl exec $POD_NAME -n $NAMESPACE -- buildah --version # Test graceful termination timing echo "โฑ๏ธ Testing termination speed..." START_TIME=$(date +%s) echo "๐Ÿ“ค Sending termination signal (scaling down)..." kubectl scale deployment $DEPLOYMENT --replicas=0 -n $NAMESPACE echo "โณ Waiting for pod to terminate..." kubectl wait --for=delete pod -l app=buildah-external -n $NAMESPACE --timeout=30s END_TIME=$(date +%s) TERMINATION_TIME=$((END_TIME - START_TIME)) echo "โœ… Pod terminated in ${TERMINATION_TIME} seconds" if [ $TERMINATION_TIME -le 10 ]; then echo "๐ŸŽ‰ Excellent! Graceful termination completed quickly (โ‰ค10s)" elif [ $TERMINATION_TIME -le 30 ]; then echo "โœ… Good! Termination within acceptable time (โ‰ค30s)" else echo "โš ๏ธ Slow termination (>30s) - may need optimization" fi echo "" echo "๐Ÿ” Final deployment status:" kubectl get deployment $DEPLOYMENT -n $NAMESPACE echo "" echo "๐Ÿ“Š Termination Analysis:" echo " โฑ๏ธ Time: ${TERMINATION_TIME}s" echo " ๐ŸŽฏ Target: <10s (excellent), <30s (good)" echo " ๐Ÿ“ Method: Signal-aware bash loop with trap" echo "" if [ $TERMINATION_TIME -le 10 ]; then echo "โœ… Signal handling is working optimally!" else echo "๐Ÿ’ก Consider further optimization if needed" fi