@@ -26,20 +26,23 @@ import (
2626 appsv1 "k8s.io/api/apps/v1"
2727 corev1 "k8s.io/api/core/v1"
2828 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+ "k8s.io/apimachinery/pkg/labels"
2930 "k8s.io/apimachinery/pkg/types"
3031 "k8s.io/apimachinery/pkg/util/sets"
3132 klog "k8s.io/klog/v2"
3233 "k8s.io/utils/ptr"
3334
3435 "sigs.k8s.io/controller-runtime/pkg/client"
3536
37+ "github.com/k8stopologyawareschedwg/deployer/pkg/deployer/platform"
3638 "github.com/k8stopologyawareschedwg/deployer/pkg/manifests"
3739
3840 nropv1 "github.com/openshift-kni/numaresources-operator/api/v1"
3941 "github.com/openshift-kni/numaresources-operator/internal/podlist"
4042 "github.com/openshift-kni/numaresources-operator/internal/wait"
4143 schedstate "github.com/openshift-kni/numaresources-operator/pkg/numaresourcesscheduler/objectstate/sched"
4244 e2eclient "github.com/openshift-kni/numaresources-operator/test/internal/clients"
45+ "github.com/openshift-kni/numaresources-operator/test/internal/configuration"
4346 e2efixture "github.com/openshift-kni/numaresources-operator/test/internal/fixture"
4447 e2eimages "github.com/openshift-kni/numaresources-operator/test/internal/images"
4548 "github.com/openshift-kni/numaresources-operator/test/internal/objects"
@@ -80,7 +83,7 @@ var _ = Describe("[Scheduler] scheduler object updates", func() {
8083 dp , err := podlist .With (e2eclient .Client ).DeploymentByOwnerReference (context .TODO (), nroSchedObj .UID )
8184 Expect (err ).ToNot (HaveOccurred (), "unable to get deployment by owner reference" )
8285
83- _ , err = wait .With (e2eclient .Client ).Timeout (5 * time .Minute ).Interval (10 * time .Second ).ForDeploymentComplete (context .TODO (), dp )
86+ _ , err = wait .With (e2eclient .Client ).Timeout (5 * time .Minute ).Interval (10 * time .Second ).ForDeploymentCompleteWithReplicas (context .TODO (), dp , * dp . Spec . Replicas )
8487 Expect (err ).ToNot (HaveOccurred ())
8588 })
8689 })
@@ -137,7 +140,7 @@ var _ = Describe("[Scheduler] scheduler object updates", func() {
137140 dp , err := podlist .With (e2eclient .Client ).DeploymentByOwnerReference (context .TODO (), nroSchedObj .GetUID ())
138141 Expect (err ).ToNot (HaveOccurred ())
139142
140- _ , err = wait .With (e2eclient .Client ).Interval (30 * time .Second ).Timeout (2 * time .Minute ).ForDeploymentComplete (context .TODO (), dp )
143+ _ , err = wait .With (e2eclient .Client ).Interval (30 * time .Second ).Timeout (2 * time .Minute ).ForDeploymentCompleteWithReplicas (context .TODO (), dp , * dp . Spec . Replicas )
141144 Expect (err ).ToNot (HaveOccurred ())
142145 })
143146
@@ -298,7 +301,7 @@ var _ = Describe("[Scheduler] scheduler object updates", func() {
298301 dp , err := podlist .With (e2eclient .Client ).DeploymentByOwnerReference (context .TODO (), nroSchedObj .UID )
299302 Expect (err ).ToNot (HaveOccurred (), "unable to get deployment by owner reference" )
300303
301- dp , err = wait .With (e2eclient .Client ).Timeout (5 * time .Minute ).Interval (10 * time .Second ).ForDeploymentComplete (context .TODO (), dp )
304+ dp , err = wait .With (e2eclient .Client ).Timeout (5 * time .Minute ).Interval (10 * time .Second ).ForDeploymentCompleteWithReplicas (context .TODO (), dp , * dp . Spec . Replicas )
302305 Expect (err ).ToNot (HaveOccurred ())
303306
304307 podList , err = podlist .With (e2eclient .Client ).ByDeployment (context .TODO (), * dp )
@@ -311,6 +314,7 @@ var _ = Describe("[Scheduler] scheduler object updates", func() {
311314 })
312315
313316 When ("testing deployment TopologySpreadConstraints" , func () {
317+
314318 var (
315319 nroSchedKey client.ObjectKey
316320 autoDetectedReplicasCount * int32
@@ -326,14 +330,38 @@ var _ = Describe("[Scheduler] scheduler object updates", func() {
326330 Expect (err ).ToNot (HaveOccurred ())
327331
328332 if currentReplicas != nil {
333+ By ("compute expected autodetected replicas count" )
334+ var labelSelector map [string ]string
335+ switch configuration .Plat {
336+ case platform .HyperShift :
337+ labelSelector = map [string ]string {
338+ "node-role.kubernetes.io/worker" : "" ,
339+ }
340+ case platform .OpenShift :
341+ labelSelector = map [string ]string {
342+ "node-role.kubernetes.io/control-plane" : "" ,
343+ }
344+ default :
345+ Fail ("unknown platform" )
346+ }
347+
348+ nodeList := & corev1.NodeList {}
349+ Expect (e2eclient .Client .List (ctx , nodeList , & client.ListOptions {LabelSelector : labels .SelectorFromSet (labelSelector )})).To (Succeed ())
350+ Expect (nodeList .Items ).ToNot (BeEmpty (), "no nodes found with control-plane or worker role" )
351+ expectedAutodetectedCount := int32 (len (nodeList .Items ))
352+ if expectedAutodetectedCount > 3 {
353+ // this is how it is capped in the controller
354+ expectedAutodetectedCount = 3
355+ }
356+
329357 e2efixture .By ("configure NRS replicas for autodetection: current=%d desired=nil" , * currentReplicas )
330358 Eventually (func (g Gomega ) {
331359 g .Expect (e2eclient .Client .Get (ctx , nroSchedKey , nroSchedObj )).To (Succeed ())
332360 nroSchedObj .Spec .Replicas = nil
333361 g .Expect (e2eclient .Client .Update (ctx , nroSchedObj )).To (Succeed ())
334362 }).WithTimeout (5 * time .Minute ).WithPolling (10 * time .Second ).Should (Succeed (), "failed to update NRS with autodetection mode for replicas" )
335363
336- schedDp , err = wait .With (e2eclient .Client ).Timeout (5 * time .Minute ).Interval (10 * time .Second ).ForDeploymentComplete (ctx , schedDp )
364+ schedDp , err = wait .With (e2eclient .Client ).Timeout (5 * time .Minute ).Interval (10 * time .Second ).ForDeploymentCompleteWithReplicas (ctx , schedDp , expectedAutodetectedCount )
337365 if err != nil {
338366 infoUponDeploymentCompleteFailure (ctx , schedDp )
339367 }
@@ -346,7 +374,7 @@ var _ = Describe("[Scheduler] scheduler object updates", func() {
346374 nroSchedObj .Spec .Replicas = currentReplicas
347375 g .Expect (e2eclient .Client .Update (ctx , nroSchedObj )).To (Succeed ())
348376 }).WithTimeout (5 * time .Minute ).WithPolling (10 * time .Second ).Should (Succeed (), "failed to update NRS with autodetection mode for replicas" )
349- schedDp , err := wait .With (e2eclient .Client ).Timeout (5 * time .Minute ).Interval (10 * time .Second ).ForDeploymentComplete (ctx , schedDp )
377+ schedDp , err := wait .With (e2eclient .Client ).Timeout (5 * time .Minute ).Interval (10 * time .Second ).ForDeploymentCompleteWithReplicas (ctx , schedDp , * currentReplicas )
350378 if err != nil {
351379 infoUponDeploymentCompleteFailure (ctx , schedDp )
352380 }
@@ -394,7 +422,7 @@ var _ = Describe("[Scheduler] scheduler object updates", func() {
394422 g .Expect (e2eclient .Client .Update (ctx , nroSchedObj )).To (Succeed ())
395423 }).WithTimeout (5 * time .Minute ).WithPolling (10 * time .Second ).Should (Succeed (), "failed to update NRS with explicit replicas count" )
396424
397- schedDp , err := wait .With (e2eclient .Client ).Timeout (10 * time .Minute ).Interval (10 * time .Second ).ForDeploymentComplete (ctx , schedDp )
425+ schedDp , err := wait .With (e2eclient .Client ).Timeout (10 * time .Minute ).Interval (10 * time .Second ).ForDeploymentCompleteWithReplicas (ctx , schedDp , 0 )
398426 if err != nil {
399427 infoUponDeploymentCompleteFailure (ctx , schedDp )
400428 }
@@ -420,7 +448,7 @@ var _ = Describe("[Scheduler] scheduler object updates", func() {
420448 g .Expect (e2eclient .Client .Update (ctx , nroSchedObj )).To (Succeed ())
421449 }).WithTimeout (5 * time .Minute ).WithPolling (10 * time .Second ).Should (Succeed (), "failed to update NRS with autodetection mode for replicas" )
422450
423- schedDp , err = wait .With (e2eclient .Client ).Timeout (10 * time .Minute ).Interval (10 * time .Second ).ForDeploymentComplete (ctx , schedDp )
451+ schedDp , err = wait .With (e2eclient .Client ).Timeout (10 * time .Minute ).Interval (10 * time .Second ).ForDeploymentCompleteWithReplicas (ctx , schedDp , * autoDetectedReplicasCount )
424452 if err != nil {
425453 infoUponDeploymentCompleteFailure (ctx , schedDp )
426454 }
@@ -482,7 +510,7 @@ var _ = Describe("[Scheduler] scheduler object updates", func() {
482510 g .Expect (e2eclient .Client .Update (ctx , nroSchedObj )).To (Succeed ())
483511 }).WithTimeout (5 * time .Minute ).WithPolling (10 * time .Second ).Should (Succeed (), "failed to update NRS with explicit replicas count" )
484512
485- schedDp , err := wait .With (e2eclient .Client ).Timeout (10 * time .Minute ).Interval (10 * time .Second ).ForDeploymentComplete (ctx , schedDp )
513+ schedDp , err := wait .With (e2eclient .Client ).Timeout (10 * time .Minute ).Interval (10 * time .Second ).ForDeploymentCompleteWithReplicas (ctx , schedDp , 1 )
486514 if err != nil {
487515 infoUponDeploymentCompleteFailure (ctx , schedDp )
488516 }
@@ -504,7 +532,7 @@ var _ = Describe("[Scheduler] scheduler object updates", func() {
504532 g .Expect (e2eclient .Client .Update (ctx , nroSchedObj )).To (Succeed ())
505533 }).WithTimeout (5 * time .Minute ).WithPolling (10 * time .Second ).Should (Succeed (), "failed to update NRS with autodetection mode for replicas" )
506534
507- schedDp , err = wait .With (e2eclient .Client ).Timeout (10 * time .Minute ).Interval (10 * time .Second ).ForDeploymentComplete (ctx , schedDp )
535+ schedDp , err = wait .With (e2eclient .Client ).Timeout (10 * time .Minute ).Interval (10 * time .Second ).ForDeploymentCompleteWithReplicas (ctx , schedDp , * autoDetectedReplicasCount )
508536 if err != nil {
509537 infoUponDeploymentCompleteFailure (ctx , schedDp )
510538 }
0 commit comments