Add pod anti-affinity rule to build pods
With this rule build pods will prefer to be scheduled on separate nodes
if possible.
@@ -166,12 +166,13 @@ class Build:
if self.git_credentials:
env.append(client.V1EnvVar(name='GIT_CREDENTIAL_ENV', value=self.git_credentials))
+ component_label = "binderhub-build"
self.pod = client.V1Pod(
metadata=client.V1ObjectMeta(
name=self.name,
labels={
"name": self.name,
- "component": "binderhub-build",
+ "component": component_label,
},
annotations={
"binder-repo": self.repo_url,
@@ -193,7 +194,24 @@ class Build:
],
node_selector=self.node_selector,
volumes=volumes,
- restart_policy="Never"
+ restart_policy="Never",
+ affinity=client.V1Affinity(
+ pod_anti_affinity=client.V1PodAntiAffinity(
+ preferred_during_scheduling_ignored_during_execution=[
+ client.V1WeightedPodAffinityTerm(
+ weight=100,
+ pod_affinity_term=client.V1PodAffinityTerm(
+ topology_key="kubernetes.io/hostname",
+ label_selector=client.V1LabelSelector(
+ match_labels=dict(
+ component=component_label
+ )
+ )
+ )
+ )
+ ]
+ )
+ )
)
)
