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

List OCP clusters in EC2 #455

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

apodhrad
Copy link
Contributor

Signed-off-by: Andrej Podhradsky [email protected]

Signed-off-by: Andrej Podhradsky <[email protected]>
@@ -506,6 +506,7 @@ def __init__(self, **kwargs):
self.ssm_connection = boto3client('ssm', **connection_kwargs)
self.sns_connection = boto3client('sns', **connection_kwargs)
self.cw_events_connection = boto3client('events', **connection_kwargs)
self.resourcegroupstaggingapi_connection = boto3client('resourcegroupstaggingapi', **connection_kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's a heck of an endpoint name 😆

Copy link
Collaborator

Choose a reason for hiding this comment

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

btw not at all suggesting you change it - its consistent, and is exactly what it should be. It's just ... verbose.

"region": self._region_name,
"identifier": [
{
"kubernetes.io/cluster/" + ocp_name: "owned"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use f-strings for concatenation

if ocp_item["name"] == ocp_name:
ocp = ocp_item
break
if not ocp:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider using for/else syntax here, removes the need to initalize ocp and you're already using a break.

ocp_list = []
resources = self.resourcegroupstaggingapi_connection.get_resources()["ResourceTagMappingList"]
for resource in resources:
tags = resource["Tags"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to label tags here if its only used in the for statement, just reference resource['Tags'] directly


def list_ocps(self):
"""
List openshift clusters (name, metadata, resources) where metadata can be used for uninstalling the cluster
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why limit the return to clusters with this metadata?

tags = resource["Tags"]
for tag in tags:
key = tag["Key"]
if key.startswith("kubernetes.io/cluster/"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

The GetResources endpoint supports TagFilters, and you can use a key regex expression to limit the response to only resources with this tag. Then you don't have to iterate so much here, and can directly fetch the objects that you want and parse their cluster key.

https://docs.aws.amazon.com/resourcegroupstagging/latest/APIReference/API_GetResources.html
https://docs.aws.amazon.com/resourcegroupstagging/latest/APIReference/API_TagFilter.html

Copy link
Collaborator

@mshriver mshriver left a comment

Choose a reason for hiding this comment

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

Couple things to discuss, the function could use some more explicit docs to describe the intended filtering/exclusion/inclusion that is happening, and why. Consider broader uses than your intent for cloudwash cleanup, and maybe move the metadata/tags restriction to a kwarg so the caller can more broadly list OCP clusters.

Thanks so much for adding to the functionality of wrapanapi!

@apodhrad
Copy link
Contributor Author

Thanks for the review! I will apply your suggestions everywhere it is possible.
I need to double check the usage of key regex in TagFilters and let you know.

@jyejare
Copy link
Contributor

jyejare commented Sep 6, 2022

@apodhrad Ping ! Do you need any help with this PR ?

@jyejare
Copy link
Contributor

jyejare commented Sep 15, 2022

@apodhrad Ping again!

@laDok8
Copy link
Contributor

laDok8 commented Jan 5, 2024

to me it seems that this PR is outdated in favor of list_resources API

@apodhrad
Copy link
Contributor Author

apodhrad commented Jan 5, 2024

I think this PR will be replaced by another (better) PR. @oharan2 could you provide more details if we can close this PR, please?

@oharan2
Copy link
Contributor

oharan2 commented Feb 6, 2024

I think this PR will be replaced by another (better) PR. @oharan2 could you provide more details if we can close this PR, please?

This PR can be closed and replaced by me with new changes rebased on top of @apodhrad work.

Note: This PR sets the approach of using the resourcegroupstaggingapi client, which is still backlog on my end. We're working on completing #18 (using AWS Resouce Explorer).

@jyejare
Copy link
Contributor

jyejare commented Feb 7, 2024

@apodhrad @oharan2 Feel free to close this one and create fresh new PR including changes in this PR(as you wanted to).
OR
you could also push to this PR without closing this one to preserve the review history.

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.

5 participants