@@ -102,7 +102,7 @@ func TestAllowedServiceTags(t *testing.T) {
102
102
},
103
103
ObjectMeta : metav1.ObjectMeta {
104
104
Annotations : map [string ]string {
105
- consts .ServiceAnnotationAllowedServiceTags : "Microsoft.ContainerInstance/containerGroups,foo,bar" ,
105
+ consts .ServiceAnnotationAllowedServiceTags : " Microsoft.ContainerInstance/containerGroups, foo, bar " ,
106
106
},
107
107
},
108
108
})
@@ -125,7 +125,7 @@ func TestAllowedIPRanges(t *testing.T) {
125
125
assert .Empty (t , actual )
126
126
assert .Empty (t , invalid )
127
127
})
128
- t .Run ("with 1 IPv4 range" , func (t * testing.T ) {
128
+ t .Run ("with 1 IPv4 range in allowed ip ranges " , func (t * testing.T ) {
129
129
actual , invalid , err := AllowedIPRanges (& v1.Service {
130
130
Spec : v1.ServiceSpec {
131
131
Type : v1 .ServiceTypeLoadBalancer ,
@@ -140,7 +140,22 @@ func TestAllowedIPRanges(t *testing.T) {
140
140
assert .Equal (t , []netip.Prefix {netip .MustParsePrefix ("10.10.0.0/24" )}, actual )
141
141
assert .Empty (t , invalid )
142
142
})
143
- t .Run ("with 1 IPv6 range" , func (t * testing.T ) {
143
+ t .Run ("with 1 IPv4 range in load balancer source ranges" , func (t * testing.T ) {
144
+ actual , invalid , err := AllowedIPRanges (& v1.Service {
145
+ Spec : v1.ServiceSpec {
146
+ Type : v1 .ServiceTypeLoadBalancer ,
147
+ },
148
+ ObjectMeta : metav1.ObjectMeta {
149
+ Annotations : map [string ]string {
150
+ v1 .AnnotationLoadBalancerSourceRangesKey : "10.10.0.0/24" ,
151
+ },
152
+ },
153
+ })
154
+ assert .NoError (t , err )
155
+ assert .Equal (t , []netip.Prefix {netip .MustParsePrefix ("10.10.0.0/24" )}, actual )
156
+ assert .Empty (t , invalid )
157
+ })
158
+ t .Run ("with 1 IPv6 range in allowed ip ranges" , func (t * testing.T ) {
144
159
actual , invalid , err := AllowedIPRanges (& v1.Service {
145
160
Spec : v1.ServiceSpec {
146
161
Type : v1 .ServiceTypeLoadBalancer ,
@@ -155,21 +170,39 @@ func TestAllowedIPRanges(t *testing.T) {
155
170
assert .Equal (t , []netip.Prefix {netip .MustParsePrefix ("2001:db8::/32" )}, actual )
156
171
assert .Empty (t , invalid )
157
172
})
173
+ t .Run ("with 1 IPv6 range in load balancer source ranges" , func (t * testing.T ) {
174
+ actual , invalid , err := AllowedIPRanges (& v1.Service {
175
+ Spec : v1.ServiceSpec {
176
+ Type : v1 .ServiceTypeLoadBalancer ,
177
+ },
178
+ ObjectMeta : metav1.ObjectMeta {
179
+ Annotations : map [string ]string {
180
+ v1 .AnnotationLoadBalancerSourceRangesKey : "2001:db8::/32" ,
181
+ },
182
+ },
183
+ })
184
+ assert .NoError (t , err )
185
+ assert .Equal (t , []netip.Prefix {netip .MustParsePrefix ("2001:db8::/32" )}, actual )
186
+ assert .Empty (t , invalid )
187
+ })
158
188
t .Run ("with multiple IP ranges" , func (t * testing.T ) {
159
189
actual , invalid , err := AllowedIPRanges (& v1.Service {
160
190
Spec : v1.ServiceSpec {
161
191
Type : v1 .ServiceTypeLoadBalancer ,
162
192
},
163
193
ObjectMeta : metav1.ObjectMeta {
164
194
Annotations : map [string ]string {
165
- consts .ServiceAnnotationAllowedIPRanges : "10.10.0.0/24,2001:db8::/32" ,
195
+ consts .ServiceAnnotationAllowedIPRanges : " 10.10.0.0/24, 2001:db8::/32 " ,
196
+ v1 .AnnotationLoadBalancerSourceRangesKey : " 10.20.0.0/24, 2002:db8::/32 " ,
166
197
},
167
198
},
168
199
})
169
200
assert .NoError (t , err )
170
201
assert .Equal (t , []netip.Prefix {
171
202
netip .MustParsePrefix ("10.10.0.0/24" ),
172
203
netip .MustParsePrefix ("2001:db8::/32" ),
204
+ netip .MustParsePrefix ("10.20.0.0/24" ),
205
+ netip .MustParsePrefix ("2002:db8::/32" ),
173
206
}, actual )
174
207
assert .Empty (t , invalid )
175
208
})
@@ -180,16 +213,16 @@ func TestAllowedIPRanges(t *testing.T) {
180
213
},
181
214
ObjectMeta : metav1.ObjectMeta {
182
215
Annotations : map [string ]string {
183
- consts .ServiceAnnotationAllowedIPRanges : "foobar,10.0.0.1/24" ,
216
+ consts .ServiceAnnotationAllowedIPRanges : "foobar,10.0.0.1/24" ,
217
+ v1 .AnnotationLoadBalancerSourceRangesKey : "barfoo,2002:db8::1/32" ,
184
218
},
185
219
},
186
220
})
187
221
assert .Error (t , err )
188
222
189
223
var e * ErrAnnotationValue
190
224
assert .ErrorAs (t , err , & e )
191
- assert .Equal (t , e .AnnotationKey , consts .ServiceAnnotationAllowedIPRanges )
192
- assert .Equal (t , []string {"foobar" , "10.0.0.1/24" }, invalid )
225
+ assert .Equal (t , []string {"foobar" , "10.0.0.1/24" , "barfoo" , "2002:db8::1/32" }, invalid )
193
226
})
194
227
}
195
228
@@ -218,42 +251,6 @@ func TestSourceRanges(t *testing.T) {
218
251
}, actual )
219
252
assert .Empty (t , invalid )
220
253
})
221
- t .Run ("specified in annotation" , func (t * testing.T ) {
222
- actual , invalid , err := SourceRanges (& v1.Service {
223
- Spec : v1.ServiceSpec {
224
- Type : v1 .ServiceTypeLoadBalancer ,
225
- },
226
- ObjectMeta : metav1.ObjectMeta {
227
- Annotations : map [string ]string {
228
- v1 .AnnotationLoadBalancerSourceRangesKey : "10.10.0.0/24,2001:db8::/32" ,
229
- },
230
- },
231
- })
232
- assert .NoError (t , err )
233
- assert .Equal (t , []netip.Prefix {
234
- netip .MustParsePrefix ("10.10.0.0/24" ),
235
- netip .MustParsePrefix ("2001:db8::/32" ),
236
- }, actual )
237
- assert .Empty (t , invalid )
238
- })
239
- t .Run ("specified in both spec and annotation" , func (t * testing.T ) {
240
- actual , invalid , err := SourceRanges (& v1.Service {
241
- Spec : v1.ServiceSpec {
242
- Type : v1 .ServiceTypeLoadBalancer ,
243
- LoadBalancerSourceRanges : []string {"10.10.0.0/24" },
244
- },
245
- ObjectMeta : metav1.ObjectMeta {
246
- Annotations : map [string ]string {
247
- v1 .AnnotationLoadBalancerSourceRangesKey : "2001:db8::/32" ,
248
- },
249
- },
250
- })
251
- assert .NoError (t , err )
252
- assert .Equal (t , []netip.Prefix {
253
- netip .MustParsePrefix ("10.10.0.0/24" ),
254
- }, actual , "spec should take precedence over annotation" )
255
- assert .Empty (t , invalid )
256
- })
257
254
t .Run ("with invalid IP range in spec" , func (t * testing.T ) {
258
255
_ , invalid , err := SourceRanges (& v1.Service {
259
256
Spec : v1.ServiceSpec {
@@ -267,25 +264,6 @@ func TestSourceRanges(t *testing.T) {
267
264
assert .Error (t , err )
268
265
assert .Equal (t , []string {"foobar" , "10.0.0.1/24" }, invalid )
269
266
})
270
-
271
- t .Run ("with invalid IP range in annotation" , func (t * testing.T ) {
272
- _ , invalid , err := SourceRanges (& v1.Service {
273
- Spec : v1.ServiceSpec {
274
- Type : v1 .ServiceTypeLoadBalancer ,
275
- },
276
- ObjectMeta : metav1.ObjectMeta {
277
- Annotations : map [string ]string {
278
- v1 .AnnotationLoadBalancerSourceRangesKey : "foobar,10.0.0.1/24" ,
279
- },
280
- },
281
- })
282
- assert .Error (t , err )
283
-
284
- var e * ErrAnnotationValue
285
- assert .ErrorAs (t , err , & e )
286
- assert .Equal (t , e .AnnotationKey , v1 .AnnotationLoadBalancerSourceRangesKey )
287
- assert .Equal (t , []string {"foobar" , "10.0.0.1/24" }, invalid )
288
- })
289
267
}
290
268
291
269
func TestAdditionalPublicIPs (t * testing.T ) {
0 commit comments