From d6a9b9239a12fe2bd5ee728fbf25c29e312758f8 Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Tue, 16 Jun 2026 22:17:38 +1000 Subject: [PATCH] force pod spread (#130) Added required pod anti-affinity (kubernetes.io/hostname, pod-uuid Exists) to K8sController.cs so all pods within a test namespace are forced onto distinct nodes (Pending if unsatisfiable) to cover the worst-case pod counts per namespace. The anti-affinity TopologyKey of "kubernetes.io/hostname" specifies that the domain is the node, along with the "Exists" operator, specifies that "this Pod should not run on this node if this node is already running one or mode pods that have a "pod-uuid" key (they all do). --- Framework/KubernetesWorkflow/K8sController.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Framework/KubernetesWorkflow/K8sController.cs b/Framework/KubernetesWorkflow/K8sController.cs index 5eebb4bf..014f1f36 100644 --- a/Framework/KubernetesWorkflow/K8sController.cs +++ b/Framework/KubernetesWorkflow/K8sController.cs @@ -375,6 +375,7 @@ namespace KubernetesWorkflow PriorityClassName = GetPriorityClassName(containerRecipes), NodeSelector = CreateNodeSelector(location, containerRecipes), Tolerations = CreateTolerations(containerRecipes), + Affinity = CreateSpreadAffinity(), Containers = CreateDeploymentContainers(containerRecipes), Volumes = CreateVolumes(containerRecipes) } @@ -422,6 +423,34 @@ namespace KubernetesWorkflow }).ToList(); } + private V1Affinity CreateSpreadAffinity() + { + return new V1Affinity + { + PodAntiAffinity = new V1PodAntiAffinity + { + RequiredDuringSchedulingIgnoredDuringExecution = new List + { + new V1PodAffinityTerm + { + TopologyKey = "kubernetes.io/hostname", + LabelSelector = new V1LabelSelector + { + MatchExpressions = new List + { + new V1LabelSelectorRequirement + { + Key = PodLabelKey, + OperatorProperty = "Exists" + } + } + } + } + } + } + }; + } + private K8sNodeLabel? GetNodeLabelForLocation(ILocation location) { var l = (Location)location;