From ad5616b4b1f27401483a011de8d9b63b4f7d8da0 Mon Sep 17 00:00:00 2001 From: Aurel Canciu Date: Wed, 16 Oct 2024 20:28:08 +0200 Subject: [PATCH] Update podspec and improve TestTopologySpreadConstraints Signed-off-by: Aurel Canciu --- pkg/operator/update/podspec.go | 1 - pkg/operator/update/podspec_test.go | 71 +++++++++++++++++++++++++++-- 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/pkg/operator/update/podspec.go b/pkg/operator/update/podspec.go index 1a50a20a..702e4e62 100644 --- a/pkg/operator/update/podspec.go +++ b/pkg/operator/update/podspec.go @@ -305,7 +305,6 @@ srcLoop: for dstIndex := range *dst { dstObj := &(*dst)[dstIndex] if reflect.DeepEqual(srcObj, dstObj) { - *dstObj = *srcObj continue srcLoop } } diff --git a/pkg/operator/update/podspec_test.go b/pkg/operator/update/podspec_test.go index a91b78df..b0113ce1 100644 --- a/pkg/operator/update/podspec_test.go +++ b/pkg/operator/update/podspec_test.go @@ -21,6 +21,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func TestTolerations(t *testing.T) { @@ -43,32 +44,92 @@ func TestTolerations(t *testing.T) { } func TestTopologySpreadConstraints(t *testing.T) { - // Make sure we don't touch tolerations that were already there. + // Make sure we don't touch topology spread constraints that were already there. val := []corev1.TopologySpreadConstraint{ { MaxSkew: 1, - TopologyKey: "alreadyExists", + TopologyKey: "existing-retain", + WhenUnsatisfiable: corev1.DoNotSchedule, + LabelSelector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "example-existing": "test", + }, + }, + }, + { + MaxSkew: 1, + TopologyKey: "existing-do-not-override", WhenUnsatisfiable: corev1.DoNotSchedule, + LabelSelector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "example-override": "test", + }, + }, }, } want := []corev1.TopologySpreadConstraint{ { MaxSkew: 1, - TopologyKey: "alreadyExists", + TopologyKey: "existing-retain", + WhenUnsatisfiable: corev1.DoNotSchedule, + LabelSelector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "example-existing": "test", + }, + }, + }, + { + MaxSkew: 1, + TopologyKey: "existing-do-not-override", WhenUnsatisfiable: corev1.DoNotSchedule, + LabelSelector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "example-override": "test", + }, + }, }, { MaxSkew: 2, - TopologyKey: "newKey", + TopologyKey: "new-1", WhenUnsatisfiable: corev1.ScheduleAnyway, + LabelSelector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "example-new": "new-1", + }, + }, + }, + { + MaxSkew: 2, + TopologyKey: "new-2", + WhenUnsatisfiable: corev1.DoNotSchedule, + LabelSelector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "example-override": "test", + }, + }, }, } TopologySpreadConstraints(&val, []corev1.TopologySpreadConstraint{ { MaxSkew: 2, - TopologyKey: "newKey", + TopologyKey: "new-1", WhenUnsatisfiable: corev1.ScheduleAnyway, + LabelSelector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "example-new": "new-1", + }, + }, + }, + { + MaxSkew: 2, + TopologyKey: "new-2", + WhenUnsatisfiable: corev1.DoNotSchedule, + LabelSelector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "example-override": "test", + }, + }, }, })