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
This commit is contained in:
Aleksandr Melnikov
2020-09-18 15:53:00 -07:00
parent 6dd7c0ac70
commit d42f88e04c

View File

@@ -364,7 +364,7 @@ func (c *Client) createWorkflow(namespace string, workflowTemplateID uint64, wor
func ensureWorkflowRunsOnDedicatedNode(wf *wfv1.Workflow, config SystemConfig) (*wfv1.Workflow, error) { func ensureWorkflowRunsOnDedicatedNode(wf *wfv1.Workflow, config SystemConfig) (*wfv1.Workflow, error) {
antiAffinityLabelKey := "onepanel.io/reserves-instance-type" antiAffinityLabelKey := "onepanel.io/reserves-instance-type"
nodeSelectorVal := "" nodeSelectorVal := ""
addPodAffinity := false
for i := range wf.Spec.Templates { for i := range wf.Spec.Templates {
template := &wf.Spec.Templates[i] template := &wf.Spec.Templates[i]
if template.NodeSelector == nil { if template.NodeSelector == nil {
@@ -392,6 +392,9 @@ func ensureWorkflowRunsOnDedicatedNode(wf *wfv1.Workflow, config SystemConfig) (
} }
} }
template.Metadata.Labels = map[string]string{antiAffinityLabelKey: nodeSelectorVal} template.Metadata.Labels = map[string]string{antiAffinityLabelKey: nodeSelectorVal}
addPodAffinity = true
}
if addPodAffinity {
wf.Spec.Affinity = &corev1.Affinity{ wf.Spec.Affinity = &corev1.Affinity{
PodAntiAffinity: &corev1.PodAntiAffinity{ PodAntiAffinity: &corev1.PodAntiAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{ RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{