From d42f88e04c181d3a3d24c056cd3c450e8ddde7e6 Mon Sep 17 00:00:00 2001 From: Aleksandr Melnikov Date: Fri, 18 Sep 2020 15:53:00 -0700 Subject: [PATCH] Adding flag to decide when to add pod affinity. - This avoids adding it every time the loop finds a nodeSelector that's not nil in a template --- pkg/workflow_execution.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/workflow_execution.go b/pkg/workflow_execution.go index 9e293c6..fd87cb0 100644 --- a/pkg/workflow_execution.go +++ b/pkg/workflow_execution.go @@ -364,7 +364,7 @@ func (c *Client) createWorkflow(namespace string, workflowTemplateID uint64, wor func ensureWorkflowRunsOnDedicatedNode(wf *wfv1.Workflow, config SystemConfig) (*wfv1.Workflow, error) { antiAffinityLabelKey := "onepanel.io/reserves-instance-type" nodeSelectorVal := "" - + addPodAffinity := false for i := range wf.Spec.Templates { template := &wf.Spec.Templates[i] if template.NodeSelector == nil { @@ -392,6 +392,9 @@ func ensureWorkflowRunsOnDedicatedNode(wf *wfv1.Workflow, config SystemConfig) ( } } template.Metadata.Labels = map[string]string{antiAffinityLabelKey: nodeSelectorVal} + addPodAffinity = true + } + if addPodAffinity { wf.Spec.Affinity = &corev1.Affinity{ PodAntiAffinity: &corev1.PodAntiAffinity{ RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{