Skip to content

Conversation

@oharan2
Copy link
Collaborator

@oharan2 oharan2 commented Apr 24, 2025

Main changes:

  • Make filtering more strict by deselecting a group of cluster-related resources if one of them has recently modified
  • Update Dockerfile to install the openshift-installer, for local env check if exists
  • Update cli with a --yes, -y flag to bypass prompt questions before cluster destroying
    • Otherwise handle user input with [Y/N]
  • Added LeftoverAWSOcp class that holds OCP cluster with all it's collected metadata and filtered resources
    • Modified other oop hirarchy for OCP cleanup
  • Write down a temp metadata file as an input for the installer:
    • Get the most accurate metadata by extracting OCP's resources tags
  • Update the dry run log with printing the names of the OCP clusters with associated leftovers found:
    image

@oharan2 oharan2 force-pushed the delete_installer branch 2 times, most recently from a232acb to b2bd7e6 Compare April 29, 2025 11:34
@jyejare jyejare marked this pull request as draft May 5, 2025 12:25
@oharan2 oharan2 changed the title WIP: Delete OCP cluster leftovers using openshift-installer Delete OCP cluster leftovers using openshift-installer May 8, 2025
@oharan2 oharan2 force-pushed the delete_installer branch from 0fa041f to 2cffbe6 Compare May 9, 2025 14:58
@oharan2 oharan2 marked this pull request as ready for review May 9, 2025 15:01
@jyejare
Copy link
Collaborator

jyejare commented May 18, 2025

@oharan2 The checks are failing in black. Please fix

Copy link
Collaborator

@jyejare jyejare left a comment

Choose a reason for hiding this comment

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

Finishing the 1st round of review. Suggested some changes.

is_flag=True,
help="Remove only unused OCP Cluster occupied resources from the provider",
)
@click.option("-y", "--yes", is_flag=True, help="Answer yes to all prompts")
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we don't have choice to say no, or if we should not provide the choice, let's remove the option here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The alternative is -d, say no to all cluster deletion makes the deletion mode redundant.

In deletion mode, if not passing -y (yes to all prompts), you can go cluster by cluster and decide which one to clean up.
Therefore you're in deletion mode, but you can safely exclude some of it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the framework that Cloudwash comes up with for excluding is to have the resource in exceptions list. That means the user has to pre-choose the clusters that user dont want to delete resources from.

Can we move to exceptions mode, How that would impact your use case ?

"DISCS": {"delete": []},
"PIPS": {"delete": []},
"OCPS": {"delete": []},
"OCPS": {"delete": [], "clusters": []},
Copy link
Collaborator

Choose a reason for hiding this comment

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

As per the cloudwash design 'clusters' must be part of delete dict

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What the part that you concern will be breaking?
The clusters part is only for producing a dry run report with printing the actual ocp names that the resources are associated with.
The deletable part that is considered is individual resources and not entire clusters.
See use of generated report in the pic inside the updated PR description.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yup, Got that But again the clusters are nothing but resources, we just changing its place from independent key-value to within the standard dictionary structure.

Saying this because we will be streamlining the dry data printing in future by having its own Class and hence good to keep the standard going fwd.



def destroy_ocp_cluster(metadata_path: str, cluster_name: str):
if metadata_path == "" or not os.path.exists(metadata_path):
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can choose to use Pathlib to play with file system.

Optional!

# Return without raising exception, will try to fetch next OCP cluster info
logger.error(f"Failed to load cluster info from metadata path: {metadata_path}.")
else:
err_msg = f"Failed to cleanup OCP cluster {cluster_name}. Failure info:"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Define this where it's needed, it's bit confusing 😔

logger.error(f"{err_msg}\n{ex}")


def validate_deletion_with_user_input(cluster_name) -> bool:
Copy link
Collaborator

Choose a reason for hiding this comment

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

The user input in automated resources cleanup is almost impossible.

Would you still want to go ahead ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct. This is why we have to provide the cli option -y for automated cleanups, the alternative is -d (see comment above)

@oharan2 oharan2 requested a review from jyejare May 20, 2025 12:20
Copy link
Collaborator

@jyejare jyejare left a comment

Choose a reason for hiding this comment

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

Few more structural and consistency comments.

Also, Did you find the chance to run the changes on multi-clusters for multi type resources.

is_flag=True,
help="Remove only unused OCP Cluster occupied resources from the provider",
)
@click.option("-y", "--yes", is_flag=True, help="Answer yes to all prompts")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the framework that Cloudwash comes up with for excluding is to have the resource in exceptions list. That means the user has to pre-choose the clusters that user dont want to delete resources from.

Can we move to exceptions mode, How that would impact your use case ?

"DISCS": {"delete": []},
"PIPS": {"delete": []},
"OCPS": {"delete": []},
"OCPS": {"delete": [], "clusters": []},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yup, Got that But again the clusters are nothing but resources, we just changing its place from independent key-value to within the standard dictionary structure.

Saying this because we will be streamlining the dry data printing in future by having its own Class and hence good to keep the standard going fwd.

print(f'Error: Input {user_input} unrecognised. Please try again.')


def destroy_ocp_cluster_wrapper(metadata_path: str, cluster_name: str, user_validation=False):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Docstring please, maybe for all the functions here, may be autogenerate :)

self.client = client
self._delete = []
def __init__(self):
self._deletable = {"ocp_clusters": [], "filtered_leftovers": []}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think its good to be consistant with var names, That is self_delete = {}

def __init__(self, client):
self.client = client
self.cleaning_region = self.client.cleaning_region
super().__init__()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesnt seems to be required.

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