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


Python client.V1Deployment方法代码示例

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


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

示例1: list_namespaced_applications

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Deployment [as 别名]
def list_namespaced_applications(
    kube_client: KubeClient, namespace: str, application_types: Sequence[Any]
) -> Sequence[Application]:
    """
    List all applications in the namespace of the types from application_types.
    Only applications with complete set of labels are included (See is_valid_application()).
    :param kube_client:
    :param namespace:
    :param application_types:  types of applications
    :return:
    """
    apps = []  # type: ignore
    for application_type in application_types:
        if application_type == V1Deployment:
            apps.extend(list_namespaced_deployments(kube_client, namespace))
        elif application_type == V1StatefulSet:
            apps.extend(list_namespaced_stateful_sets(kube_client, namespace))
    return apps 
开发者ID:Yelp,项目名称:paasta,代码行数:20,代码来源:tools.py

示例2: __init__

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Deployment [as 别名]
def __init__(
        self,
        item: Union[V1Deployment, V1StatefulSet],
        logging=logging.getLogger(__name__),
    ) -> None:
        """
        This Application wrapper is an interface for creating/deleting k8s deployments and statefulsets
        soa_config is KubernetesDeploymentConfig. It is not loaded in init because it is not always required.
        :param item: Kubernetes Object(V1Deployment/V1StatefulSet) that has already been filled up.
        :param logging: where logs go
        """
        if not item.metadata.namespace:
            item.metadata.namespace = "paasta"
        attrs = {
            attr: item.metadata.labels[paasta_prefixed(attr)]
            for attr in ["service", "instance", "git_sha", "config_sha"]
        }
        self.kube_deployment = KubeDeployment(replicas=item.spec.replicas, **attrs)
        self.item = item
        self.soa_config = None  # type: KubernetesDeploymentConfig
        self.logging = logging 
开发者ID:Yelp,项目名称:paasta,代码行数:23,代码来源:controller_wrappers.py

示例3: write_annotation_for_kubernetes_service

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Deployment [as 别名]
def write_annotation_for_kubernetes_service(
    kube_client: KubeClient,
    service_config: KubernetesDeploymentConfig,
    formatted_application: Union[V1Deployment, V1StatefulSet],
    annotation: Dict,
) -> None:
    name = formatted_application.metadata.name
    formatted_application.metadata.annotations = annotation
    if service_config.get_persistent_volumes():
        kube_client.deployments.patch_namespaced_stateful_set(
            name=name, namespace="paasta", body=formatted_application
        )
    else:
        kube_client.deployments.patch_namespaced_deployment(
            name=name, namespace="paasta", body=formatted_application
        ) 
开发者ID:Yelp,项目名称:paasta,代码行数:18,代码来源:kubernetes_tools.py

示例4: get_kubernetes_app_by_name

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Deployment [as 别名]
def get_kubernetes_app_by_name(
    name: str, kube_client: KubeClient, namespace: str = "paasta"
) -> Union[V1Deployment, V1StatefulSet]:
    try:
        app = kube_client.deployments.read_namespaced_deployment_status(
            name=name, namespace=namespace
        )
        return app
    except ApiException as e:
        if e.status == 404:
            pass
        else:
            raise
    return kube_client.deployments.read_namespaced_stateful_set_status(
        name=name, namespace=namespace
    ) 
开发者ID:Yelp,项目名称:paasta,代码行数:18,代码来源:kubernetes_tools.py

示例5: get_events_for_object

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Deployment [as 别名]
def get_events_for_object(
    kube_client: KubeClient,
    obj: Union[V1Pod, V1Deployment, V1StatefulSet, V1ReplicaSet],
    kind: str,  # for some reason, obj.kind isn't populated when this function is called so we pass it in by hand
) -> List[V1Event]:
    host = KubeConfiguration().host

    # The python kubernetes client doesn't support the V1Events API
    # yet, so we have to make the request by hand (we need the V1Events
    # API so that we can query by the involvedObject.name/kind)
    #
    # Also, as best as I can tell, the list_namespaced_event API call under the
    # CoreV1 API does _not_ return the events that we're interested in.
    events = kube_client.request(
        "GET",
        f"{host}/api/v1/namespaces/{obj.metadata.namespace}/events",
        query_params={
            "fieldSelector": f"involvedObject.name={obj.metadata.name},involvedObject.kind={kind}",
            "limit": MAX_EVENTS_TO_RETRIEVE,
        },
    )
    parsed_events = json.loads(events.data)
    return parsed_events["items"] 
开发者ID:Yelp,项目名称:paasta,代码行数:25,代码来源:kubernetes_tools.py

示例6: test_sanitize_for_config_hash

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Deployment [as 别名]
def test_sanitize_for_config_hash(self):
        with mock.patch(
            "paasta_tools.kubernetes_tools.get_kubernetes_secret_hashes", autospec=True
        ) as mock_get_kubernetes_secret_hashes:
            mock_config = V1Deployment(
                metadata=V1ObjectMeta(name="qwe", labels={"mc": "grindah"}),
                spec=V1DeploymentSpec(
                    replicas=2,
                    selector=V1LabelSelector(match_labels={"freq": "108.9"}),
                    template=V1PodTemplateSpec(),
                ),
            )
            ret = self.deployment.sanitize_for_config_hash(mock_config)
            assert "replicas" not in ret["spec"].keys()
            assert (
                ret["paasta_secrets"] == mock_get_kubernetes_secret_hashes.return_value
            ) 
开发者ID:Yelp,项目名称:paasta,代码行数:19,代码来源:test_kubernetes_tools.py

示例7: test_get_annotations_for_kubernetes_service

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Deployment [as 别名]
def test_get_annotations_for_kubernetes_service(
    mock_kube_deploy_config, has_persistent_volumes, expected_annotations
):
    mock_client = mock.Mock()
    mock_client.deployments.read_namespaced_stateful_set.return_value = V1StatefulSet(
        metadata=V1ObjectMeta(annotations={"I-am": "stateful_set"})
    )
    mock_client.deployments.read_namespaced_deployment.return_value = V1Deployment(
        metadata=V1ObjectMeta(annotations={"I-am": "deployment"})
    )
    mock_kube_deploy_config.get_sanitised_deployment_name.return_value = (
        "fake_k8s_service"
    )
    mock_kube_deploy_config.get_persistent_volumes.return_value = has_persistent_volumes
    mock_kube_deploy_config.format_kubernetes_app.return_value = mock.Mock()
    annotations = get_annotations_for_kubernetes_service(
        mock_client, mock_kube_deploy_config
    )
    assert annotations == expected_annotations 
开发者ID:Yelp,项目名称:paasta,代码行数:21,代码来源:test_kubernetes_tools.py

示例8: fake_deployment

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Deployment [as 别名]
def fake_deployment():
    fake_deployment = V1Deployment(
        metadata=mock.Mock(
            namespace="paasta",
            labels={
                "yelp.com/paasta_service": "service",
                "yelp.com/paasta_instance": "instance-1",
                "yelp.com/paasta_git_sha": "1234",
                "yelp.com/paasta_config_sha": "1234",
                "paasta.yelp.com/service": "service",
                "paasta.yelp.com/instance": "instance-1",
                "paasta.yelp.com/git_sha": "1234",
                "paasta.yelp.com/config_sha": "1234",
            },
        ),
        spec=mock.Mock(replicas=0),
    )
    type(fake_deployment.metadata).name = mock.PropertyMock(
        return_value="service-instance-1"
    )
    return fake_deployment 
开发者ID:Yelp,项目名称:paasta,代码行数:23,代码来源:test_cleanup_kubernetes_jobs.py

示例9: create_deployment

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Deployment [as 别名]
def create_deployment(apps_v1_api):
    container = client.V1Container(
        name="deployment",
        image="gcr.io/google-appengine/fluentd-logger",
        image_pull_policy="Never",
        ports=[client.V1ContainerPort(container_port=5678)],
    )
    # Template
    template = client.V1PodTemplateSpec(
        metadata=client.V1ObjectMeta(labels={"app": "deployment"}),
        spec=client.V1PodSpec(containers=[container]))
    # Spec
    spec = client.V1DeploymentSpec(
        replicas=1,
        template=template)
    # Deployment
    deployment = client.V1Deployment(
        api_version="apps/v1",
        kind="Deployment",
        metadata=client.V1ObjectMeta(name="deployment"),
        spec=spec)
    # Creation of the Deployment in specified namespace
    # (Can replace "default" with a namespace you may have created)
    apps_v1_api.create_namespaced_deployment(
        namespace="default", body=deployment
    ) 
开发者ID:kubernetes-client,项目名称:python,代码行数:28,代码来源:ingress_create.py

示例10: create_deployment_object

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Deployment [as 别名]
def create_deployment_object():
    # Configureate Pod template container
    container = client.V1Container(
        name="nginx",
        image="nginx:1.15.4",
        ports=[client.V1ContainerPort(container_port=80)],
        resources=client.V1ResourceRequirements(
            requests={"cpu": "100m", "memory": "200Mi"},
            limits={"cpu": "500m", "memory": "500Mi"}
        )
    )
    # Create and configurate a spec section
    template = client.V1PodTemplateSpec(
        metadata=client.V1ObjectMeta(labels={"app": "nginx"}),
        spec=client.V1PodSpec(containers=[container]))
    # Create the specification of deployment
    spec = client.V1DeploymentSpec(
        replicas=3,
        template=template,
        selector={'matchLabels': {'app': 'nginx'}})
    # Instantiate the deployment object
    deployment = client.V1Deployment(
        api_version="apps/v1",
        kind="Deployment",
        metadata=client.V1ObjectMeta(name=DEPLOYMENT_NAME),
        spec=spec)

    return deployment 
开发者ID:kubernetes-client,项目名称:python,代码行数:30,代码来源:deployment_crud.py

示例11: is_valid_application

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Deployment [as 别名]
def is_valid_application(deployment: V1Deployment):
    is_valid = True
    missing = []
    for attr in ["service", "instance", "git_sha", "config_sha"]:
        prefixed_attr = paasta_prefixed(attr)
        if prefixed_attr not in deployment.metadata.labels:
            is_valid = False
            missing.append(prefixed_attr)
    if missing:
        log.warning(
            f"deployment/{deployment.metadata.name} in "
            f"namespace/{deployment.metadata.namespace} "
            f"is missing following labels: {missing}"
        )
    return is_valid 
开发者ID:Yelp,项目名称:paasta,代码行数:17,代码来源:tools.py

示例12: get_application_wrapper

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Deployment [as 别名]
def get_application_wrapper(
    formatted_application: Union[V1Deployment, V1StatefulSet]
) -> Application:
    app: Application
    if isinstance(formatted_application, V1Deployment):
        app = DeploymentWrapper(formatted_application)
    elif isinstance(formatted_application, V1StatefulSet):
        app = StatefulSetWrapper(formatted_application)
    else:
        raise Exception("Unknown kubernetes object to update")

    return app 
开发者ID:Yelp,项目名称:paasta,代码行数:14,代码来源:controller_wrappers.py

示例13: mark_deployment_as_paused

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Deployment [as 别名]
def mark_deployment_as_paused(
    kube_client: KubeClient,
    service_config: KubernetesDeploymentConfig,
    formatted_application: Union[V1Deployment, V1StatefulSet],
    paused: bool,
) -> None:
    annotation = {"is_paused": str(paused)}
    write_annotation_for_kubernetes_service(
        kube_client, service_config, formatted_application, annotation
    ) 
开发者ID:Yelp,项目名称:paasta,代码行数:12,代码来源:autoscaling_service_lib.py

示例14: get_active_shas_for_service

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Deployment [as 别名]
def get_active_shas_for_service(
    obj_list: Sequence[Union[V1Pod, V1ReplicaSet, V1Deployment, V1StatefulSet]],
) -> Mapping[str, Set[str]]:
    ret: MutableMapping[str, Set[str]] = {"config_sha": set(), "git_sha": set()}
    for obj in obj_list:
        config_sha = obj.metadata.labels.get("paasta.yelp.com/config_sha")
        if config_sha is not None:
            ret["config_sha"].add(config_sha)
        git_sha = obj.metadata.labels.get("paasta.yelp.com/git_sha")
        if git_sha is not None:
            ret["git_sha"].add(git_sha)
    return ret 
开发者ID:Yelp,项目名称:paasta,代码行数:14,代码来源:kubernetes_tools.py

示例15: create_deployment

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Deployment [as 别名]
def create_deployment(
    kube_client: KubeClient, formatted_deployment: V1Deployment
) -> None:
    return kube_client.deployments.create_namespaced_deployment(
        namespace="paasta", body=formatted_deployment
    ) 
开发者ID:Yelp,项目名称:paasta,代码行数:8,代码来源:kubernetes_tools.py


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