@@ -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"
@@ -74,7 +77,7 @@ var _ = Describe("[Scheduler] scheduler object updates", func() {
7477 dp , err := podlist .With (e2eclient .Client ).DeploymentByOwnerReference (context .TODO (), nroSchedObj .UID )
7578 Expect (err ).ToNot (HaveOccurred (), "unable to get deployment by owner reference" )
7679
77- _ , err = wait .With (e2eclient .Client ).Timeout (5 * time .Minute ).Interval (10 * time .Second ).ForDeploymentComplete (context .TODO (), dp )
80+ _ , err = wait .With (e2eclient .Client ).Timeout (5 * time .Minute ).Interval (10 * time .Second ).ForDeploymentCompleteWithReplicas (context .TODO (), dp , * dp . Spec . Replicas )
7881 Expect (err ).ToNot (HaveOccurred ())
7982 })
8083 })
@@ -129,7 +132,7 @@ var _ = Describe("[Scheduler] scheduler object updates", func() {
129132 dp , err := podlist .With (e2eclient .Client ).DeploymentByOwnerReference (context .TODO (), nroSchedObj .GetUID ())
130133 Expect (err ).ToNot (HaveOccurred ())
131134
132- _ , err = wait .With (e2eclient .Client ).Interval (30 * time .Second ).Timeout (2 * time .Minute ).ForDeploymentComplete (context .TODO (), dp )
135+ _ , err = wait .With (e2eclient .Client ).Interval (30 * time .Second ).Timeout (2 * time .Minute ).ForDeploymentCompleteWithReplicas (context .TODO (), dp , * dp . Spec . Replicas )
133136 Expect (err ).ToNot (HaveOccurred ())
134137 })
135138
@@ -267,7 +270,7 @@ var _ = Describe("[Scheduler] scheduler object updates", func() {
267270 dp , err := podlist .With (e2eclient .Client ).DeploymentByOwnerReference (context .TODO (), nroSchedObj .UID )
268271 Expect (err ).ToNot (HaveOccurred (), "unable to get deployment by owner reference" )
269272
270- dp , err = wait .With (e2eclient .Client ).Timeout (5 * time .Minute ).Interval (10 * time .Second ).ForDeploymentComplete (context .TODO (), dp )
273+ dp , err = wait .With (e2eclient .Client ).Timeout (5 * time .Minute ).Interval (10 * time .Second ).ForDeploymentCompleteWithReplicas (context .TODO (), dp , * dp . Spec . Replicas )
271274 Expect (err ).ToNot (HaveOccurred ())
272275
273276 podList , err = podlist .With (e2eclient .Client ).ByDeployment (context .TODO (), * dp )
@@ -280,6 +283,7 @@ var _ = Describe("[Scheduler] scheduler object updates", func() {
280283 })
281284
282285 When ("testing deployment TopologySpreadConstraints" , func () {
286+
283287 var (
284288 nroSchedKey client.ObjectKey
285289 autoDetectedReplicasCount * int32
@@ -295,14 +299,38 @@ var _ = Describe("[Scheduler] scheduler object updates", func() {
295299 Expect (err ).ToNot (HaveOccurred ())
296300
297301 if currentReplicas != nil {
302+ By ("compute expected autodetected replicas count" )
303+ var labelSelector map [string ]string
304+ switch configuration .Plat {
305+ case platform .HyperShift :
306+ labelSelector = map [string ]string {
307+ "node-role.kubernetes.io/worker" : "" ,
308+ }
309+ case platform .OpenShift :
310+ labelSelector = map [string ]string {
311+ "node-role.kubernetes.io/control-plane" : "" ,
312+ }
313+ default :
314+ Fail ("unknown platform" )
315+ }
316+
317+ nodeList := & corev1.NodeList {}
318+ Expect (e2eclient .Client .List (ctx , nodeList , & client.ListOptions {LabelSelector : labels .SelectorFromSet (labelSelector )})).To (Succeed ())
319+ Expect (nodeList .Items ).ToNot (BeEmpty (), "no nodes found with control-plane or worker role" )
320+ expectedAutodetectedCount := int32 (len (nodeList .Items ))
321+ if expectedAutodetectedCount > 3 {
322+ // this is how it is capped in the controller
323+ expectedAutodetectedCount = 3
324+ }
325+
298326 e2efixture .By ("configure NRS replicas for autodetection: current=%d desired=nil" , * currentReplicas )
299327 Eventually (func (g Gomega ) {
300328 g .Expect (e2eclient .Client .Get (ctx , nroSchedKey , nroSchedObj )).To (Succeed ())
301329 nroSchedObj .Spec .Replicas = nil
302330 g .Expect (e2eclient .Client .Update (ctx , nroSchedObj )).To (Succeed ())
303331 }).WithTimeout (5 * time .Minute ).WithPolling (10 * time .Second ).Should (Succeed (), "failed to update NRS with autodetection mode for replicas" )
304332
305- schedDp , err = wait .With (e2eclient .Client ).Timeout (5 * time .Minute ).Interval (10 * time .Second ).ForDeploymentComplete (ctx , schedDp )
333+ schedDp , err = wait .With (e2eclient .Client ).Timeout (5 * time .Minute ).Interval (10 * time .Second ).ForDeploymentCompleteWithReplicas (ctx , schedDp , expectedAutodetectedCount )
306334 if err != nil {
307335 infoUponDeploymentCompleteFailure (ctx , schedDp )
308336 }
@@ -315,7 +343,7 @@ var _ = Describe("[Scheduler] scheduler object updates", func() {
315343 nroSchedObj .Spec .Replicas = currentReplicas
316344 g .Expect (e2eclient .Client .Update (ctx , nroSchedObj )).To (Succeed ())
317345 }).WithTimeout (5 * time .Minute ).WithPolling (10 * time .Second ).Should (Succeed (), "failed to update NRS with autodetection mode for replicas" )
318- schedDp , err := wait .With (e2eclient .Client ).Timeout (5 * time .Minute ).Interval (10 * time .Second ).ForDeploymentComplete (ctx , schedDp )
346+ schedDp , err := wait .With (e2eclient .Client ).Timeout (5 * time .Minute ).Interval (10 * time .Second ).ForDeploymentCompleteWithReplicas (ctx , schedDp , * currentReplicas )
319347 if err != nil {
320348 infoUponDeploymentCompleteFailure (ctx , schedDp )
321349 }
@@ -363,7 +391,7 @@ var _ = Describe("[Scheduler] scheduler object updates", func() {
363391 g .Expect (e2eclient .Client .Update (ctx , nroSchedObj )).To (Succeed ())
364392 }).WithTimeout (5 * time .Minute ).WithPolling (10 * time .Second ).Should (Succeed (), "failed to update NRS with explicit replicas count" )
365393
366- schedDp , err := wait .With (e2eclient .Client ).Timeout (10 * time .Minute ).Interval (10 * time .Second ).ForDeploymentComplete (ctx , schedDp )
394+ schedDp , err := wait .With (e2eclient .Client ).Timeout (10 * time .Minute ).Interval (10 * time .Second ).ForDeploymentCompleteWithReplicas (ctx , schedDp , 0 )
367395 if err != nil {
368396 infoUponDeploymentCompleteFailure (ctx , schedDp )
369397 }
@@ -389,7 +417,7 @@ var _ = Describe("[Scheduler] scheduler object updates", func() {
389417 g .Expect (e2eclient .Client .Update (ctx , nroSchedObj )).To (Succeed ())
390418 }).WithTimeout (5 * time .Minute ).WithPolling (10 * time .Second ).Should (Succeed (), "failed to update NRS with autodetection mode for replicas" )
391419
392- schedDp , err = wait .With (e2eclient .Client ).Timeout (10 * time .Minute ).Interval (10 * time .Second ).ForDeploymentComplete (ctx , schedDp )
420+ schedDp , err = wait .With (e2eclient .Client ).Timeout (10 * time .Minute ).Interval (10 * time .Second ).ForDeploymentCompleteWithReplicas (ctx , schedDp , * autoDetectedReplicasCount )
393421 if err != nil {
394422 infoUponDeploymentCompleteFailure (ctx , schedDp )
395423 }
@@ -451,7 +479,7 @@ var _ = Describe("[Scheduler] scheduler object updates", func() {
451479 g .Expect (e2eclient .Client .Update (ctx , nroSchedObj )).To (Succeed ())
452480 }).WithTimeout (5 * time .Minute ).WithPolling (10 * time .Second ).Should (Succeed (), "failed to update NRS with explicit replicas count" )
453481
454- schedDp , err := wait .With (e2eclient .Client ).Timeout (10 * time .Minute ).Interval (10 * time .Second ).ForDeploymentComplete (ctx , schedDp )
482+ schedDp , err := wait .With (e2eclient .Client ).Timeout (10 * time .Minute ).Interval (10 * time .Second ).ForDeploymentCompleteWithReplicas (ctx , schedDp , 1 )
455483 if err != nil {
456484 infoUponDeploymentCompleteFailure (ctx , schedDp )
457485 }
@@ -473,7 +501,7 @@ var _ = Describe("[Scheduler] scheduler object updates", func() {
473501 g .Expect (e2eclient .Client .Update (ctx , nroSchedObj )).To (Succeed ())
474502 }).WithTimeout (5 * time .Minute ).WithPolling (10 * time .Second ).Should (Succeed (), "failed to update NRS with autodetection mode for replicas" )
475503
476- schedDp , err = wait .With (e2eclient .Client ).Timeout (10 * time .Minute ).Interval (10 * time .Second ).ForDeploymentComplete (ctx , schedDp )
504+ schedDp , err = wait .With (e2eclient .Client ).Timeout (10 * time .Minute ).Interval (10 * time .Second ).ForDeploymentCompleteWithReplicas (ctx , schedDp , * autoDetectedReplicasCount )
477505 if err != nil {
478506 infoUponDeploymentCompleteFailure (ctx , schedDp )
479507 }
0 commit comments