Created
June 24, 2020 13:08
-
-
Save Szymongib/db3a142a2d5cefd37196be0d0f215e3c to your computer and use it in GitHub Desktop.
List all Shoots from Gardener project with corresponding runtime id and account id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import base64 | |
import json | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-c", "--serviceaccount", help="Gardener service account key path") | |
parser.add_argument("-p", "--project", help="Gardener Project") | |
parser.add_argument("-o", "--output", help="Output Type", default="") | |
args = parser.parse_args() | |
# Set kubeconfig env and init client | |
os.environ["KUBECONFIG"] = args.serviceaccount | |
from kubernetes import client, config | |
config.load_kube_config() | |
namespace = f"garden-{args.project}" | |
api = client.CustomObjectsApi() | |
shoot_list = api.list_namespaced_custom_object( | |
group="core.gardener.cloud", | |
version="v1beta1", | |
namespace=namespace, | |
plural="shoots", | |
) | |
shoots = { | |
"items": [] | |
} | |
for shoot in shoot_list['items']: | |
shoots['items'].append({ | |
"name": shoot['metadata']['name'], | |
"runtime_id": shoot['metadata']['annotations']['compass.provisioner.kyma-project.io/runtime-id'], | |
"account": shoot['metadata']['labels']['account'] | |
}) | |
if args.output.lower() == "json": | |
print(json.dumps(shoots)) | |
else: | |
print("Runtime Id Account Shoot name") | |
for s in shoots['items']: | |
print(f"{s['runtime_id']} {s['account']} {s['name']}") | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## This file contains exmaple usage in bash script | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | |
source ${DIR}/env | |
python3 ${DIR}/scripts/gardener_clusters.py -c $GARDENER_SERVICE_ACCOUNT_PATH -p $PROJECT $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment