def ensure_service(api: client.CoreV1Api, service, namespace, name): if len( api.list_namespaced_service( namespace=namespace, field_selector=f'metadata.name={name}').items) == 0: logger.info(f'creating Service: {namespace}/{name}') api.create_namespaced_service(body=service, namespace=namespace) else: logger.info(f'Service exists: {namespace}/{name}')
def create_service(v1: CoreV1Api, namespace, body) -> str: """ Create a service based on a dict. :param v1: CoreV1Api :param namespace: namespace :param body: a dict :return: str """ print("Create a Service:") resp = v1.create_namespaced_service(namespace, body) print(f"Service created with name '{body['metadata']['name']}'") return resp.metadata.name
def create_service(v1: CoreV1Api, namespace, body) -> str: """ Create a service based on a dict. :param v1: CoreV1Api :param namespace: namespace :param body: a dict :return: str """ print("Create a Service:") resp = v1.create_namespaced_service(namespace, body) print(f"Service created with name '{body['metadata']['name']}'") return resp.metadata.name