@@ -1341,14 +1341,21 @@ func TestCompareEnv(t *testing.T) {
1341
1341
}
1342
1342
}
1343
1343
1344
- func newService (ann map [string ]string , svcT v1.ServiceType , lbSr []string ) * v1.Service {
1344
+ func newService (
1345
+ annotations map [string ]string ,
1346
+ svcType v1.ServiceType ,
1347
+ sourceRanges []string ,
1348
+ selector map [string ]string ,
1349
+ policy v1.ServiceExternalTrafficPolicyType ) * v1.Service {
1345
1350
svc := & v1.Service {
1346
1351
Spec : v1.ServiceSpec {
1347
- Type : svcT ,
1348
- LoadBalancerSourceRanges : lbSr ,
1352
+ Selector : selector ,
1353
+ Type : svcType ,
1354
+ LoadBalancerSourceRanges : sourceRanges ,
1355
+ ExternalTrafficPolicy : policy ,
1349
1356
},
1350
1357
}
1351
- svc .Annotations = ann
1358
+ svc .Annotations = annotations
1352
1359
return svc
1353
1360
}
1354
1361
@@ -1365,13 +1372,18 @@ func TestCompareServices(t *testing.T) {
1365
1372
},
1366
1373
}
1367
1374
1375
+ defaultPolicy := v1 .ServiceExternalTrafficPolicyTypeCluster
1376
+
1368
1377
serviceWithOwnerReference := newService (
1369
1378
map [string ]string {
1370
1379
constants .ZalandoDNSNameAnnotation : "clstr.acid.zalan.do" ,
1371
1380
constants .ElbTimeoutAnnotationName : constants .ElbTimeoutAnnotationValue ,
1372
1381
},
1373
1382
v1 .ServiceTypeClusterIP ,
1374
- []string {"128.141.0.0/16" , "137.138.0.0/16" })
1383
+ []string {"128.141.0.0/16" , "137.138.0.0/16" },
1384
+ nil ,
1385
+ defaultPolicy ,
1386
+ )
1375
1387
1376
1388
ownerRef := metav1.OwnerReference {
1377
1389
APIVersion : "acid.zalan.do/v1" ,
@@ -1397,14 +1409,16 @@ func TestCompareServices(t *testing.T) {
1397
1409
constants .ElbTimeoutAnnotationName : constants .ElbTimeoutAnnotationValue ,
1398
1410
},
1399
1411
v1 .ServiceTypeClusterIP ,
1400
- []string {"128.141.0.0/16" , "137.138.0.0/16" }),
1412
+ []string {"128.141.0.0/16" , "137.138.0.0/16" },
1413
+ nil , defaultPolicy ),
1401
1414
new : newService (
1402
1415
map [string ]string {
1403
1416
constants .ZalandoDNSNameAnnotation : "clstr.acid.zalan.do" ,
1404
1417
constants .ElbTimeoutAnnotationName : constants .ElbTimeoutAnnotationValue ,
1405
1418
},
1406
1419
v1 .ServiceTypeClusterIP ,
1407
- []string {"128.141.0.0/16" , "137.138.0.0/16" }),
1420
+ []string {"128.141.0.0/16" , "137.138.0.0/16" },
1421
+ nil , defaultPolicy ),
1408
1422
match : true ,
1409
1423
},
1410
1424
{
@@ -1415,14 +1429,16 @@ func TestCompareServices(t *testing.T) {
1415
1429
constants .ElbTimeoutAnnotationName : constants .ElbTimeoutAnnotationValue ,
1416
1430
},
1417
1431
v1 .ServiceTypeClusterIP ,
1418
- []string {"128.141.0.0/16" , "137.138.0.0/16" }),
1432
+ []string {"128.141.0.0/16" , "137.138.0.0/16" },
1433
+ nil , defaultPolicy ),
1419
1434
new : newService (
1420
1435
map [string ]string {
1421
1436
constants .ZalandoDNSNameAnnotation : "clstr.acid.zalan.do" ,
1422
1437
constants .ElbTimeoutAnnotationName : constants .ElbTimeoutAnnotationValue ,
1423
1438
},
1424
1439
v1 .ServiceTypeLoadBalancer ,
1425
- []string {"128.141.0.0/16" , "137.138.0.0/16" }),
1440
+ []string {"128.141.0.0/16" , "137.138.0.0/16" },
1441
+ nil , defaultPolicy ),
1426
1442
match : false ,
1427
1443
reason : `new service's type "LoadBalancer" does not match the current one "ClusterIP"` ,
1428
1444
},
@@ -1434,14 +1450,16 @@ func TestCompareServices(t *testing.T) {
1434
1450
constants .ElbTimeoutAnnotationName : constants .ElbTimeoutAnnotationValue ,
1435
1451
},
1436
1452
v1 .ServiceTypeLoadBalancer ,
1437
- []string {"128.141.0.0/16" , "137.138.0.0/16" }),
1453
+ []string {"128.141.0.0/16" , "137.138.0.0/16" },
1454
+ nil , defaultPolicy ),
1438
1455
new : newService (
1439
1456
map [string ]string {
1440
1457
constants .ZalandoDNSNameAnnotation : "clstr.acid.zalan.do" ,
1441
1458
constants .ElbTimeoutAnnotationName : constants .ElbTimeoutAnnotationValue ,
1442
1459
},
1443
1460
v1 .ServiceTypeLoadBalancer ,
1444
- []string {"185.249.56.0/22" }),
1461
+ []string {"185.249.56.0/22" },
1462
+ nil , defaultPolicy ),
1445
1463
match : false ,
1446
1464
reason : `new service's LoadBalancerSourceRange does not match the current one` ,
1447
1465
},
@@ -1453,14 +1471,16 @@ func TestCompareServices(t *testing.T) {
1453
1471
constants .ElbTimeoutAnnotationName : constants .ElbTimeoutAnnotationValue ,
1454
1472
},
1455
1473
v1 .ServiceTypeLoadBalancer ,
1456
- []string {"128.141.0.0/16" , "137.138.0.0/16" }),
1474
+ []string {"128.141.0.0/16" , "137.138.0.0/16" },
1475
+ nil , defaultPolicy ),
1457
1476
new : newService (
1458
1477
map [string ]string {
1459
1478
constants .ZalandoDNSNameAnnotation : "clstr.acid.zalan.do" ,
1460
1479
constants .ElbTimeoutAnnotationName : constants .ElbTimeoutAnnotationValue ,
1461
1480
},
1462
1481
v1 .ServiceTypeLoadBalancer ,
1463
- []string {}),
1482
+ []string {},
1483
+ nil , defaultPolicy ),
1464
1484
match : false ,
1465
1485
reason : `new service's LoadBalancerSourceRange does not match the current one` ,
1466
1486
},
@@ -1472,10 +1492,39 @@ func TestCompareServices(t *testing.T) {
1472
1492
constants .ElbTimeoutAnnotationName : constants .ElbTimeoutAnnotationValue ,
1473
1493
},
1474
1494
v1 .ServiceTypeClusterIP ,
1475
- []string {"128.141.0.0/16" , "137.138.0.0/16" }),
1495
+ []string {"128.141.0.0/16" , "137.138.0.0/16" },
1496
+ nil , defaultPolicy ),
1476
1497
new : serviceWithOwnerReference ,
1477
1498
match : false ,
1478
1499
},
1500
+ {
1501
+ about : "new service has a label selector" ,
1502
+ current : newService (
1503
+ map [string ]string {},
1504
+ v1 .ServiceTypeClusterIP ,
1505
+ []string {},
1506
+ nil , defaultPolicy ),
1507
+ new : newService (
1508
+ map [string ]string {},
1509
+ v1 .ServiceTypeClusterIP ,
1510
+ []string {},
1511
+ map [string ]string {"cluster-name" : "clstr" , "spilo-role" : "master" }, defaultPolicy ),
1512
+ match : false ,
1513
+ },
1514
+ {
1515
+ about : "services differ on external traffic policy" ,
1516
+ current : newService (
1517
+ map [string ]string {},
1518
+ v1 .ServiceTypeClusterIP ,
1519
+ []string {},
1520
+ nil , defaultPolicy ),
1521
+ new : newService (
1522
+ map [string ]string {},
1523
+ v1 .ServiceTypeClusterIP ,
1524
+ []string {},
1525
+ nil , v1 .ServiceExternalTrafficPolicyTypeLocal ),
1526
+ match : false ,
1527
+ },
1479
1528
}
1480
1529
1481
1530
for _ , tt := range tests {
0 commit comments