@@ -21,12 +21,14 @@ import (
21
21
adminpolicybasedrouteapi "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/adminpolicybasedroute/v1"
22
22
egressfirewallapi "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/egressfirewall/v1"
23
23
egressqosapi "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/egressqos/v1"
24
+ networkqosapi "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/networkqos/v1alpha1"
24
25
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/factory"
25
26
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/types"
26
27
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util"
27
28
28
29
. "github.com/onsi/ginkgo/v2"
29
30
. "github.com/onsi/gomega"
31
+ networkingv1 "k8s.io/api/networking/v1"
30
32
)
31
33
32
34
func getNodeWithZone (nodeName , zoneName string ) * corev1.Node {
@@ -203,6 +205,72 @@ func checkEmptyEQStatusConsistently(egressQoS *egressqosapi.EgressQoS, fakeClien
203
205
}).Should (BeTrue (), "expected Status to be consistently empty" )
204
206
}
205
207
208
+ func newNetworkQoS (namespace string ) * networkqosapi.NetworkQoS {
209
+ return & networkqosapi.NetworkQoS {
210
+ ObjectMeta : util .NewObjectMeta ("default" , namespace ),
211
+ Spec : networkqosapi.Spec {
212
+ NetworkAttachmentRefs : []v1.ObjectReference {
213
+ {
214
+ Kind : "NetworkAttachmentDefinition" ,
215
+ Namespace : "default" ,
216
+ Name : "stream" ,
217
+ },
218
+ },
219
+ Priority : 100 ,
220
+ Egress : []networkqosapi.Rule {
221
+ {
222
+ DSCP : 60 ,
223
+ Classifier : networkqosapi.Classifier {
224
+ To : []networkqosapi.Destination {
225
+ {
226
+ IPBlock : & networkingv1.IPBlock {
227
+ CIDR : "1.2.3.4/32" ,
228
+ },
229
+ },
230
+ },
231
+ },
232
+ Bandwidth : networkqosapi.Bandwidth {
233
+ Rate : 100 ,
234
+ Burst : 1000 ,
235
+ },
236
+ },
237
+ },
238
+ },
239
+ }
240
+ }
241
+
242
+ func updateNetworkQoSStatus (networkQoS * networkqosapi.NetworkQoS , status * networkqosapi.Status ,
243
+ fakeClient * util.OVNClusterManagerClientset ) {
244
+ networkQoS .Status = * status
245
+ _ , err := fakeClient .NetworkQoSClient .K8sV1alpha1 ().NetworkQoSes (networkQoS .Namespace ).
246
+ Update (context .TODO (), networkQoS , metav1.UpdateOptions {})
247
+ Expect (err ).ToNot (HaveOccurred ())
248
+ }
249
+
250
+ func checkNQStatusEventually (networkQoS * networkqosapi.NetworkQoS , expectFailure bool , expectEmpty bool , fakeClient * util.OVNClusterManagerClientset ) {
251
+ Eventually (func () bool {
252
+ eq , err := fakeClient .NetworkQoSClient .K8sV1alpha1 ().NetworkQoSes (networkQoS .Namespace ).
253
+ Get (context .TODO (), networkQoS .Name , metav1.GetOptions {})
254
+ Expect (err ).NotTo (HaveOccurred ())
255
+ if expectFailure {
256
+ return strings .Contains (eq .Status .Status , types .NetworkQoSErrorMsg )
257
+ } else if expectEmpty {
258
+ return eq .Status .Status == ""
259
+ } else {
260
+ return strings .Contains (eq .Status .Status , "applied" )
261
+ }
262
+ }).Should (BeTrue (), fmt .Sprintf ("expected network QoS status with expectFailure=%v expectEmpty=%v" , expectFailure , expectEmpty ))
263
+ }
264
+
265
+ func checkEmptyNQStatusConsistently (networkQoS * networkqosapi.NetworkQoS , fakeClient * util.OVNClusterManagerClientset ) {
266
+ Consistently (func () bool {
267
+ ef , err := fakeClient .NetworkQoSClient .K8sV1alpha1 ().NetworkQoSes (networkQoS .Namespace ).
268
+ Get (context .TODO (), networkQoS .Name , metav1.GetOptions {})
269
+ Expect (err ).NotTo (HaveOccurred ())
270
+ return ef .Status .Status == ""
271
+ }).Should (BeTrue (), "expected Status to be consistently empty" )
272
+ }
273
+
206
274
var _ = Describe ("Cluster Manager Status Manager" , func () {
207
275
var (
208
276
statusManager * StatusManager
@@ -505,4 +573,96 @@ var _ = Describe("Cluster Manager Status Manager", func() {
505
573
return atomic .LoadUint32 (& banpWerePatched )
506
574
}).Should (Equal (uint32 (2 )))
507
575
})
576
+
577
+ It ("updates NetworkQoS status with 1 zone" , func () {
578
+ config .OVNKubernetesFeature .EnableNetworkQoS = true
579
+ zones := sets.New [string ]("zone1" )
580
+ namespace1 := util .NewNamespace (namespace1Name )
581
+ networkQoS := newNetworkQoS (namespace1 .Name )
582
+ start (zones , namespace1 , networkQoS )
583
+ updateNetworkQoSStatus (networkQoS , & networkqosapi.Status {
584
+ Conditions : []metav1.Condition {{
585
+ Type : "Ready-In-Zone-zone1" ,
586
+ Status : metav1 .ConditionTrue ,
587
+ Reason : "SetupSucceeded" ,
588
+ Message : "NetworkQoS Destinations applied" ,
589
+ }},
590
+ }, fakeClient )
591
+
592
+ checkNQStatusEventually (networkQoS , false , false , fakeClient )
593
+ })
594
+
595
+ It ("updates NetworkQoS status with 2 zones" , func () {
596
+ config .OVNKubernetesFeature .EnableNetworkQoS = true
597
+ zones := sets .New [string ]("zone1" , "zone2" )
598
+ namespace1 := util .NewNamespace (namespace1Name )
599
+ networkQoS := newNetworkQoS (namespace1 .Name )
600
+ start (zones , namespace1 , networkQoS )
601
+
602
+ updateNetworkQoSStatus (networkQoS , & networkqosapi.Status {
603
+ Conditions : []metav1.Condition {{
604
+ Type : "Ready-In-Zone-zone1" ,
605
+ Status : metav1 .ConditionTrue ,
606
+ Reason : "SetupSucceeded" ,
607
+ Message : "NetworkQoS Destinations applied" ,
608
+ }},
609
+ }, fakeClient )
610
+
611
+ checkEmptyNQStatusConsistently (networkQoS , fakeClient )
612
+
613
+ updateNetworkQoSStatus (networkQoS , & networkqosapi.Status {
614
+ Conditions : []metav1.Condition {{
615
+ Type : "Ready-In-Zone-zone1" ,
616
+ Status : metav1 .ConditionTrue ,
617
+ Reason : "SetupSucceeded" ,
618
+ Message : "NetworkQoS Destinations applied" ,
619
+ }, {
620
+ Type : "Ready-In-Zone-zone2" ,
621
+ Status : metav1 .ConditionTrue ,
622
+ Reason : "SetupSucceeded" ,
623
+ Message : "NetworkQoS Destinations applied" ,
624
+ }},
625
+ }, fakeClient )
626
+ checkNQStatusEventually (networkQoS , false , false , fakeClient )
627
+
628
+ })
629
+
630
+ It ("updates NetworkQoS status with UnknownZone" , func () {
631
+ config .OVNKubernetesFeature .EnableNetworkQoS = true
632
+ zones := sets .New [string ]("zone1" , zone_tracker .UnknownZone )
633
+ namespace1 := util .NewNamespace (namespace1Name )
634
+ networkQoS := newNetworkQoS (namespace1 .Name )
635
+ start (zones , namespace1 , networkQoS )
636
+
637
+ // no matter how many messages are in the status, it won't be updated while UnknownZone is present
638
+ updateNetworkQoSStatus (networkQoS , & networkqosapi.Status {
639
+ Conditions : []metav1.Condition {{
640
+ Type : "Ready-In-Zone-zone1" ,
641
+ Status : metav1 .ConditionTrue ,
642
+ Reason : "SetupSucceeded" ,
643
+ Message : "NetworkQoS Destinations applied" ,
644
+ }},
645
+ }, fakeClient )
646
+ checkEmptyNQStatusConsistently (networkQoS , fakeClient )
647
+
648
+ // when UnknownZone is removed, updates will be handled, but status from the new zone is not reported yet
649
+ statusManager .onZoneUpdate (sets .New [string ]("zone1" , "zone2" ))
650
+ checkEmptyNQStatusConsistently (networkQoS , fakeClient )
651
+ // when new zone status is reported, status will be set
652
+ updateNetworkQoSStatus (networkQoS , & networkqosapi.Status {
653
+ Conditions : []metav1.Condition {{
654
+ Type : "Ready-In-Zone-zone1" ,
655
+ Status : metav1 .ConditionTrue ,
656
+ Reason : "SetupSucceeded" ,
657
+ Message : "NetworkQoS Destinations applied" ,
658
+ }, {
659
+ Type : "Ready-In-Zone-zone2" ,
660
+ Status : metav1 .ConditionTrue ,
661
+ Reason : "SetupSucceeded" ,
662
+ Message : "NetworkQoS Destinations applied" ,
663
+ }},
664
+ }, fakeClient )
665
+ checkNQStatusEventually (networkQoS , false , false , fakeClient )
666
+ })
667
+
508
668
})
0 commit comments