예제 #1
0
def kubernetes_job_status(
    kstatus: MutableMapping[str, Any],
    client: kubernetes_tools.KubeClient,
    job_config: kubernetes_tools.KubernetesDeploymentConfig,
    pod_list: Sequence[V1Pod],
    replicaset_list: Sequence[V1ReplicaSet],
    verbose: int,
) -> None:
    app_id = job_config.get_sanitised_deployment_name()
    kstatus["app_id"] = app_id
    kstatus["pods"] = []
    kstatus["replicasets"] = []
    if verbose > 0:
        for pod in pod_list:
            kstatus["pods"].append({
                "name":
                pod.metadata.name,
                "host":
                pod.spec.node_name,
                "deployed_timestamp":
                pod.metadata.creation_timestamp.timestamp(),
                "phase":
                pod.status.phase,
            })
        for replicaset in replicaset_list:
            kstatus["replicasets"].append({
                "name":
                replicaset.metadata.name,
                "replicas":
                replicaset.spec.replicas,
                "ready_replicas":
                replicaset.status.ready_replicas,
                "create_timestamp":
                replicaset.metadata.creation_timestamp.timestamp(),
            })

    kstatus["expected_instance_count"] = job_config.get_instances()

    app = kubernetes_tools.get_kubernetes_app_by_name(app_id, client)
    deploy_status = kubernetes_tools.get_kubernetes_app_deploy_status(
        client, app, job_config.get_instances())
    kstatus[
        "deploy_status"] = kubernetes_tools.KubernetesDeployStatus.tostring(
            deploy_status)
    kstatus["running_instance_count"] = (app.status.ready_replicas
                                         if app.status.ready_replicas else 0)
    kstatus["create_timestamp"] = app.metadata.creation_timestamp.timestamp()
    kstatus["namespace"] = app.metadata.namespace
예제 #2
0
def kubernetes_job_status(
    kstatus: MutableMapping[str, Any],
    client: kubernetes_tools.KubeClient,
    job_config: kubernetes_tools.KubernetesDeploymentConfig,
    pod_list: Sequence[V1Pod],
    verbose: bool,
) -> None:
    app_id = job_config.get_sanitised_deployment_name()
    kstatus['app_id'] = app_id
    if verbose is True:
        kstatus['slaves'] = [
            pod.spec.node_name
            for pod in pod_list
        ]
    kstatus['expected_instance_count'] = job_config.get_instances()

    app = kubernetes_tools.get_kubernetes_app_by_name(app_id, client)
    deploy_status = kubernetes_tools.get_kubernetes_app_deploy_status(client, app, job_config.get_instances())
    kstatus['deploy_status'] = kubernetes_tools.KubernetesDeployStatus.tostring(deploy_status)
    kstatus['running_instance_count'] = app.status.ready_replicas if app.status.ready_replicas else 0