Adding function to ensure a workflow gets a dedicated node for all the

templates it executes.
- Note that workflows executed by cron are also affected.
This commit is contained in:
Aleksandr Melnikov
2020-09-17 17:06:20 -07:00
parent b27ca42e42
commit ec634b66ca

View File

@@ -372,6 +372,7 @@ func (c *Client) createWorkflow(namespace string, workflowTemplateID uint64, wor
return nil, err
}
ensureWorkflowRunsOnDedicatedNode(wf)
createdArgoWorkflow, err := c.ArgoprojV1alpha1().Workflows(namespace).Create(wf)
if err != nil {
return nil, err
@@ -401,6 +402,26 @@ func (c *Client) createWorkflow(namespace string, workflowTemplateID uint64, wor
return
}
func ensureWorkflowRunsOnDedicatedNode(wf *wfv1.Workflow) {
antiAffinityLabelKey := "onepanel.io/reserves-instance-type"
nodeSelectorVal := "singular-workflow"
for i := range wf.Spec.Templates {
wf.Spec.Templates[i].Metadata.Labels = map[string]string{antiAffinityLabelKey: nodeSelectorVal}
}
wf.Spec.Affinity = &corev1.Affinity{
PodAntiAffinity: &corev1.PodAntiAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{
{LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{Key: antiAffinityLabelKey, Operator: "In", Values: []string{nodeSelectorVal}},
},
},
TopologyKey: "kubernetes.io/hostname"},
},
},
}
}
func (c *Client) ValidateWorkflowExecution(namespace string, manifest []byte) (err error) {
manifest, err = filterOutCustomTypesFromManifest(manifest)
if err != nil {