Skip to content

Commit

Permalink
Merge pull request #411 from davidkutz-marks/regionhandling
Browse files Browse the repository at this point in the history
eks__enum fix
  • Loading branch information
DaveYesland authored Mar 8, 2024
2 parents 3bd8aac + 04df484 commit 170ebb1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 47 deletions.
10 changes: 5 additions & 5 deletions pacu/modules/cloudformation__download_data/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def default(self, obj):
print(f"Error: Could not enumerate region {region}")
print(f"Error: {e}")
continue
exports = client.list_exports()
if exports:
with outfile('exports', region) as (f):
json.dump(exports, f, indent=1)
find_secrets(json.dumps(exports))
exports = client.list_exports()
if exports:
with outfile('exports', region) as (f):
json.dump(exports, f, indent=1)
find_secrets(json.dumps(exports))
while 'NextToken' in stacks_data:
stacks_data = client.describe_stacks(NextToken=(stacks_data['NextToken']))
stacks += stacks_data['Stacks']
Expand Down
93 changes: 51 additions & 42 deletions pacu/modules/eks__enum/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import argparse
from botocore.exceptions import ClientError

module_info = {
'name': 'eks_enum',
Expand Down Expand Up @@ -42,52 +43,60 @@ def main(args, pacu_main):
regions = args.regions.split(',')

for region in regions:
eks_client = pacu_main.get_boto3_client('eks', region)
cluster_paginator = eks_client.get_paginator("list_clusters")
cluster_page_iterator = cluster_paginator.paginate(PaginationConfig={'PageSize': 50})
data[region] = { # use this to count clusters
"clusters": {}
}
for page in cluster_page_iterator:
clusters = page["clusters"]
for cluster in clusters:
nodegroups = []
addons = []
fargate_profiles = []
ip_configs = []
try:
eks_client = pacu_main.get_boto3_client('eks', region)
cluster_paginator = eks_client.get_paginator("list_clusters")
cluster_page_iterator = cluster_paginator.paginate(PaginationConfig={'PageSize': 50})
data[region] = { # use this to count clusters
"clusters": {}
}
for page in cluster_page_iterator:
clusters = page["clusters"]
for cluster in clusters:
nodegroups = []
addons = []
fargate_profiles = []
ip_configs = []

nodegroup_paginator = eks_client.get_paginator("list_nodegroups")
nodegroup_page_iterator = nodegroup_paginator.paginate(clusterName=cluster, PaginationConfig={'PageSize': 50})
addon_paginator = eks_client.get_paginator("list_addons")
addon_page_iterator = addon_paginator.paginate(clusterName=cluster, PaginationConfig={'PageSize': 50})
fargate_paginator = eks_client.get_paginator("list_fargate_profiles")
fargate_page_iterator = fargate_paginator.paginate(clusterName=cluster, PaginationConfig={'PageSize': 50})
ip_config_paginator = eks_client.get_paginator("list_identity_provider_configs")
ip_config_page_iterator = ip_config_paginator.paginate(clusterName=cluster, maxResults=1, PaginationConfig={'PageSize': 1})
nodegroup_paginator = eks_client.get_paginator("list_nodegroups")
nodegroup_page_iterator = nodegroup_paginator.paginate(clusterName=cluster, PaginationConfig={'PageSize': 50})
addon_paginator = eks_client.get_paginator("list_addons")
addon_page_iterator = addon_paginator.paginate(clusterName=cluster, PaginationConfig={'PageSize': 50})
fargate_paginator = eks_client.get_paginator("list_fargate_profiles")
fargate_page_iterator = fargate_paginator.paginate(clusterName=cluster, PaginationConfig={'PageSize': 50})
ip_config_paginator = eks_client.get_paginator("list_identity_provider_configs")
ip_config_page_iterator = ip_config_paginator.paginate(clusterName=cluster, maxResults=1, PaginationConfig={'PageSize': 1})

for page in nodegroup_page_iterator:
nodegroups.append(page["nodegroups"])
for page in addon_page_iterator:
addons.append(page["addons"])
for page in fargate_page_iterator:
fargate_profiles.append(page["fargateProfileNames"])
for page in ip_config_page_iterator:
ip_configs.append(page["identityProviderConfigs"])
for page in nodegroup_page_iterator:
nodegroups.append(page["nodegroups"])
for page in addon_page_iterator:
addons.append(page["addons"])
for page in fargate_page_iterator:
fargate_profiles.append(page["fargateProfileNames"])
for page in ip_config_page_iterator:
ip_configs.append(page["identityProviderConfigs"])

data[region]['clusters'][cluster] = {
"cluster_description": eks_client.describe_cluster(name=cluster)["cluster"],
"nodegroups": nodegroups
}
if not args.no_addons:
data[region]['clusters'][cluster]["addons"] = addons
if not args.no_fargate_profiles:
data[region]['clusters'][cluster]["fargate_profiles"] = fargate_profiles
# if not args.no_identity_provider_configs:
# data[region]['clusters'][cluster]["identity_provider_configs"] = ip_configs
data[region]['clusters'][cluster] = {
"cluster_description": eks_client.describe_cluster(name=cluster)["cluster"],
"nodegroups": nodegroups
}
if not args.no_addons:
data[region]['clusters'][cluster]["addons"] = addons
if not args.no_fargate_profiles:
data[region]['clusters'][cluster]["fargate_profiles"] = fargate_profiles
# if not args.no_identity_provider_configs:
# data[region]['clusters'][cluster]["identity_provider_configs"] = ip_configs

region_clusters = [cluster for cluster in data[region]["clusters"]]
print(f"clusters in {region}: {region_clusters}")
cluster_count += len(data[region]["clusters"])
region_clusters = [cluster for cluster in data[region]["clusters"]]
print(f"clusters in {region}: {region_clusters}")
cluster_count += len(data[region]["clusters"])
except ClientError as error:
code = error.response["Error"]["Code"]
if code == "AccessDeniedException":
print(f"Access denied to EKS in {region}.")
else:
print(f"Error: {error}")
continue
session.update(pacu_main.database, EKS=data)
return cluster_count

Expand Down

0 comments on commit 170ebb1

Please sign in to comment.