From c977cf862301f6b3b5bafe86f5201ba8d44ec7ba Mon Sep 17 00:00:00 2001 From: "Fabio M. Graetz, Ph.D" Date: Tue, 8 Aug 2023 20:26:59 +0200 Subject: [PATCH] Fix deletion of elastic task resource requests (#379) Signed-off-by: Fabio Graetz --- .../tasks/plugins/k8s/kfoperators/common/common_operator.go | 4 +--- .../plugins/k8s/kfoperators/common/common_operator_test.go | 6 ++++-- .../tasks/plugins/k8s/kfoperators/pytorch/pytorch_test.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator.go b/flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator.go index ac3b7f455a..3a86ed9a54 100644 --- a/flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator.go +++ b/flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator.go @@ -268,12 +268,10 @@ func OverrideContainerSpec(podSpec *v1.PodSpec, containerName string, image stri if len(resources.Requests) >= 1 || len(resources.Limits) >= 1 { resources, err := flytek8s.ToK8sResourceRequirements(resources) if err != nil { - return flyteerr.Errorf(flyteerr.BadTaskSpecification, "invalid TaskSpecificat ion on Resources [%v], Err: [%v]", resources, err.Error()) + return flyteerr.Errorf(flyteerr.BadTaskSpecification, "invalid TaskSpecification on Resources [%v], Err: [%v]", resources, err.Error()) } podSpec.Containers[idx].Resources = *resources } - } else { - podSpec.Containers[idx].Resources = v1.ResourceRequirements{} } if len(args) != 0 { podSpec.Containers[idx].Args = args diff --git a/flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator_test.go b/flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator_test.go index cd92557f38..8914e976f5 100644 --- a/flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator_test.go +++ b/flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator_test.go @@ -314,11 +314,13 @@ func TestOverrideContainerSpecEmptyFields(t *testing.T) { func TestOverrideContainerNilResources(t *testing.T) { podSpec := dummyPodSpec() + podSpecCopy := podSpec.DeepCopy() + err := OverrideContainerSpec(&podSpec, "primary container", "", nil, []string{}) assert.NoError(t, err) assert.Equal(t, 2, len(podSpec.Containers)) - assert.Nil(t, podSpec.Containers[0].Resources.Limits) - assert.Nil(t, podSpec.Containers[0].Resources.Requests) + assert.Equal(t, podSpec.Containers[0].Resources.Limits, podSpecCopy.Containers[0].Resources.Limits) + assert.Equal(t, podSpec.Containers[0].Resources.Requests, podSpecCopy.Containers[0].Resources.Requests) } func dummyTaskContext() pluginsCore.TaskExecutionContext { diff --git a/flyteplugins/go/tasks/plugins/k8s/kfoperators/pytorch/pytorch_test.go b/flyteplugins/go/tasks/plugins/k8s/kfoperators/pytorch/pytorch_test.go index 0eb1dbf06c..8122a85e32 100644 --- a/flyteplugins/go/tasks/plugins/k8s/kfoperators/pytorch/pytorch_test.go +++ b/flyteplugins/go/tasks/plugins/k8s/kfoperators/pytorch/pytorch_test.go @@ -720,7 +720,7 @@ func TestBuildResourcePytorchV1WithZeroWorker(t *testing.T) { assert.Error(t, err) } -func TestParasElasticConfig(t *testing.T) { +func TestParseElasticConfig(t *testing.T) { elasticConfig := plugins.ElasticConfig{MinReplicas: 1, MaxReplicas: 2, NprocPerNode: 4, RdzvBackend: "c10d"} elasticPolicy := ParseElasticConfig(&elasticConfig) assert.Equal(t, int32(1), *elasticPolicy.MinReplicas)