Skip to content

Commit

Permalink
Update podspec and improve TestTopologySpreadConstraints
Browse files Browse the repository at this point in the history
Signed-off-by: Aurel Canciu <[email protected]>
  • Loading branch information
relu committed Oct 16, 2024
1 parent e600832 commit ad5616b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
1 change: 0 additions & 1 deletion pkg/operator/update/podspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ srcLoop:
for dstIndex := range *dst {
dstObj := &(*dst)[dstIndex]
if reflect.DeepEqual(srcObj, dstObj) {
*dstObj = *srcObj
continue srcLoop
}
}
Expand Down
71 changes: 66 additions & 5 deletions pkg/operator/update/podspec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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",
},
},
},
})

Expand Down

0 comments on commit ad5616b

Please sign in to comment.