@@ -42,7 +42,6 @@ import (
42
42
"k8s.io/cloud-provider-gcp/pkg/controller/testutil"
43
43
"k8s.io/cloud-provider-gcp/providers/gce"
44
44
metricsUtil "k8s.io/component-base/metrics/testutil"
45
- netutils "k8s.io/utils/net"
46
45
)
47
46
48
47
const (
@@ -98,10 +97,6 @@ func TestBoundedRetries(t *testing.T) {
98
97
}
99
98
}
100
99
101
- func withinExpectedRange (got time.Duration , expected time.Duration ) bool {
102
- return got >= expected / 2 && got <= 3 * expected / 2
103
- }
104
-
105
100
func TestUpdateCIDRAllocation (t * testing.T ) {
106
101
tests := []struct {
107
102
name string
@@ -131,7 +126,7 @@ func TestUpdateCIDRAllocation(t *testing.T) {
131
126
nodeChanges : func (node * v1.Node ) {},
132
127
},
133
128
{
134
- name : "provider not set" ,
129
+ name : "want error - provider not set" ,
135
130
fakeNodeHandler : & testutil.FakeNodeHandler {
136
131
Existing : []* v1.Node {
137
132
{
@@ -152,7 +147,7 @@ func TestUpdateCIDRAllocation(t *testing.T) {
152
147
expectErrMsg : "doesn't have providerID" ,
153
148
},
154
149
{
155
- name : "node not found in gce by provider" ,
150
+ name : "want error - node not found in gce by provider" ,
156
151
fakeNodeHandler : & testutil.FakeNodeHandler {
157
152
Existing : []* v1.Node {
158
153
{
@@ -176,7 +171,7 @@ func TestUpdateCIDRAllocation(t *testing.T) {
176
171
expectErrMsg : "failed to get instance from provider" ,
177
172
},
178
173
{
179
- name : "gce node has no networks" ,
174
+ name : "want error - gce node has no networks" ,
180
175
fakeNodeHandler : & testutil.FakeNodeHandler {
181
176
Existing : []* v1.Node {
182
177
{
@@ -287,7 +282,7 @@ func TestUpdateCIDRAllocation(t *testing.T) {
287
282
expectedUpdate : true ,
288
283
},
289
284
{
290
- name : "incorrect cidr" ,
285
+ name : "want error - incorrect cidr" ,
291
286
fakeNodeHandler : & testutil.FakeNodeHandler {
292
287
Existing : []* v1.Node {
293
288
{
@@ -320,6 +315,40 @@ func TestUpdateCIDRAllocation(t *testing.T) {
320
315
expectErr : true ,
321
316
expectErrMsg : "failed to parse strings" ,
322
317
},
318
+ {
319
+ name : "want error - incorrect dualstack cidr" ,
320
+ fakeNodeHandler : & testutil.FakeNodeHandler {
321
+ Existing : []* v1.Node {
322
+ {
323
+ ObjectMeta : metav1.ObjectMeta {
324
+ Name : "test" ,
325
+ },
326
+ Spec : v1.NodeSpec {
327
+ ProviderID : "gce://test-project/us-central1-b/test" ,
328
+ },
329
+ },
330
+ },
331
+ Clientset : fake .NewSimpleClientset (),
332
+ },
333
+ gceInstance : []* compute.Instance {
334
+ {
335
+ Name : "test" ,
336
+ NetworkInterfaces : []* compute.NetworkInterface {
337
+ {
338
+ Ipv6Address : "10.10.1.0" ,
339
+ AliasIpRanges : []* compute.AliasIpRange {
340
+ {
341
+ IpCidrRange : "192.168.1.0/24" ,
342
+ },
343
+ },
344
+ },
345
+ },
346
+ },
347
+ },
348
+ nodeChanges : func (node * v1.Node ) {},
349
+ expectErr : true ,
350
+ expectErrMsg : "err: IPs are not dual stack" ,
351
+ },
323
352
{
324
353
name : "node already configured" ,
325
354
fakeNodeHandler : & testutil.FakeNodeHandler {
@@ -804,7 +833,7 @@ func TestUpdateCIDRAllocation(t *testing.T) {
804
833
},
805
834
},
806
835
{
807
- name : "[mn] [invalid] - node with cidrs in incorrect format" ,
836
+ name : "[mn] want error - node with cidrs in incorrect format" ,
808
837
networks : []* networkv1.Network {
809
838
network (networkv1 .DefaultPodNetworkName , defaultGKENetworkParamsName , true ),
810
839
network (redNetworkName , redGKENetworkParamsName , true ),
@@ -860,7 +889,7 @@ func TestUpdateCIDRAllocation(t *testing.T) {
860
889
expectErrMsg : "invalid CIDR address" ,
861
890
},
862
891
{
863
- name : "[mn] one additional network with /32 cidr" ,
892
+ name : "[mn] want error - one additional network with /32 cidr" ,
864
893
networks : []* networkv1.Network {
865
894
network (networkv1 .DefaultPodNetworkName , defaultGKENetworkParamsName , true ),
866
895
network (redNetworkName , redGKENetworkParamsName , true ),
@@ -1321,106 +1350,3 @@ func interfaces(network, subnetwork, networkIP string, aliasIPRanges []*compute.
1321
1350
NetworkIP : networkIP ,
1322
1351
}
1323
1352
}
1324
-
1325
- func TestNeedPodCIDRsUpdate (t * testing.T ) {
1326
- for _ , tc := range []struct {
1327
- desc string
1328
- cidrs []string
1329
- nodePodCIDR string
1330
- nodePodCIDRs []string
1331
- want bool
1332
- wantErr bool
1333
- }{
1334
- {
1335
- desc : "want error - invalid cidr" ,
1336
- cidrs : []string {"10.10.10.0/24" },
1337
- nodePodCIDR : "10.10..0/24" ,
1338
- nodePodCIDRs : []string {"10.10..0/24" },
1339
- want : true ,
1340
- },
1341
- {
1342
- desc : "want error - cidr len 2 but not dual stack" ,
1343
- cidrs : []string {"10.10.10.0/24" , "10.10.11.0/24" },
1344
- nodePodCIDR : "10.10.10.0/24" ,
1345
- nodePodCIDRs : []string {"10.10.10.0/24" , "2001:db8::/64" },
1346
- wantErr : true ,
1347
- },
1348
- {
1349
- desc : "want false - matching v4 only cidr" ,
1350
- cidrs : []string {"10.10.10.0/24" },
1351
- nodePodCIDR : "10.10.10.0/24" ,
1352
- nodePodCIDRs : []string {"10.10.10.0/24" },
1353
- want : false ,
1354
- },
1355
- {
1356
- desc : "want false - nil node.Spec.PodCIDR" ,
1357
- cidrs : []string {"10.10.10.0/24" },
1358
- want : true ,
1359
- },
1360
- {
1361
- desc : "want true - non matching v4 only cidr" ,
1362
- cidrs : []string {"10.10.10.0/24" },
1363
- nodePodCIDR : "10.10.11.0/24" ,
1364
- nodePodCIDRs : []string {"10.10.11.0/24" },
1365
- want : true ,
1366
- },
1367
- {
1368
- desc : "want false - matching v4 and v6 cidrs" ,
1369
- cidrs : []string {"10.10.10.0/24" , "2001:db8::/64" },
1370
- nodePodCIDR : "10.10.10.0/24" ,
1371
- nodePodCIDRs : []string {"10.10.10.0/24" , "2001:db8::/64" },
1372
- want : false ,
1373
- },
1374
- {
1375
- desc : "want false - matching v4 and v6 cidrs, different strings but same CIDRs" ,
1376
- cidrs : []string {"10.10.10.0/24" , "2001:db8::/64" },
1377
- nodePodCIDR : "10.10.10.0/24" ,
1378
- nodePodCIDRs : []string {"10.10.10.0/24" , "2001:db8:0::/64" },
1379
- want : false ,
1380
- },
1381
- {
1382
- desc : "want true - matching v4 and non matching v6 cidrs" ,
1383
- cidrs : []string {"10.10.10.0/24" , "2001:db8::/64" },
1384
- nodePodCIDR : "10.10.10.0/24" ,
1385
- nodePodCIDRs : []string {"10.10.10.0/24" , "2001:dba::/64" },
1386
- want : true ,
1387
- },
1388
- {
1389
- desc : "want true - nil node.Spec.PodCIDRs" ,
1390
- cidrs : []string {"10.10.10.0/24" , "2001:db8::/64" },
1391
- want : true ,
1392
- },
1393
- {
1394
- desc : "want true - matching v6 and non matching v4 cidrs" ,
1395
- cidrs : []string {"10.10.10.0/24" , "2001:db8::/64" },
1396
- nodePodCIDR : "10.10.1.0/24" ,
1397
- nodePodCIDRs : []string {"10.10.1.0/24" , "2001:db8::/64" },
1398
- want : true ,
1399
- },
1400
- {
1401
- desc : "want true - missing v6" ,
1402
- cidrs : []string {"10.10.10.0/24" , "2001:db8::/64" },
1403
- nodePodCIDR : "10.10.10.0/24" ,
1404
- nodePodCIDRs : []string {"10.10.10.0/24" },
1405
- want : true ,
1406
- },
1407
- } {
1408
- var node v1.Node
1409
- node .Spec .PodCIDR = tc .nodePodCIDR
1410
- node .Spec .PodCIDRs = tc .nodePodCIDRs
1411
- netCIDRs , err := netutils .ParseCIDRs (tc .cidrs )
1412
- if err != nil {
1413
- t .Errorf ("failed to parse %v as CIDRs: %v" , tc .cidrs , err )
1414
- }
1415
-
1416
- t .Run (tc .desc , func (t * testing.T ) {
1417
- got , err := needPodCIDRsUpdate (& node , netCIDRs )
1418
- if tc .wantErr == (err == nil ) {
1419
- t .Errorf ("err: %v, wantErr: %v" , err , tc .wantErr )
1420
- }
1421
- if err == nil && got != tc .want {
1422
- t .Errorf ("got: %v, want: %v" , got , tc .want )
1423
- }
1424
- })
1425
- }
1426
- }
0 commit comments