-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
||
self.kwargs = kwargs | ||
|
||
|
@@ -1595,3 +1596,41 @@ def cleanup_resources(self): | |
self.remove_all_unused_nics() | ||
self.remove_all_unused_volumes() | ||
self.remove_all_unused_ips() | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Why limit the return to clusters with this metadata? |
||
""" | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. No need to label |
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. The GetResources endpoint supports https://docs.aws.amazon.com/resourcegroupstagging/latest/APIReference/API_GetResources.html |
||
ocp = None | ||
ocp_name = key[22:] | ||
for ocp_item in ocp_list: | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Consider using for/else syntax here, removes the need to initalize |
||
ocp = { | ||
"name": ocp_name, | ||
"metadata": { | ||
"clusterName": ocp_name, | ||
"infraID": ocp_name, | ||
"aws": { | ||
"region": self._region_name, | ||
"identifier": [ | ||
{ | ||
"kubernetes.io/cluster/" + ocp_name: "owned" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use f-strings for concatenation |
||
} | ||
] | ||
} | ||
}, | ||
"resources": [] | ||
} | ||
ocp_list.append(ocp) | ||
ocp["resources"].append(resource) | ||
return ocp_list |
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.