コード例 #1
0
def scale_deployment(v1: CoreV1Api, apps_v1_api: AppsV1Api, name, namespace, value) -> int:
    """
    Scale a deployment.

    :param apps_v1_api: AppsV1Api
    :param namespace: namespace name
    :param name: deployment name
    :param value: int
    :return: original: int the original amount of replicas
    """
    body = apps_v1_api.read_namespaced_deployment_scale(name, namespace)
    original = body.spec.replicas
    print(f"Original number of replicas is {original}")
    print(f"Scaling deployment '{name}' to {value} replica(s)")
    body.spec.replicas = value
    apps_v1_api.patch_namespaced_deployment_scale(name, namespace, body)
    if value is not 0:
        now = time.time()
        wait_until_all_pods_are_ready(v1, namespace)
        later = time.time()
        print(f"All pods came up in {int(later-now)} seconds")

    elif value is 0:
        replica_num = (apps_v1_api.read_namespaced_deployment_scale(name, namespace)).spec.replicas
        while(replica_num is not None):
            replica_num = (apps_v1_api.read_namespaced_deployment_scale(name, namespace)).spec.replicas
            time.sleep(1)
            print("Number of replicas is not 0, retrying...")

    else:
        pytest.fail("wrong argument")

    print(f"Scale a deployment '{name}': complete")
    return original
コード例 #2
0
def scale_deployment(apps_v1_api: AppsV1Api, name, namespace, value) -> None:
    """
    Scale a deployment.

    :param apps_v1_api: AppsV1Api
    :param namespace: namespace name
    :param name: deployment name
    :param value: int
    :return:
    """
    print(f"Scale a deployment '{name}'")
    body = apps_v1_api.read_namespaced_deployment_scale(name, namespace)
    body.spec.replicas = value
    apps_v1_api.patch_namespaced_deployment_scale(name, namespace, body)
    print(f"Scale a deployment '{name}': complete")
コード例 #3
0
def scale_deployment(apps_v1_api: AppsV1Api, name, namespace, value) -> int:
    """
    Scale a deployment.

    :param apps_v1_api: AppsV1Api
    :param namespace: namespace name
    :param name: deployment name
    :param value: int
    :return: original: int the original amount of replicas
    """
    print(f"Scale a deployment '{name}'")
    body = apps_v1_api.read_namespaced_deployment_scale(name, namespace)
    original = body.spec.replicas
    body.spec.replicas = value
    apps_v1_api.patch_namespaced_deployment_scale(name, namespace, body)
    print(f"Scale a deployment '{name}': complete")
    return original