Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unified/Simplified Cloud Provider Cleanup and Resource Types #126

Merged
merged 2 commits into from
Mar 13, 2024

Conversation

jyejare
Copy link
Collaborator

@jyejare jyejare commented Feb 9, 2024

Multiple Changes that simplifies contribution now:

  • The Dry run setting is now available directly from settings globally, hence need not to pass the context in click subcommands. (But we need to until we do translate all cloud providers and resource types in new code standards)
  • New entities/providers.py module contains the base class providerCleanup that holds the resource_type properties for all common resource types. Also contains the individual cloud provider class for non-common resource types for that cloud specific resource type.
  • New entitites/resources package contains the modules for every resource type for all the cloud providers. Those resource type modules contains a common base class and common functions applicable for all cloud providers and could be overridden from individual cloud provider resource type class.
  • Now providers packages cloud provider module just imports the cleanup class for that cloud provider. And then the applicable resource types properties would be called for cleanup easily.
    e.g from cloudwash.entities.providers import AWSCleanup; awscleanup= AWSCleanup(client=aws_client); awscleanup.vms.cleanup(); awscleanup.discs.cleanup(), Same example applies for all other cloudproviders.

@jyejare jyejare force-pushed the unified_cleanup_funcs branch from 94b0a68 to 208cf47 Compare February 19, 2024 11:58
@jyejare jyejare force-pushed the unified_cleanup_funcs branch from 208cf47 to c4e406e Compare February 21, 2024 08:02
@jyejare jyejare changed the title Unified Cloud Provider Cleanup and Resource Types Unified/Simplified Cloud Provider Cleanup and Resource Types Feb 21, 2024
Comment on lines +11 to +17
@property
def vms(self):
providerclass = self.__class__.__name__
if 'Azure' in providerclass:
return CleanAzureVMs(client=self.client)
elif 'AWS' in providerclass:
return CleanAWSVms(client=self.client)
Copy link
Contributor

Choose a reason for hiding this comment

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

@jyejare one more approach to solve this to remove more coupling and adding more providers and reduce the factory pattern made in parent class. let me know what you think about it

class ProviderCleanup:
    def __init__(self, client, vm_cleaner, disc_cleaner):
        self.client = client
        self.vm_cleaner = vm_cleaner
        self.disc_cleaner = disc_cleaner

    def vms(self):
        return self.vm_cleaner.clean(self.client)

    def discs(self):
        return self.disc_cleaner.clean(self.client)


class AzureCleanup(ProviderCleanup):
    def __init__(self, client):
        super().__init__(client, CleanAzureVMs(), CleanAzureDiscs())


class AWSCleanup(ProviderCleanup):
    def __init__(self, client):
        super().__init__(client, CleanAWSVms(), CleanAWSDiscs())

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm!

I see multiple issues in this pattern:

  1. Unnecessary Object Initialization of CloudProviderResourceType classes (e.g CleanAzureVMs(client), CleanAzureDiscs(client)) even though its not demanded! That also takes a huge time for all classes initialization. For now its the object creation is on demand and explicit if its demanded!
  2. The list of parameters will increase in endless number as and when number of resource types will grow. Though we can control it with kwargs, but its extra layer of verification if the object is available in params.
  3. In current design, if the non-common resource type property is needed to be added then you can do it at that cloud provider class level and dont need to send it back to base class for processing / returning.

For now, I can only think of these issues! Feel free to reply with the thoughts !

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, I ack it.

def __init__(self, client):
self.client = client
self._delete = []
self.list()
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure how this is working ? is that intentional ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes it is intentional. As soon as the class is initiated the listing should happen and all dry data must be updated for viewing without calling the explicit cleanup() method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This also helps in if user just wanted to list / stop or any other method without actually cleaning it or calling that function !

Copy link
Contributor

@omkarkhatavkar omkarkhatavkar left a comment

Choose a reason for hiding this comment

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

ACK

@omkarkhatavkar omkarkhatavkar merged commit 0192d4e into RedHatQE:develop Mar 13, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants