def get_service_node_ports(v1: CoreV1Api, name, namespace) -> (int, int, int, int, int, int): """ Get service allocated node_ports. :param v1: CoreV1Api :param name: :param namespace: :return: (plain_port, ssl_port, api_port, exporter_port) """ resp = v1.read_namespaced_service(name, namespace) if len(resp.spec.ports) == 6: print( "An unexpected amount of ports in a service. Check the configuration" ) print(f"Service with an API port: {resp.spec.ports[2].node_port}") print(f"Service with an Exporter port: {resp.spec.ports[3].node_port}") return ( resp.spec.ports[0].node_port, resp.spec.ports[1].node_port, resp.spec.ports[2].node_port, resp.spec.ports[3].node_port, resp.spec.ports[4].node_port, resp.spec.ports[5].node_port, )
def read_service(v1: CoreV1Api, name, namespace) -> V1Service: """ Get details of a Service. :param v1: CoreV1Api :param name: service name :param namespace: namespace name :return: V1Service """ print(f"Read a service named '{name}'") return v1.read_namespaced_service(name, namespace)
def get_service_node_ports(v1: CoreV1Api, name, namespace) -> (str, str): """ Get service allocated node_ports. :param v1: CoreV1Api :param name: :param namespace: :return: (plain_port, ssl_port) """ resp = v1.read_namespaced_service(name, namespace) assert len(resp.spec.ports) == 2, "There are not enough ports assigned to a service" return resp.spec.ports[0].node_port, resp.spec.ports[1].node_port
def get_service_node_ports(v1: CoreV1Api, name, namespace) -> (str, str): """ Get service allocated node_ports. :param v1: CoreV1Api :param name: :param namespace: :return: (plain_port, ssl_port) """ resp = v1.read_namespaced_service(name, namespace) assert len(resp.spec.ports) == 2, "There are not enough ports assigned to a service" return resp.spec.ports[0].node_port, resp.spec.ports[1].node_port