本文整理匯總了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