@@ -47,6 +47,7 @@ type testRA struct {
4747 SelectsDefault bool
4848 AdvertisePods bool
4949 AdvertiseEgressIPs bool
50+ Status * metav1.ConditionStatus
5051}
5152
5253func (tra testRA ) RouteAdvertisements () * ratypes.RouteAdvertisements {
@@ -92,6 +93,9 @@ func (tra testRA) RouteAdvertisements() *ratypes.RouteAdvertisements {
9293 MatchLabels : tra .FRRConfigurationSelector ,
9394 }
9495 }
96+ if tra .Status != nil {
97+ ra .Status .Conditions = []metav1.Condition {{Type : "Accepted" , Status : * tra .Status }}
98+ }
9599 return ra
96100}
97101
@@ -776,6 +780,38 @@ func TestController_reconcile(t *testing.T) {
776780 },
777781 expectNADAnnotations : map [string ]map [string ]string {"default" : {types .OvnRouteAdvertisementsKey : "[\" ra\" ]" }, "red" : {types .OvnRouteAdvertisementsKey : "[\" ra\" ]" }},
778782 },
783+ {
784+ name : "reconciles RouteAdvertisements status even when no other updates are required" ,
785+ ra : & testRA {Name : "ra" , AdvertisePods : true , AdvertiseEgressIPs : true , SelectsDefault : true , Status : ptr .To (metav1 .ConditionFalse )},
786+ frrConfigs : []* testFRRConfig {
787+ {
788+ Name : "frrConfig" ,
789+ Namespace : frrNamespace ,
790+ Routers : []* testRouter {
791+ {ASN : 1 , Prefixes : []string {"1.1.1.0/24" }, Neighbors : []* testNeighbor {
792+ {ASN : 1 , Address : "1.0.0.100" },
793+ }},
794+ },
795+ },
796+ {
797+ Labels : map [string ]string {types .OvnRouteAdvertisementsKey : "ra" },
798+ Annotations : map [string ]string {types .OvnRouteAdvertisementsKey : "ra/frrConfig/node" },
799+ NodeSelector : map [string ]string {"kubernetes.io/hostname" : "node" },
800+ Routers : []* testRouter {
801+ {ASN : 1 , Prefixes : []string {"1.0.1.1/32" , "1.1.0.0/24" }, Neighbors : []* testNeighbor {
802+ {ASN : 1 , Address : "1.0.0.100" , Advertise : []string {"1.0.1.1/32" , "1.1.0.0/24" }, Receive : []string {"1.1.0.0/16/24" }},
803+ }},
804+ },
805+ },
806+ },
807+ nads : []* testNAD {
808+ {Name : "default" , Namespace : "ovn-kubernetes" , Network : "default" , Annotations : map [string ]string {types .OvnRouteAdvertisementsKey : "[\" ra\" ]" }},
809+ },
810+ nodes : []* testNode {{Name : "node" , SubnetsAnnotation : "{\" default\" :\" 1.1.0.0/24\" }" }},
811+ eips : []* testEIP {{Name : "eip" , EIPs : map [string ]string {"node" : "1.0.1.1" }}},
812+ reconcile : "ra" ,
813+ expectAcceptedStatus : metav1 .ConditionTrue ,
814+ },
779815 {
780816 name : "fails to reconcile a secondary network" ,
781817 ra : & testRA {Name : "ra" , AdvertisePods : true , NetworkSelector : map [string ]string {"selected" : "true" }},
@@ -1005,11 +1041,6 @@ func TestController_reconcile(t *testing.T) {
10051041
10061042 c := NewController (nm .Interface (), wf , fakeClientset )
10071043
1008- // prime the default network NAD
1009- if defaultNAD == nil {
1010- defaultNAD , err = c .getOrCreateDefaultNetworkNAD ()
1011- g .Expect (err ).ToNot (gomega .HaveOccurred ())
1012- }
10131044 // prime the default network NAD namespace
10141045 namespace := & corev1.Namespace {
10151046 ObjectMeta : metav1.ObjectMeta {
@@ -1018,11 +1049,15 @@ func TestController_reconcile(t *testing.T) {
10181049 }
10191050 _ , err = fakeClientset .KubeClient .CoreV1 ().Namespaces ().Create (context .Background (), namespace , metav1.CreateOptions {})
10201051 g .Expect (err ).ToNot (gomega .HaveOccurred ())
1021-
1022- // update it with the annotation that network manager would set
1023- defaultNAD .Annotations = map [string ]string {types .OvnNetworkNameAnnotation : types .DefaultNetworkName }
1024- _ , err = fakeClientset .NetworkAttchDefClient .K8sCniCncfIoV1 ().NetworkAttachmentDefinitions (defaultNAD .Namespace ).Update (context .Background (), defaultNAD , metav1.UpdateOptions {})
1025- g .Expect (err ).ToNot (gomega .HaveOccurred ())
1052+ // prime the default network NAD
1053+ if defaultNAD == nil {
1054+ defaultNAD , err = c .getOrCreateDefaultNetworkNAD ()
1055+ g .Expect (err ).ToNot (gomega .HaveOccurred ())
1056+ // update it with the annotation that network manager would set
1057+ defaultNAD .Annotations = map [string ]string {types .OvnNetworkNameAnnotation : types .DefaultNetworkName }
1058+ _ , err = fakeClientset .NetworkAttchDefClient .K8sCniCncfIoV1 ().NetworkAttachmentDefinitions (defaultNAD .Namespace ).Update (context .Background (), defaultNAD , metav1.UpdateOptions {})
1059+ g .Expect (err ).ToNot (gomega .HaveOccurred ())
1060+ }
10261061
10271062 err = wf .Start ()
10281063 g .Expect (err ).ToNot (gomega .HaveOccurred ())
@@ -1039,7 +1074,13 @@ func TestController_reconcile(t *testing.T) {
10391074 )
10401075
10411076 err = nm .Start ()
1042- g .Expect (err ).ToNot (gomega .HaveOccurred ())
1077+ // some test cases start with a bad RA status, avoid asserting
1078+ // initial sync in this case as it will fail
1079+ if tt .ra == nil || tt .ra .Status == nil || * tt .ra .Status == metav1 .ConditionTrue {
1080+ g .Expect (err ).ToNot (gomega .HaveOccurred ())
1081+ } else {
1082+ g .Expect (err ).To (gomega .HaveOccurred ())
1083+ }
10431084 // we just need the inital sync
10441085 nm .Stop ()
10451086
0 commit comments