Skip to content

Implement OCP cluster cleanup using openshift-install#179

Open
jyejare wants to merge 1 commit into
RedHatQE:masterfrom
jyejare:ocp-cluster-cleanup
Open

Implement OCP cluster cleanup using openshift-install#179
jyejare wants to merge 1 commit into
RedHatQE:masterfrom
jyejare:ocp-cluster-cleanup

Conversation

@jyejare

@jyejare jyejare commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements full OCP cluster cleanup on AWS using the openshift-install CLI, superseding #166. This builds on the work from PR #166 by @oharan2, incorporating all review feedback.

  • LeftoverAWSOcp class to model cluster resources, extract metadata from AWS resource tags (clusterName, clusterID, infraID), and build the metadata.json required by openshift-install
  • Cleanup flow: discovers OCP-tagged resources via AWS Resource Explorer, groups by cluster infra ID, filters by SLA and exceptions, then runs openshift-install destroy cluster for each deletable cluster
  • Exceptions support via OCPS: [] in aws.yaml config (consistent with VM/Stack exception patterns) instead of interactive --yes prompts
  • Utility functions: check_installer_exists(), destroy_ocp_cluster(), write_metadata_file() with proper docstrings, pathlib usage, and specific exception handling
  • Refactored filter_resources_by_time_modifiedare_resources_older_than (returns bool, integrates time threshold calculation)
  • Dockerfile.dev updated to install openshift-install CLI under /usr/local/bin/
  • Removed dead code (delete_ocp stub, duplicated group_ocps_by_cluster from utils)
  • Moved OCP_TAG_SUBSTR and related tag constants to constants.py

Review feedback addressed from #166:

  • No --yes CLI flag — uses standard exceptions config instead (per @jyejare feedback on automated cleanup)
  • self._delete naming for consistency with other cleanup classes
  • Clusters kept inside the _delete dict structure for future dry-data standardization
  • Function renamed to match its boolean return semantics
  • pathlib.Path used for file operations
  • Docstrings added to all new functions

Supersedes #166

Test plan

  • Run swach -d aws --ocps in dry mode to verify resource discovery and filtering
  • Verify OCP cluster exceptions are respected via OCPS: [] in config
  • Run non-dry swach aws --ocps with openshift-install available to confirm cluster destruction
  • Verify multi-region scanning works correctly
  • Build Docker image from Dockerfile.dev to confirm openshift-install is available

Made with Cursor

Replace the dry-run-only OCP stub with a full cleanup implementation
that uses the openshift-install CLI to destroy leftover OCP clusters
on AWS, addressing review feedback from PR RedHatQE#166.

- Add LeftoverAWSOcp class to model cluster resources and metadata
- Add destroy_ocp_cluster/write_metadata_file/check_installer_exists utils
- Support OCP exceptions in config for cluster exclusion
- Move OCP constants to constants.py, remove dead code from utils.py
- Install openshift-install CLI in Dockerfile.dev

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

1 participant