當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。