本文整理汇总了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
示例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")
示例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