in subfunctions/ALE_single_account.py [0:0]
def eks_logging(region_list):
"""Function to turn on logging for EKS Clusters"""
for aws_region in region_list:
logging.info("Turning on audit and authenticator logging for EKS clusters in region " + aws_region + ".")
eks = boto3.client('eks', region_name=aws_region)
try:
logging.info("ListClusters API Call")
eks_clusters = eks.list_clusters()
eks_cluster_list = eks_clusters ['clusters']
logging.info("EKS Clusters found in " + aws_region + ":")
print(eks_cluster_list)
for cluster in eks_cluster_list:
logging.info("UpdateClusterConfig API Call")
eks_activate = eks.update_cluster_config(
name=cluster,
logging={
'clusterLogging': [
{
'types': [
'audit',
],
'enabled': True
},
{
'types': [
'authenticator',
],
'enabled': True
},
]
}
)
if eks_activate['update']['status'] == 'InProgress':
logging.info(cluster + " EKS Cluster is currently updating. Status: InProgress")
elif eks_activate['update']['status'] == 'Failed':
logging.info(cluster + " EKS Cluster failed to turn on logs. Please check if you have permissions to update the logging configuration of EKS. Status: Failed")
elif eks_activate['update']['status'] == 'Cancelled':
logging.info(cluster + " EKS Cluster log update was cancelled. Status: Cancelled.")
else:
logging.info(cluster + " EKS Cluster has audit and authenticator logs turned on.")
except Exception as exception_handle:
logging.error(exception_handle)