-
Notifications
You must be signed in to change notification settings - Fork 81
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
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Andrej Podhradsky <apodhrad@redhat.com>
@@ -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) |
There was a problem hiding this comment.
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 😆
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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"] |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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/"): |
There was a problem hiding this comment.
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
There was a problem hiding this 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!
Thanks for the review! I will apply your suggestions everywhere it is possible. |
@apodhrad Ping ! Do you need any help with this PR ? |
@apodhrad Ping again! |
to me it seems that this PR is outdated in favor of |
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 |
Signed-off-by: Andrej Podhradsky apodhrad@redhat.com