@@ -109,6 +109,23 @@ var _ = Describe("[IPAM]", func() {
109
109
Expect (err ).ShouldNot (HaveOccurred ())
110
110
Expect (ip ).To (Equal ("10.16.0.1" ))
111
111
})
112
+
113
+ It ("donot reuse released address after update subnet's excludedIps" , func () {
114
+ im := ipam .NewIPAM ()
115
+ err := im .AddOrUpdateSubnet (subnetName , "10.16.0.0/30" , nil )
116
+ Expect (err ).ShouldNot (HaveOccurred ())
117
+
118
+ ip , _ , _ , err := im .GetRandomAddress ("pod1.ns" , "pod1.ns" , subnetName , nil )
119
+ Expect (err ).ShouldNot (HaveOccurred ())
120
+ Expect (ip ).To (Equal ("10.16.0.1" ))
121
+
122
+ im .ReleaseAddressByPod ("pod1.ns" )
123
+ err = im .AddOrUpdateSubnet (subnetName , "10.16.0.0/30" , []string {"10.16.0.1..10.16.0.2" })
124
+ Expect (err ).ShouldNot (HaveOccurred ())
125
+
126
+ _ , _ , _ , err = im .GetRandomAddress ("pod1.ns" , "pod1.ns" , subnetName , nil )
127
+ Expect (err ).Should (MatchError (ipam .ErrNoAvailable ))
128
+ })
112
129
})
113
130
114
131
Context ("[IPv6]" , func () {
@@ -189,6 +206,23 @@ var _ = Describe("[IPAM]", func() {
189
206
Expect (err ).ShouldNot (HaveOccurred ())
190
207
Expect (ip ).To (Equal ("fd00::1" ))
191
208
})
209
+
210
+ It ("donot reuse released address after update subnet's excludedIps" , func () {
211
+ im := ipam .NewIPAM ()
212
+ err := im .AddOrUpdateSubnet (subnetName , "fd00::/126" , nil )
213
+ Expect (err ).ShouldNot (HaveOccurred ())
214
+
215
+ _ , ip , _ , err := im .GetRandomAddress ("pod1.ns" , "pod1.ns" , subnetName , nil )
216
+ Expect (err ).ShouldNot (HaveOccurred ())
217
+ Expect (ip ).To (Equal ("fd00::1" ))
218
+
219
+ im .ReleaseAddressByPod ("pod1.ns" )
220
+ err = im .AddOrUpdateSubnet (subnetName , "fd00::/126" , []string {"fd00::1..fd00::2" })
221
+ Expect (err ).ShouldNot (HaveOccurred ())
222
+
223
+ _ , _ , _ , err = im .GetRandomAddress ("pod1.ns" , "pod1.ns" , subnetName , nil )
224
+ Expect (err ).Should (MatchError (ipam .ErrNoAvailable ))
225
+ })
192
226
})
193
227
194
228
Context ("[DualStack]" , func () {
@@ -281,6 +315,24 @@ var _ = Describe("[IPAM]", func() {
281
315
Expect (ipv4 ).To (Equal ("10.16.0.1" ))
282
316
Expect (ipv6 ).To (Equal ("fd00::1" ))
283
317
})
318
+
319
+ It ("donot reuse released address after update subnet's excludedIps" , func () {
320
+ im := ipam .NewIPAM ()
321
+ err := im .AddOrUpdateSubnet (subnetName , "10.16.0.2/30,fd00::/126" , nil )
322
+ Expect (err ).ShouldNot (HaveOccurred ())
323
+
324
+ ipv4 , ipv6 , _ , err := im .GetRandomAddress ("pod1.ns" , "pod1.ns" , subnetName , nil )
325
+ Expect (err ).ShouldNot (HaveOccurred ())
326
+ Expect (ipv4 ).To (Equal ("10.16.0.1" ))
327
+ Expect (ipv6 ).To (Equal ("fd00::1" ))
328
+
329
+ im .ReleaseAddressByPod ("pod1.ns" )
330
+ err = im .AddOrUpdateSubnet (subnetName , "10.16.0.2/30,fd00::/126" , []string {"10.16.0.1..10.16.0.2" , "fd00::1..fd00::2" })
331
+ Expect (err ).ShouldNot (HaveOccurred ())
332
+
333
+ _ , _ , _ , err = im .GetRandomAddress ("pod1.ns" , "pod1.ns" , subnetName , nil )
334
+ Expect (err ).Should (MatchError (ipam .ErrNoAvailable ))
335
+ })
284
336
})
285
337
})
286
338
0 commit comments