From 6b0c82503acd52133351ef83a5f3b029eadf76cf Mon Sep 17 00:00:00 2001 From: fg91 Date: Mon, 13 Jun 2022 23:18:51 +0200 Subject: [PATCH] Test passing default tolerations to spark driver and executor --- go/tasks/plugins/k8s/spark/spark_test.go | 41 ++++++++++++++++++------ 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/go/tasks/plugins/k8s/spark/spark_test.go b/go/tasks/plugins/k8s/spark/spark_test.go index 13721aee6..0bf2e3f9f 100755 --- a/go/tasks/plugins/k8s/spark/spark_test.go +++ b/go/tasks/plugins/k8s/spark/spark_test.go @@ -378,6 +378,14 @@ func TestBuildResourceSpark(t *testing.T) { }, Searches: []string{"ns1.svc.cluster-domain.example", "my.dns.search.suffix"}, }, + DefaultTolerations: []corev1.Toleration{ + { + Key: "x/flyte", + Value: "default", + Operator: "Equal", + Effect: "NoSchedule", + }, + }, InterruptibleNodeSelector: map[string]string{ "x/interruptible": "true", }, @@ -440,17 +448,28 @@ func TestBuildResourceSpark(t *testing.T) { assert.Equal(t, dummySparkConf["spark.batchScheduler"], *sparkApp.Spec.BatchScheduler) // Validate Interruptible Toleration and NodeSelector set for Executor but not Driver. - assert.Equal(t, 0, len(sparkApp.Spec.Driver.Tolerations)) + assert.Equal(t, 1, len(sparkApp.Spec.Driver.Tolerations)) assert.Equal(t, 0, len(sparkApp.Spec.Driver.NodeSelector)) + tolDriverDefault := sparkApp.Spec.Driver.Tolerations[0] + assert.Equal(t, tolDriverDefault.Key, "x/flyte") + assert.Equal(t, tolDriverDefault.Value, "default") + assert.Equal(t, tolDriverDefault.Operator, corev1.TolerationOperator("Equal")) + assert.Equal(t, tolDriverDefault.Effect, corev1.TaintEffect("NoSchedule")) - assert.Equal(t, 1, len(sparkApp.Spec.Executor.Tolerations)) + assert.Equal(t, 2, len(sparkApp.Spec.Executor.Tolerations)) assert.Equal(t, 1, len(sparkApp.Spec.Executor.NodeSelector)) - tol := sparkApp.Spec.Executor.Tolerations[0] - assert.Equal(t, tol.Key, "x/flyte") - assert.Equal(t, tol.Value, "interruptible") - assert.Equal(t, tol.Operator, corev1.TolerationOperator("Equal")) - assert.Equal(t, tol.Effect, corev1.TaintEffect("NoSchedule")) + tolExecDefault := sparkApp.Spec.Executor.Tolerations[0] + assert.Equal(t, tolExecDefault.Key, "x/flyte") + assert.Equal(t, tolExecDefault.Value, "default") + assert.Equal(t, tolExecDefault.Operator, corev1.TolerationOperator("Equal")) + assert.Equal(t, tolExecDefault.Effect, corev1.TaintEffect("NoSchedule")) + + tolExecInterrupt := sparkApp.Spec.Executor.Tolerations[1] + assert.Equal(t, tolExecInterrupt.Key, "x/flyte") + assert.Equal(t, tolExecInterrupt.Value, "interruptible") + assert.Equal(t, tolExecInterrupt.Operator, corev1.TolerationOperator("Equal")) + assert.Equal(t, tolExecInterrupt.Effect, corev1.TaintEffect("NoSchedule")) assert.Equal(t, "true", sparkApp.Spec.Executor.NodeSelector["x/interruptible"]) for confKey, confVal := range dummySparkConf { @@ -514,10 +533,14 @@ func TestBuildResourceSpark(t *testing.T) { assert.True(t, ok) // Validate Interruptible Toleration and NodeSelector not set for both Driver and Executors. - assert.Equal(t, 0, len(sparkApp.Spec.Driver.Tolerations)) + assert.Equal(t, 1, len(sparkApp.Spec.Driver.Tolerations)) assert.Equal(t, 0, len(sparkApp.Spec.Driver.NodeSelector)) - assert.Equal(t, 0, len(sparkApp.Spec.Executor.Tolerations)) + assert.Equal(t, 1, len(sparkApp.Spec.Executor.Tolerations)) assert.Equal(t, 0, len(sparkApp.Spec.Executor.NodeSelector)) + assert.Equal(t, sparkApp.Spec.Executor.Tolerations[0].Key, "x/flyte") + assert.Equal(t, sparkApp.Spec.Executor.Tolerations[0].Value, "default") + assert.Equal(t, sparkApp.Spec.Driver.Tolerations[0].Key, "x/flyte") + assert.Equal(t, sparkApp.Spec.Driver.Tolerations[0].Value, "default") // Case 4: Invalid Spark Task-Template taskTemplate.Custom = nil