Skip to content

Commit 6ddda13

Browse files
fix(deploy): harden security scan, right-sizing failure tracking, and pod log checks
- Fix Lighthouse security scan exiting with code 1 in warning-only mode (set -e kills shell on npm_audit_scan return 1 before handler runs) - Apply same if/else set -e fix to npm_security_scan for robustness - Track right-sizing failures across pipe subshell via temp file; exit 1 if any deployment fails to stabilize (prevents broken deploys) - Add --tail=100 and proper quoting to check_pod_logs oc logs call - Update example.secrets MONITOR_IMAGE to internal OpenShift CLI image
1 parent 1e023dc commit 6ddda13

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,9 @@ jobs:
776776
source ../../openshift/scripts/utils/npm.sh
777777
778778
# Lighthouse security scan (warnings only - dependencies now installed)
779-
lighthouse_security_scan "." "moderate"
779+
if ! lighthouse_security_scan "." "moderate"; then
780+
echo "⚠️ Lighthouse security scan reported warnings (non-blocking)"
781+
fi
780782
781783
cd ../../
782784
echo ""

example.secrets

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ AUTH_TOKEN_DEV=secret.auth.token
99
ARTIFACTORY_PULL_SECRET_NAME=artifactory-pull-secret-name--with-credentials-must-exist-in-openshift
1010

1111
# Pod health monitor deployment controls (required)
12-
MONITOR_IMAGE=artifacts.developer.gov.bc.ca/m950-learning/cron:950003-dev
12+
# Internal OpenShift CLI image:
13+
$ Every OCP 4 Silver cluster has the cli image stream pre-installed
14+
MONITOR_IMAGE=image-registry.openshift-image-registry.svc:5000/openshift/cli:latest
1315
SERVICE_ACCOUNT=github-actions-sa
1416
ARTIFACTORY_PULL_SECRET=artifactory-m950-learning
1517

openshift/scripts/right-sizing.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ source ./openshift/scripts/_utils.sh
5151
# Initialize utility file arrays for any containerized operations
5252
initialize_utility_arrays
5353

54+
# Track failures across the pipe subshell
55+
rm -f /tmp/right-sizing-failures.txt
56+
5457
# Read the CSV file line by line to set deployment resources
5558
# based on those values
5659
tail -n +2 ./openshift/${DEPLOY_NAMESPACE}-sizing.csv | while IFS=, read -r Deployment Type PodCount MaxPods PVCCount PVCCapacity CPURequest CPULimit MemRequest MemLimit CPUScaleValue
@@ -65,7 +68,11 @@ do
6568
if [[ $PodCount -eq 0 ]]; then
6669
echo "Skipping optional / temporary resource... no pods required to be running."
6770
else
68-
scale_deployment "$Type" "$Deployment" "$PodCount" "$MaxPods"
71+
if ! scale_deployment "$Type" "$Deployment" "$PodCount" "$MaxPods"; then
72+
echo "$Type/$Deployment failed to stabilize after scaling"
73+
# Signal failure to parent shell via temp file (pipe subshell can't set vars)
74+
echo "FAILED:$Type/$Deployment" >> /tmp/right-sizing-failures.txt
75+
fi
6976

7077
# Check if MaxPods is greater than PodCount before creating the HPA
7178
if [[ $MaxPods -gt $PodCount ]]; then
@@ -75,3 +82,18 @@ do
7582
fi
7683
fi
7784
done
85+
86+
# Check for any failures that occurred in the pipe subshell
87+
if [[ -f /tmp/right-sizing-failures.txt ]]; then
88+
echo ""
89+
echo "❌ RIGHT-SIZING FAILURES DETECTED:"
90+
cat /tmp/right-sizing-failures.txt
91+
echo ""
92+
echo "⚠️ Some resources failed to stabilize after scaling."
93+
echo " The site should NOT exit maintenance mode until these are resolved."
94+
rm -f /tmp/right-sizing-failures.txt
95+
exit 1
96+
fi
97+
98+
rm -f /tmp/right-sizing-failures.txt
99+
echo "✅ Right-sizing completed successfully."

openshift/scripts/utils/npm.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,14 @@ lighthouse_security_scan() {
3232
local overall_status="PASS"
3333

3434
# Run NPM audit (primary security check)
35-
npm_audit_scan "$project_dir" "$audit_level" "audit_result"
36-
local audit_exit=$?
35+
# Use if/else as it's the only reliable set -e suppression pattern in bash 5.x.
36+
# The cmd || var=$? pattern has edge cases with nested function returns.
37+
local audit_exit=0
38+
if npm_audit_scan "$project_dir" "$audit_level" "audit_result"; then
39+
audit_exit=0
40+
else
41+
audit_exit=$?
42+
fi
3743

3844
# Determine status but always continue (warning-only)
3945
if [ "$audit_result" = "CRITICAL" ]; then
@@ -163,8 +169,13 @@ npm_security_scan() {
163169
local overall_status="PASS"
164170

165171
# Run NPM audit (now our primary security check)
166-
npm_audit_scan "$project_dir" "$audit_level" "audit_result"
167-
local audit_exit=$?
172+
# Use if/else — the only reliable set -e suppression pattern in bash 5.x.
173+
local audit_exit=0
174+
if npm_audit_scan "$project_dir" "$audit_level" "audit_result"; then
175+
audit_exit=0
176+
else
177+
audit_exit=$?
178+
fi
168179

169180
# Determine overall status based on audit results
170181
if [ "$audit_result" = "CRITICAL" ]; then

openshift/scripts/utils/openshift.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,7 @@ check_pod_logs() {
13261326
local error_search_strings=${3:-"error"}
13271327
local error_handler=${4:-delete_pod}
13281328
local log_file="/tmp/logs/check-pod-logs.log"
1329+
local tail_lines=${5:-100} # Only check recent logs to avoid startup noise
13291330

13301331
# Split the error_search_strings into an array
13311332
IFS=',' read -r -a error_strings <<< "$error_search_strings"
@@ -1341,7 +1342,7 @@ check_pod_logs() {
13411342
IFS=' ' read -r -a container_array <<< "$CONTAINERS"
13421343

13431344
for container in "${container_array[@]}"; do
1344-
LOGS=$(oc logs $pod -n $namespace -c $container)
1345+
LOGS=$(oc logs "$pod" -n "$namespace" -c "$container" --tail="$tail_lines")
13451346

13461347
for error_search_string in "${error_strings[@]}"; do
13471348
if echo "$LOGS" | grep -q "$error_search_string"; then

0 commit comments

Comments
 (0)