From b61ea6e718346aca019025c86fba47312afbbeff Mon Sep 17 00:00:00 2001 From: Chris Collins Date: Mon, 2 Feb 2026 15:52:49 -1000 Subject: [PATCH] Improve log clarity for delete-olm-operator dry-run mode During incident response, SREs ran the delete-olm-operator job without the FORCE=y parameter and incorrectly assumed the job had completed its work when it was only describing what would be deleted. This led to operational confusion and extended incident duration. Changes: - Add prominent dry-run mode banner at script start - Prefix all dry-run messages with [DRY-RUN] - Change "Will delete" to "Would delete" to clarify hypothetical actions - Add final summary banner for both dry-run and execution modes - Include clear instructions to execute with --params FORCE=y These changes make it immediately obvious whether the script is running in dry-run mode or actually executing deletions, preventing operational mistakes during incident response. Related: https://issues.redhat.com/browse/SREP-3321 Co-Authored-By: Claude Sonnet 4.5 --- .../delete-olm-operator/script.sh | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/scripts/operators-lifecycle/delete-olm-operator/script.sh b/scripts/operators-lifecycle/delete-olm-operator/script.sh index 598b2138..04c63211 100644 --- a/scripts/operators-lifecycle/delete-olm-operator/script.sh +++ b/scripts/operators-lifecycle/delete-olm-operator/script.sh @@ -17,7 +17,18 @@ if [[ "${NAMESPACE}" != openshift-* && "${NAMESPACE}" != redhat-* ]]; then exit "${ERR_INVALID_NS}" fi -"$DELETE" || echo "Not going to delete resources" +if ! $DELETE; then + echo "========================================" + echo " DRY-RUN MODE - NO CHANGES " + echo "========================================" + echo "This script is running in DRY-RUN mode." + echo "NO resources will be deleted." + echo "" + echo "To execute deletions, re-run with:" + echo " --params FORCE=y" + echo "========================================" + echo "" +fi SUBSCRIPTION_SAVED=$(oc get subscriptions.operators.coreos.com -n "${NAMESPACE}" -ojson | jq -r 'del(.items[].metadata.annotations."kubectl.kubernetes.io/last-applied-configuration")') SUBSCRIPTION=$(oc get subscriptions.operators.coreos.com -n "${NAMESPACE}" -o jsonpath='{.items[*].metadata.name}') @@ -41,12 +52,12 @@ if $DELETE; then oc delete operatorgroups.operators.coreos.com "${OPERATOR_GROUP}" -n "${NAMESPACE}" fi else - echo "Will delete Subscription: ${SUBSCRIPTION}" - echo "Will delete CatalogSource: ${CATALOG_SOURCE}" - echo "Will delete OperatorGroup: ${OPERATOR_GROUP}" + echo "[DRY-RUN] Would delete Subscription: ${SUBSCRIPTION}" + echo "[DRY-RUN] Would delete CatalogSource: ${CATALOG_SOURCE}" + echo "[DRY-RUN] Would delete OperatorGroup: ${OPERATOR_GROUP}" fi -"${DELETE}" || echo "Will delete CSVs:" +"${DELETE}" || echo "[DRY-RUN] Would delete the following CSVs:" for csv in $(oc get clusterserviceversions.operators.coreos.com -n "${NAMESPACE}" -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}') do if "${DELETE}"; then @@ -72,3 +83,21 @@ if "${DELETE}"; then echo "${OPERATOR_GROUP_SAVED}" | oc create -f - fi fi + +echo "" +if $DELETE; then + echo "========================================" + echo " DELETION COMPLETED SUCCESSFULLY " + echo "========================================" + echo "All OLM resources have been deleted and recreated." + echo "========================================" +else + echo "========================================" + echo " DRY-RUN COMPLETED " + echo "========================================" + echo "No resources were deleted." + echo "" + echo "To execute these deletions, re-run with:" + echo " --params FORCE=y" + echo "========================================" +fi