Exemplo n.º 1
0
def ensure_deployment(api: client.AppsV1Api, deployment, namespace, name):
    if len(
            api.list_namespaced_deployment(
                namespace=namespace,
                field_selector=f'metadata.name={name}').items) == 0:
        logger.info(f'creating Deployment: {namespace}/{name}')
        api.create_namespaced_deployment(body=deployment, namespace=namespace)
    else:
        logger.info(f'Deployment exists: {namespace}/{name}')
Exemplo n.º 2
0
def create_deployment(apps_v1_api: AppsV1Api, namespace, body) -> str:
    """
    Create a deployment based on a dict.

    :param apps_v1_api: AppsV1Api
    :param namespace: namespace name
    :param body: dict
    :return: str
    """
    print("Create a deployment:")
    apps_v1_api.create_namespaced_deployment(namespace, body)
    print(f"Deployment created with name '{body['metadata']['name']}'")
    return body['metadata']['name']
Exemplo n.º 3
0
def upsert(client: AppsV1Api, log: BoundLogger, namespace: V1Namespace,
           dep: V1Deployment) -> V1Deployment:
    existing_dep = get(client, log, namespace, dep)
    return common_k8s.upsert_resource(
        existing_dep, dep, log, 'deployment',
        lambda: client.create_namespaced_deployment(
            body=dep, namespace=namespace.metadata.name),
        lambda: client.patch_namespaced_deployment(
            existing_dep.metadata.name, namespace.metadata.name, dep))
def create_deployment(api_instance: AppsV1Api, deployment: V1Deployment, namespace: str) -> None:
    """
    Instantiate the deployment.
    :param api_instance: The api instance.
    :param deployment: The deployment setup.
    :param namespace: The namespace in which the pods are deployed.
    """
    api_response = api_instance.create_namespaced_deployment(
        body=deployment,
        namespace=namespace)
    print("Deployment created.\n status=\n'%s'" % str(api_response.status))