import os import sys import boto3 from kubernetes import client, config ec2client = boto3.client('ec2') response = ec2client.describe_nat_gateways() nats = [] for nat in response["NatGateways"]: tags = nat['Tags'] name = "" for tag in tags: if tag['Key'] == 'Name': name = tag['Value'] # print(name) if name != '': nats.append(name) print(len(nats)) print(nats) shootName = [] config.kube_config.load_kube_config(config_file="/home/gardener-dev") apiClient = client.CoreV1Api() namespaces = apiClient.list_namespace() shootClient = client.CustomObjectsApi() for ns in namespaces.items: shoots = shootClient.list_namespaced_custom_object( group="core.gardener.cloud", version="v1beta1", namespace=ns.metadata.name, plural="shoots", ) ns = ns.metadata.name.replace("garden-","") for shoot in shoots['items']: cloudType = shoot['spec']['cloudProfileName'].encode('ascii','ignore') name = shoot["metadata"]["name"].encode('ascii','ignore') if cloudType == "aws": shootName.append("shoot--" + ns + "--" + name) config.kube_config.load_kube_config(config_file="/home/gardener-staging") apiClient = client.CoreV1Api() namespaces = apiClient.list_namespace() shootClient = client.CustomObjectsApi() for ns in namespaces.items: shoots = shootClient.list_namespaced_custom_object( group="core.gardener.cloud", version="v1beta1", namespace=ns.metadata.name, plural="shoots", ) ns = ns.metadata.name.replace("garden-","") for shoot in shoots['items']: cloudType = shoot['spec']['cloudProfileName'].encode('ascii','ignore') name = shoot["metadata"]["name"].encode('ascii','ignore') if cloudType == "aws": shootName.append("shoot--" + ns + "--" + name) config.kube_config.load_kube_config(config_file="/home/gardener-stability") apiClient = client.CoreV1Api() namespaces = apiClient.list_namespace() shootClient = client.CustomObjectsApi() for ns in namespaces.items: shoots = shootClient.list_namespaced_custom_object( group="core.gardener.cloud", version="v1beta1", namespace=ns.metadata.name, plural="shoots", ) ns = ns.metadata.name.replace("garden-","") for shoot in shoots['items']: cloudType = shoot['spec']['cloudProfileName'].encode('ascii','ignore') name = shoot["metadata"]["name"].encode('ascii','ignore') if cloudType == "aws": shootName.append("shoot--" + ns + "--" + name) print(len(shootName)) print(shootName) leakNats = [] for nat in nats: found = False for shoot in shootName: if shoot in nat: found = True break if not found: leakNats.append(nat) print("leaked nats:", len(leakNats)) print("leaked nats:", leakNats)