Slowly prepping dev tool to find admin services too
Some checks failed
Ansible Linting / ansible-lint (push) Failing after 6s
Secops Linting and Safety Checks / checkov-scan-s3 (push) Failing after 18s

This commit is contained in:
shockrah 2024-12-18 20:11:27 -08:00
parent 6d642a7359
commit f5f670e5f2

View File

@ -8,21 +8,21 @@ def get_args() -> Namespace:
prog="Cluster Search Thing", prog="Cluster Search Thing",
description="General utility for finding resources for game server bot" description="General utility for finding resources for game server bot"
) )
games = {"reflex", "minecraft", "nginx"} games = {"reflex", "minecraft"}
parser.add_argument('-g', '--game', required=True, choices=games) parser.add_argument('-g', '--game', required=False, choices=games)
admin = {"health"}
parser.add_argument('-a', '--admin', required=False, choices=admin)
return parser.parse_args() return parser.parse_args()
def k8s_api(config_path: str) -> client.api.core_v1_api.CoreV1Api: def k8s_api(config_path: str) -> client.api.core_v1_api.CoreV1Api:
config.load_kube_config("../config.yaml") config.load_kube_config("../config.yaml")
print("Getting pod name of our game requested")
return client.CoreV1Api() return client.CoreV1Api()
if __name__ == '__main__': def get_admin_service_details(args: ArgumentParser, api: client.api.core_v1_api.CoreV1Api):
args = get_args() print('admin thing requested', args.admin)
# Setting up k8s stuff def get_game_server_ip(args: ArgumentParser, api: client.api.core_v1_api.CoreV1Api):
api = k8s_api('../config.yaml')
pods = api.list_pod_for_all_namespaces(label_selector=f'app={args.game}') pods = api.list_pod_for_all_namespaces(label_selector=f'app={args.game}')
node_name = pods.items[0].spec.node_name 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 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 ipv6 = list(filter(lambda item: re.match('[\d\.]{3}\d', item.address), node_ips))[0].address
print(f'{args.game} --> {ipv4}:{port} ~~> {ipv6}:{port}') 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)