Skip to content

[SAR] APPENG-5150: Add --purge-data flag to cleanup script#201

Open
yuvalk wants to merge 1 commit into
RHEcosystemAppEng:mainfrom
yuvalk:fix/APPENG-5150-cleanup-data-purge
Open

[SAR] APPENG-5150: Add --purge-data flag to cleanup script#201
yuvalk wants to merge 1 commit into
RHEcosystemAppEng:mainfrom
yuvalk:fix/APPENG-5150-cleanup-data-purge

Conversation

@yuvalk
Copy link
Copy Markdown
Collaborator

@yuvalk yuvalk commented May 6, 2026

Summary

Addresses APPENG-5150.

Add an optional --purge-data flag to the Cloud Run cleanup script that enables deletion of CloudSQL instances and lists Redis instances for manual cleanup. Without the flag, data resources are preserved (existing behavior unchanged).

Changes

  • Add --purge-data CLI argument to deploy/cloudrun/cleanup.sh
  • Add CloudSQL instance deletion loop (filtered by name~lightspeed) when flag is set
  • Add Redis instance listing for manual cleanup awareness
  • Update usage comments and "not deleted" notice to reference the new flag

SAR Reference

  • CWE: CWE-212 (Improper Removal of Sensitive Information Before Storage or Transfer)
  • Impact: Low

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

Add an optional --purge-data flag to the Cloud Run cleanup script that
deletes CloudSQL instances matching 'lightspeed' and lists Redis
instances for manual deletion. Without the flag, data resources are
preserved (existing behavior). This ensures data is not accidentally
deleted during routine cleanup while providing an explicit purge option.

- Add --purge-data CLI argument parsing
- Add CloudSQL instance deletion loop when flag is set
- Add Redis instance listing for manual cleanup
- Update help text and 'not deleted' notice to reference --purge-data

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@luis5tb luis5tb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Collaborator

@luis5tb luis5tb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Summary

Critical (1)

1. Purge block runs after "Cleanup complete!" banner [cleanup.sh:275-290]

The --purge-data block executes after the "Cleanup complete!" message (line 264). If a CloudSQL deletion fails or hangs, the user already saw "complete." The purge should run as a new step section (e.g., "Step 5") before the summary block.

Important (3)

2. Confirmation prompt doesn't warn about data destruction [cleanup.sh:80-99]

The confirmation at line 93 lists services, secrets, Pub/Sub, and service accounts — but never mentions CloudSQL or data destruction when --purge-data is set. Running ./cleanup.sh --force --purge-data deletes databases with zero data-specific warning. The confirmation should include a line like " - CloudSQL instances matching 'lightspeed' (IRREVERSIBLE DATA LOSS)" when PURGE_DATA=true, or add a second confirmation specifically for the purge.

3. Misleading comment: # Flush Redis data [cleanup.sh:285]

The code doesn't flush anything; it lists instances with a "delete manually" note. The comment should say # List Redis instances for manual cleanup.

4. Missing indentation inside if block [cleanup.sh:293-296]

The echo lines inside if [ "$PURGE_DATA" != true ] are not indented, breaking the script's consistent 4-space indentation style:

if [ "$PURGE_DATA" != true ]; then
echo "  - Cloud SQL instances (use --purge-data to delete)"   # <-- should be indented
echo "  - Cloud Memorystore Redis instances (use --purge-data to delete)"  # <-- same
fi

Suggestions (3)

5. Options header says "Redis data" but Redis isn't deleted [cleanup.sh:12]

--purge-data Also delete CloudSQL instances and Redis data implies Redis gets deleted, but the code only prints a manual-cleanup notice. Suggest: --purge-data Also delete CloudSQL instances (lists Redis for manual cleanup).

6. Regex filter could be narrower [cleanup.sh:280]

name~lightspeed could match unintended instances. Consider anchoring (name~^lightspeed) or using the existing DB_INSTANCE_NAME variable for an exact match.

7. Log warnings on CloudSQL delete failure [cleanup.sh:281]

|| true prevents script abort (good), but silently hides errors. Consider adding a log_warn on failure for observability.

Strengths

  • Backwards-compatible: existing behavior unchanged without the flag
  • Argument parsing follows the established pattern cleanly
  • || true on CloudSQL delete prevents the script from aborting mid-loop
  • 2>/dev/null on list commands handles disabled APIs gracefully
  • Good use of --quiet to suppress interactive gcloud prompts

🤖 Generated with Claude Code

@luis5tb
Copy link
Copy Markdown
Collaborator

luis5tb commented May 8, 2026

suggested fixes at yuvalk#4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants