当前位置: 首页>>代码示例>>Python>>正文


Python client.AppsV1beta1Api方法代码示例

本文整理汇总了Python中kubernetes.client.AppsV1beta1Api方法的典型用法代码示例。如果您正苦于以下问题:Python client.AppsV1beta1Api方法的具体用法?Python client.AppsV1beta1Api怎么用?Python client.AppsV1beta1Api使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kubernetes.client的用法示例。


在下文中一共展示了client.AppsV1beta1Api方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_deployment

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1beta1Api [as 别名]
def create_deployment(spec_path: str, ns: str = "default",
                      secrets: Secrets = None):
    """
    Create a deployment described by the deployment config, which must be the
    path to the JSON or YAML representation of the deployment.
    """
    api = create_k8s_api_client(secrets)

    with open(spec_path) as f:
        p, ext = os.path.splitext(spec_path)
        if ext == '.json':
            deployment = json.loads(f.read())
        elif ext in ['.yml', '.yaml']:
            deployment = yaml.load(f.read())
        else:
            raise ActivityFailed(
                "cannot process {path}".format(path=spec_path))

    v1 = client.AppsV1beta1Api(api)
    resp = v1.create_namespaced_deployment(ns, body=deployment) 
开发者ID:chaostoolkit,项目名称:chaostoolkit-kubernetes,代码行数:22,代码来源:actions.py

示例2: delete_deployment

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1beta1Api [as 别名]
def delete_deployment(name: str, ns: str = "default",
                      label_selector: str = "name in ({name})",
                      secrets: Secrets = None):
    """
    Delete a deployment by `name` in the namespace `ns`.

    The deployment is deleted without a graceful period to trigger an abrupt
    termination.

    The selected resources are matched by the given `label_selector`.
    """
    label_selector = label_selector.format(name=name)
    api = create_k8s_api_client(secrets)

    v1 = client.AppsV1beta1Api(api)
    if label_selector:
        ret = v1.list_namespaced_deployment(ns, label_selector=label_selector)
    else:
        ret = v1.list_namespaced_deployment(ns)

    logger.debug("Found {d} deployments named '{n}'".format(
        d=len(ret.items), n=name))

    body = client.V1DeleteOptions()
    for d in ret.items:
        v1.delete_namespaced_deployment(d.metadata.name, ns, body=body) 
开发者ID:chaostoolkit,项目名称:chaostoolkit-kubernetes,代码行数:28,代码来源:actions.py

示例3: deployment_available_and_healthy

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1beta1Api [as 别名]
def deployment_available_and_healthy(
        name: str, ns: str = "default",
        label_selector: str = None,
        secrets: Secrets = None) -> Union[bool, None]:
    """
    Lookup a deployment by `name` in the namespace `ns`.

    The selected resources are matched by the given `label_selector`.

    Raises :exc:`chaoslib.exceptions.ActivityFailed` when the state is not
    as expected.
    """

    field_selector = "metadata.name={name}".format(name=name)
    api = create_k8s_api_client(secrets)

    v1 = client.AppsV1beta1Api(api)
    if label_selector:
        ret = v1.list_namespaced_deployment(ns, field_selector=field_selector,
                                            label_selector=label_selector)
    else:
        ret = v1.list_namespaced_deployment(ns, field_selector=field_selector)

    logger.debug("Found {d} deployment(s) named '{n}' in ns '{s}'".format(
        d=len(ret.items), n=name, s=ns))

    if not ret.items:
        raise ActivityFailed(
            "Deployment '{name}' was not found".format(name=name))

    for d in ret.items:
        logger.debug("Deployment has '{s}' available replicas".format(
            s=d.status.available_replicas))

        if d.status.available_replicas != d.spec.replicas:
            raise ActivityFailed(
                "Deployment '{name}' is not healthy".format(name=name))

    return True 
开发者ID:chaostoolkit,项目名称:chaostoolkit-kubernetes,代码行数:41,代码来源:probes.py

示例4: rollout_status_deployment

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1beta1Api [as 别名]
def rollout_status_deployment(
    api: client.AppsV1beta1Api, name: str, namespace: str,
) -> Tuple[str, bool]:
    # tbh this is mostly ported from Go into Python from:
    # https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/rollout_status.go#L76-L92
    deployment = api.read_namespaced_deployment(name=name, namespace=namespace)
    if deployment.metadata.generation > deployment.status.observed_generation:
        return (
            f"Waiting for deployment {repr(name)} spec update to be observed...",
            False,
        )

    # TimedOutReason is added in a deployment when its newest replica set
    # fails to show any progress within the given deadline (progressDeadlineSeconds).
    for condition in deployment.status.conditions or []:
        if condition.type == "Progressing":
            if condition.reason == "ProgressDeadlineExceeded":
                return f"deployment {repr(name)} exceeded its progress deadline", False

    spec_replicas = deployment.spec.replicas
    status_replicas = deployment.status.replicas or 0
    updated_replicas = deployment.status.updated_replicas or 0
    available_replicas = deployment.status.available_replicas or 0

    if updated_replicas < spec_replicas:
        return (
            f"Waiting for deployment {repr(name)} rollout to finish: {updated_replicas} out of {spec_replicas} new replicas have been updated...",
            False,
        )
    if status_replicas > updated_replicas:
        return (
            f"Waiting for deployment {repr(name)} rollout to finish: {status_replicas-updated_replicas} old replicas are pending termination...",
            False,
        )
    if available_replicas < updated_replicas:
        return (
            f"Waiting for deployment {repr(name)} rollout to finish: {available_replicas} of {updated_replicas} updated replicas are available...",
            False,
        )
    return f"Deployment {repr(name)} successfully rolled out", True 
开发者ID:getsentry,项目名称:freight,代码行数:42,代码来源:pipeline.py

示例5: __init__

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1beta1Api [as 别名]
def __init__(self):
        # Create Kubernetes config.
        load_incluster_config()
        config = Configuration()
        config.debug = Settings.KUBERNETES_SERVICE_DEBUG
        self.api_client = client.ApiClient(config)

        # Re-usable API client instances.
        self.core_api = client.CoreV1Api(self.api_client)
        self.custom_objects_api = client.CustomObjectsApi(self.api_client)
        self.extensions_api = client.ApiextensionsV1beta1Api(self.api_client)
        self.apps_api = client.AppsV1beta1Api(self.api_client) 
开发者ID:Ultimaker,项目名称:k8s-mongo-operator,代码行数:14,代码来源:KubernetesService.py

示例6: __init__

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1beta1Api [as 别名]
def __init__(self):
        self.logger = logging.getLogger(__name__)
        try:
            config_file = os.path.expanduser(kubeconfig_filepath)
            config.load_kube_config(config_file=config_file)
        except:
            self.logger.warning("unable to load kube-config")

        self.v1 = client.CoreV1Api()
        self.v1Beta1 = client.AppsV1beta1Api()
        self.extensionsV1Beta1 = client.ExtensionsV1beta1Api()
        self.autoscalingV1Api = client.AutoscalingV1Api()
        self.rbacApi = client.RbacAuthorizationV1beta1Api()
        self.batchV1Api = client.BatchV1Api()
        self.batchV2Api = client.BatchV2alpha1Api() 
开发者ID:cloudnativelabs,项目名称:kube-shell,代码行数:17,代码来源:client.py

示例7: _deployment_readiness_has_state

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import AppsV1beta1Api [as 别名]
def _deployment_readiness_has_state(
        name: str, ready: bool,
        ns: str = "default",
        label_selector: str = None,
        timeout: int = 30,
        secrets: Secrets = None) -> Union[bool, None]:
    """
    Check wether if the given deployment state is ready or not
    according to the ready paramter.
    If the state is not reached after `timeout` seconds, a
    :exc:`chaoslib.exceptions.ActivityFailed` exception is raised.
    """
    field_selector = "metadata.name={name}".format(name=name)
    api = create_k8s_api_client(secrets)
    v1 = client.AppsV1beta1Api(api)
    w = watch.Watch()
    timeout = int(timeout)

    if label_selector is None:
        watch_events = partial(w.stream, v1.list_namespaced_deployment,
                               namespace=ns,
                               field_selector=field_selector,
                               _request_timeout=timeout)
    else:
        label_selector = label_selector.format(name=name)
        watch_events = partial(w.stream, v1.list_namespaced_deployment,
                               namespace=ns,
                               field_selector=field_selector,
                               label_selector=label_selector,
                               _request_timeout=timeout)

    try:
        logger.debug("Watching events for {t}s".format(t=timeout))
        for event in watch_events():
            deployment = event['object']
            status = deployment.status
            spec = deployment.spec

            logger.debug(
                "Deployment '{p}' {t}: "
                "Ready Replicas {r} - "
                "Unavailable Replicas {u} - "
                "Desired Replicas {a}".format(
                    p=deployment.metadata.name, t=event["type"],
                    r=status.ready_replicas,
                    a=spec.replicas,
                    u=status.unavailable_replicas))

            readiness = status.ready_replicas == spec.replicas
            if ready == readiness:
                w.stop()
                return True

    except urllib3.exceptions.ReadTimeoutError:
        logger.debug("Timed out!")
        return False 
开发者ID:chaostoolkit,项目名称:chaostoolkit-kubernetes,代码行数:58,代码来源:probes.py


注:本文中的kubernetes.client.AppsV1beta1Api方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。