From f5f670e5f2fe2ee6b41c3387fda131d1526e4d0d Mon Sep 17 00:00:00 2001 From: shockrah Date: Wed, 18 Dec 2024 20:11:27 -0800 Subject: [PATCH] Slowly prepping dev tool to find admin services too --- infra/vultr-kubernetes/dev/find-server.py | 30 ++++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/infra/vultr-kubernetes/dev/find-server.py b/infra/vultr-kubernetes/dev/find-server.py index 6d4f2c9..c9d416f 100644 --- a/infra/vultr-kubernetes/dev/find-server.py +++ b/infra/vultr-kubernetes/dev/find-server.py @@ -8,21 +8,21 @@ def get_args() -> Namespace: prog="Cluster Search Thing", description="General utility for finding resources for game server bot" ) - games = {"reflex", "minecraft", "nginx"} - parser.add_argument('-g', '--game', required=True, choices=games) + games = {"reflex", "minecraft"} + parser.add_argument('-g', '--game', required=False, choices=games) + + admin = {"health"} + parser.add_argument('-a', '--admin', required=False, choices=admin) return parser.parse_args() def k8s_api(config_path: str) -> client.api.core_v1_api.CoreV1Api: config.load_kube_config("../config.yaml") - print("Getting pod name of our game requested") return client.CoreV1Api() -if __name__ == '__main__': - args = get_args() +def get_admin_service_details(args: ArgumentParser, api: client.api.core_v1_api.CoreV1Api): + print('admin thing requested', args.admin) - # Setting up k8s stuff - api = k8s_api('../config.yaml') - +def get_game_server_ip(args: ArgumentParser, api: client.api.core_v1_api.CoreV1Api): pods = api.list_pod_for_all_namespaces(label_selector=f'app={args.game}') node_name = pods.items[0].spec.node_name @@ -36,4 +36,16 @@ if __name__ == '__main__': ipv4 = list(filter(lambda item: not re.match('[\d\.]{3}\d', item.address), node_ips))[0].address ipv6 = list(filter(lambda item: re.match('[\d\.]{3}\d', item.address), node_ips))[0].address - print(f'{args.game} --> {ipv4}:{port} ~~> {ipv6}:{port}') \ No newline at end of file + print(f'{args.game} --> {ipv4}:{port} ~~> {ipv6}:{port}') + + +if __name__ == '__main__': + args = get_args() + api = k8s_api('../config.yaml') + + if args.game: + get_game_server_ip(args, api) + + if args.admin: + get_admin_service_details(args, api) +