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


Python client.V1Affinity方法代码示例

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


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

示例1: test_default_affinity

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Affinity [as 别名]
def test_default_affinity():
    # check that the default affinity is a pod anti-affinity
    build = Build(
        mock.MagicMock(), api=mock.MagicMock(), name='test_build',
        namespace='build_namespace', repo_url=mock.MagicMock(),
        ref=mock.MagicMock(), build_image=mock.MagicMock(),
        image_name=mock.MagicMock(), push_secret=mock.MagicMock(),
        memory_limit=mock.MagicMock(), git_credentials=None,
        docker_host='http://mydockerregistry.local',
        node_selector=mock.MagicMock())

    affinity = build.get_affinity()

    assert isinstance(affinity, client.V1Affinity)
    assert affinity.node_affinity is None
    assert affinity.pod_affinity is None
    assert affinity.pod_anti_affinity is not None 
开发者ID:jupyterhub,项目名称:binderhub,代码行数:19,代码来源:test_build.py

示例2: test_sticky_builds_affinity

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Affinity [as 别名]
def test_sticky_builds_affinity():
    # Setup some mock objects for the response from the k8s API
    Pod = namedtuple("Pod", "spec")
    PodSpec = namedtuple("PodSpec", "node_name")
    PodList = namedtuple("PodList", "items")

    mock_k8s_api = mock.MagicMock()
    mock_k8s_api.list_namespaced_pod.return_value = PodList(
        [Pod(PodSpec("node-a")), Pod(PodSpec("node-b"))],
    )

    build = Build(
        mock.MagicMock(), api=mock_k8s_api, name='test_build',
        namespace='build_namespace', repo_url=mock.MagicMock(),
        ref=mock.MagicMock(), build_image=mock.MagicMock(),
        image_name=mock.MagicMock(), push_secret=mock.MagicMock(),
        memory_limit=mock.MagicMock(), git_credentials=None,
        docker_host='http://mydockerregistry.local',
        node_selector=mock.MagicMock(),
        sticky_builds=True)

    affinity = build.get_affinity()

    assert isinstance(affinity, client.V1Affinity)
    assert affinity.node_affinity is not None
    assert affinity.pod_affinity is None
    assert affinity.pod_anti_affinity is None

    # One of the two nodes we have in our mock should be the preferred node
    assert affinity.node_affinity.preferred_during_scheduling_ignored_during_execution[0].preference.match_expressions[0].values[0] in ("node-a", "node-b") 
开发者ID:jupyterhub,项目名称:binderhub,代码行数:32,代码来源:test_build.py

示例3: add_affinity

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Affinity [as 别名]
def add_affinity(self, affinity: V1Affinity):
        """Add K8s Affinity
        Args:
          affinity: Kubernetes affinity
          For detailed spec, check affinity definition
          https://github.com/kubernetes-client/python/blob/master/kubernetes/client/models/v1_affinity.py
          example: V1Affinity(
                    node_affinity=V1NodeAffinity(
                        required_during_scheduling_ignored_during_execution=V1NodeSelector(
                            node_selector_terms=[V1NodeSelectorTerm(
                                match_expressions=[V1NodeSelectorRequirement(
                                    key='beta.kubernetes.io/instance-type', operator='In', values=['p2.xlarge'])])])))
        """
        self.affinity = affinity
        return self 
开发者ID:kubeflow,项目名称:pipelines,代码行数:17,代码来源:_container_op.py


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