@@ -92,12 +92,36 @@ var _ = Describe("Overlay CNI", func() {
9292 }, appGw , agicPod , namespace , false )
9393 })
9494
95+ Context ("NodeNetworkConfigList does not have the overlay label" , func () {
96+ It ("returns nil error" , func () {
97+ // Create NodeNetworkConfigList so that cluster is not considered as overlay CNI
98+ config := & nodenetworkconfig_v1alpha.NodeNetworkConfig {
99+ ObjectMeta : metav1.ObjectMeta {
100+ Name : "test-node-network-config" ,
101+ Namespace : namespace ,
102+ Labels : map [string ]string {
103+ cni .PodNetworkTypeLabel : "not overlay" ,
104+ },
105+ },
106+ Spec : nodenetworkconfig_v1alpha.NodeNetworkConfigSpec {},
107+ }
108+ Expect (k8sClient .Create (ctx , config )).To (BeNil ())
109+ Expect (reconciler .Reconcile (ctx )).To (BeNil ())
110+ })
111+ })
112+
95113 Context ("Handle Overlay CNI cluster" , func () {
96114 BeforeEach (func () {
97115 // Create NodeNetworkConfig so that cluster is considered as overlay CNI
98116 config := & nodenetworkconfig_v1alpha.NodeNetworkConfig {
99- ObjectMeta : metav1.ObjectMeta {Name : "test-node-network-config" , Namespace : namespace },
100- Spec : nodenetworkconfig_v1alpha.NodeNetworkConfigSpec {},
117+ ObjectMeta : metav1.ObjectMeta {
118+ Name : "test-node-network-config" ,
119+ Namespace : namespace ,
120+ Labels : map [string ]string {
121+ cni .PodNetworkTypeLabel : "overlay" ,
122+ },
123+ },
124+ Spec : nodenetworkconfig_v1alpha.NodeNetworkConfigSpec {},
101125 }
102126 Expect (k8sClient .Create (ctx , config )).To (BeNil ())
103127
@@ -149,6 +173,38 @@ var _ = Describe("Overlay CNI", func() {
149173 Expect (err .Error ()).To (ContainSubstring ("failed to get subnet" ))
150174 })
151175
176+ It ("should return error if subnet does not have an address prefix or address prefixes" , func () {
177+ azClient .GetSubnetFunc = func (subnetID string ) (n.Subnet , error ) {
178+ return n.Subnet {
179+ SubnetPropertiesFormat : & n.SubnetPropertiesFormat {
180+ AddressPrefix : nil ,
181+ AddressPrefixes : & []string {},
182+ }}, nil
183+ }
184+
185+ err := reconciler .Reconcile (ctx )
186+ Expect (err ).To (Not (BeNil ()))
187+ Expect (err .Error ()).To (ContainSubstring ("subnet does not have an address prefix(es)" ))
188+ })
189+
190+ It ("should not return error if subnet has an entry in address prefixes" , func () {
191+ azClient .GetSubnetFunc = func (subnetID string ) (n.Subnet , error ) {
192+ return n.Subnet {
193+ SubnetPropertiesFormat : & n.SubnetPropertiesFormat {
194+ AddressPrefix : nil ,
195+ AddressPrefixes : & []string {"CIDR1" },
196+ }}, nil
197+ }
198+
199+ err := reconciler .Reconcile (ctx )
200+ Expect (err ).To (Not (HaveOccurred ()))
201+
202+ var config overlayextensionconfig_v1alpha1.OverlayExtensionConfig
203+ Expect (k8sClient .Get (ctx , ctrl_client.ObjectKey {Name : cni .OverlayExtensionConfigName , Namespace : namespace }, & config )).To (BeNil ())
204+ Expect (config .Labels ).To (HaveLen (1 ))
205+ Expect (config .Spec .ExtensionIPRange ).To (Equal ("CIDR1" ))
206+ })
207+
152208 It ("should delete and recreate OEC if subnet CIDR changes" , func () {
153209 // Create OverlayExtensionConfig
154210 Expect (k8sClient .Create (ctx , & overlayextensionconfig_v1alpha1.OverlayExtensionConfig {
@@ -197,8 +253,10 @@ var _ = Describe("Overlay CNI", func() {
197253
198254 // Create NodeNetworkConfig so that cluster is considered as overlay CNI
199255 Expect (k8sClient .Create (ctx , & nodenetworkconfig_v1alpha.NodeNetworkConfig {
200- ObjectMeta : metav1.ObjectMeta {Name : "test-node-network-config" , Namespace : namespace },
201- Spec : nodenetworkconfig_v1alpha.NodeNetworkConfigSpec {},
256+ ObjectMeta : metav1.ObjectMeta {Name : "test-node-network-config" , Namespace : namespace , Labels : map [string ]string {
257+ cni .PodNetworkTypeLabel : "overlay" ,
258+ }},
259+ Spec : nodenetworkconfig_v1alpha.NodeNetworkConfigSpec {},
202260 })).To (BeNil ())
203261
204262 Expect (reconciler .Reconcile (ctx )).To (BeNil ())
@@ -216,8 +274,10 @@ var _ = Describe("Overlay CNI", func() {
216274
217275 // Create NodeNetworkConfig so that cluster is considered as overlay CNI
218276 Expect (k8sClient .Create (ctx , & nodenetworkconfig_v1alpha.NodeNetworkConfig {
219- ObjectMeta : metav1.ObjectMeta {Name : "test-node-network-config" , Namespace : namespace },
220- Spec : nodenetworkconfig_v1alpha.NodeNetworkConfigSpec {},
277+ ObjectMeta : metav1.ObjectMeta {Name : "test-node-network-config" , Namespace : namespace , Labels : map [string ]string {
278+ cni .PodNetworkTypeLabel : "overlay" ,
279+ }},
280+ Spec : nodenetworkconfig_v1alpha.NodeNetworkConfigSpec {},
221281 })).To (BeNil ())
222282
223283 go func () {
0 commit comments