Ejemplo n.º 1
0
def patch_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("Patch a deployment:")
    apps_v1_api.patch_namespaced_deployment(body["metadata"]["name"], namespace, body)
    print(f"Deployment patched with name '{body['metadata']['name']}'")
    return body["metadata"]["name"]
Ejemplo n.º 2
0
def update_no_replicas_in_deployment(
        whac_config: WhacConfig,
        apps_v1: AppsV1Api,
        new_no_replicas: int,
) -> None:
    """
    Update our deployment
    :param whac_config: All the static configurations required to run are in this instance.
    :param apps_v1: The api instance.
    :param new_no_replicas: the new number of replicas
    """
    list_of_mole_deployment = get_all_deployments(
        apps_v1=apps_v1, deployment_filter=whac_config.deployment_name_mole)

    if len(list_of_mole_deployment) == 0:
        return None

    the_mole_deployment = list_of_mole_deployment[0]

    # Update no replicas image
    the_mole_deployment.spec.replicas = new_no_replicas
    # Update the deployment
    api_response = apps_v1.patch_namespaced_deployment(
        name=whac_config.deployment_name_mole,
        namespace=whac_config.namespace,
        body=the_mole_deployment)
    print("Deployment updated.\n status=\n'%s'" % str(api_response.status))
Ejemplo 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))