Fixing port finding script
Some checks failed
Ansible Linting / ansible-lint (push) Failing after 3s
Secops Linting and Safety Checks / checkov-scan-s3 (push) Failing after 16s

This commit is contained in:
shockrah 2024-12-10 17:59:48 -08:00
parent 7f2ee6d35b
commit 5d03f6b218

View File

@ -22,15 +22,16 @@ if __name__ == '__main__':
# Setting up k8s stuff # Setting up k8s stuff
api = k8s_api('../config.yaml') api = k8s_api('../config.yaml')
print(type(api))
pods = api.list_pod_for_all_namespaces(label_selector=f'app={args.game}')
# Now we collect specific data about the game server we requested pods = api.list_pod_for_all_namespaces(label_selector=f'app={args.game}')
port = pods.items[0].spec.containers[0].ports[0].container_port node_name = pods.items[0].spec.node_name
services = api.list_service_for_all_namespaces(label_selector=f'app={args.game}')
port = services.items[0].spec.ports[0].port
# Collecting the IPV4 of the node that contains the pod(container) # Collecting the IPV4 of the node that contains the pod(container)
# we actually care about. Since these pods only have 1 container # we actually care about. Since these pods only have 1 container
node_name = pods.items[0].spec.node_name # Now we collect specific data about the game server we requested
node_ips = list(filter(lambda a: a.type == 'ExternalIP', api.list_node().items[0].status.addresses)) node_ips = list(filter(lambda a: a.type == 'ExternalIP', api.list_node().items[0].status.addresses))
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