@@ -76,12 +76,16 @@ const (
76
76
// Bring the cleanup timeout back down to 5m once b/33588344 is resolved.
77
77
LoadBalancerCleanupTimeout = 15 * time .Minute
78
78
79
+ // LoadBalancerPollTimeout is the time required by the loadbalancer to poll.
79
80
// On average it takes ~6 minutes for a single backend to come online in GCE.
80
- LoadBalancerPollTimeout = 15 * time .Minute
81
+ LoadBalancerPollTimeout = 15 * time .Minute
82
+ // LoadBalancerPollInterval is the interval value in which the loadbalancer polls.
81
83
LoadBalancerPollInterval = 30 * time .Second
82
84
85
+ // LargeClusterMinNodesNumber is the number of nodes which a large cluster consists of.
83
86
LargeClusterMinNodesNumber = 100
84
87
88
+ // MaxNodesForEndpointsTests is the max number for testing endpoints.
85
89
// Don't test with more than 3 nodes.
86
90
// Many tests create an endpoint per node, in large clusters, this is
87
91
// resource and time intensive.
@@ -236,6 +240,7 @@ func (j *ServiceTestJig) CreateServiceWithServicePort(labels map[string]string,
236
240
return j .Client .CoreV1 ().Services (namespace ).Create (service )
237
241
}
238
242
243
+ // ChangeServiceType updates the given service's ServiceType to the given newType.
239
244
func (j * ServiceTestJig ) ChangeServiceType (namespace , name string , newType v1.ServiceType , timeout time.Duration ) {
240
245
ingressIP := ""
241
246
svc := j .UpdateServiceOrFail (namespace , name , func (s * v1.Service ) {
@@ -318,6 +323,7 @@ func (j *ServiceTestJig) CreateLoadBalancerService(namespace, serviceName string
318
323
return svc
319
324
}
320
325
326
+ // GetNodeAddresses returns a list of addresses of the given addressType for the given node
321
327
func GetNodeAddresses (node * v1.Node , addressType v1.NodeAddressType ) (ips []string ) {
322
328
for j := range node .Status .Addresses {
323
329
nodeAddress := & node .Status .Addresses [j ]
@@ -328,6 +334,7 @@ func GetNodeAddresses(node *v1.Node, addressType v1.NodeAddressType) (ips []stri
328
334
return
329
335
}
330
336
337
+ // CollectAddresses returns a list of addresses of the given addressType for the given list of nodes
331
338
func CollectAddresses (nodes * v1.NodeList , addressType v1.NodeAddressType ) []string {
332
339
ips := []string {}
333
340
for i := range nodes .Items {
@@ -336,6 +343,7 @@ func CollectAddresses(nodes *v1.NodeList, addressType v1.NodeAddressType) []stri
336
343
return ips
337
344
}
338
345
346
+ // GetNodePublicIps returns a public IP list of nodes.
339
347
func GetNodePublicIps (c clientset.Interface ) ([]string , error ) {
340
348
nodes := GetReadySchedulableNodesOrDie (c )
341
349
@@ -347,6 +355,7 @@ func GetNodePublicIps(c clientset.Interface) ([]string, error) {
347
355
return ips , nil
348
356
}
349
357
358
+ // PickNodeIP picks one public node IP
350
359
func PickNodeIP (c clientset.Interface ) string {
351
360
publicIps , err := GetNodePublicIps (c )
352
361
ExpectNoError (err )
@@ -415,6 +424,7 @@ func (j *ServiceTestJig) GetNodes(maxNodesForTest int) (nodes *v1.NodeList) {
415
424
return nodes
416
425
}
417
426
427
+ // GetNodesNames returns a list of names of the first maxNodesForTest nodes
418
428
func (j * ServiceTestJig ) GetNodesNames (maxNodesForTest int ) []string {
419
429
nodes := j .GetNodes (maxNodesForTest )
420
430
nodesNames := []string {}
@@ -424,6 +434,7 @@ func (j *ServiceTestJig) GetNodesNames(maxNodesForTest int) []string {
424
434
return nodesNames
425
435
}
426
436
437
+ // WaitForEndpointOnNode waits for a service endpoint on the given node.
427
438
func (j * ServiceTestJig ) WaitForEndpointOnNode (namespace , serviceName , nodeName string ) {
428
439
err := wait .PollImmediate (Poll , LoadBalancerCreateTimeoutDefault , func () (bool , error ) {
429
440
endpoints , err := j .Client .CoreV1 ().Endpoints (namespace ).Get (serviceName , metav1.GetOptions {})
@@ -451,6 +462,7 @@ func (j *ServiceTestJig) WaitForEndpointOnNode(namespace, serviceName, nodeName
451
462
ExpectNoError (err )
452
463
}
453
464
465
+ // SanityCheckService performs sanity checks on the given service
454
466
func (j * ServiceTestJig ) SanityCheckService (svc * v1.Service , svcType v1.ServiceType ) {
455
467
if svc .Spec .Type != svcType {
456
468
Failf ("unexpected Spec.Type (%s) for service, expected %s" , svc .Spec .Type , svcType )
@@ -533,6 +545,7 @@ func (j *ServiceTestJig) UpdateServiceOrFail(namespace, name string, update func
533
545
return svc
534
546
}
535
547
548
+ // WaitForNewIngressIPOrFail waits for the given service to get a new ingress IP, or fails after the given timeout
536
549
func (j * ServiceTestJig ) WaitForNewIngressIPOrFail (namespace , name , existingIP string , timeout time.Duration ) * v1.Service {
537
550
Logf ("Waiting up to %v for service %q to get a new ingress IP" , timeout , name )
538
551
service := j .waitForConditionOrFail (namespace , name , timeout , "have a new ingress IP" , func (svc * v1.Service ) bool {
@@ -548,6 +561,7 @@ func (j *ServiceTestJig) WaitForNewIngressIPOrFail(namespace, name, existingIP s
548
561
return service
549
562
}
550
563
564
+ // ChangeServiceNodePortOrFail changes node ports of the given service.
551
565
func (j * ServiceTestJig ) ChangeServiceNodePortOrFail (namespace , name string , initial int ) * v1.Service {
552
566
var err error
553
567
var service * v1.Service
@@ -571,6 +585,7 @@ func (j *ServiceTestJig) ChangeServiceNodePortOrFail(namespace, name string, ini
571
585
return service
572
586
}
573
587
588
+ // WaitForLoadBalancerOrFail waits the given service to have a LoadBalancer, or fails after the given timeout
574
589
func (j * ServiceTestJig ) WaitForLoadBalancerOrFail (namespace , name string , timeout time.Duration ) * v1.Service {
575
590
Logf ("Waiting up to %v for service %q to have a LoadBalancer" , timeout , name )
576
591
service := j .waitForConditionOrFail (namespace , name , timeout , "have a load balancer" , func (svc * v1.Service ) bool {
@@ -579,6 +594,7 @@ func (j *ServiceTestJig) WaitForLoadBalancerOrFail(namespace, name string, timeo
579
594
return service
580
595
}
581
596
597
+ // WaitForLoadBalancerDestroyOrFail waits the given service to destroy a LoadBalancer, or fails after the given timeout
582
598
func (j * ServiceTestJig ) WaitForLoadBalancerDestroyOrFail (namespace , name string , ip string , port int , timeout time.Duration ) * v1.Service {
583
599
// TODO: once support ticket 21807001 is resolved, reduce this timeout back to something reasonable
584
600
defer func () {
@@ -658,6 +674,7 @@ func (j *ServiceTestJig) newRCTemplate(namespace string) *v1.ReplicationControll
658
674
return rc
659
675
}
660
676
677
+ // AddRCAntiAffinity adds AntiAffinity to the given ReplicationController.
661
678
func (j * ServiceTestJig ) AddRCAntiAffinity (rc * v1.ReplicationController ) {
662
679
var replicas int32 = 2
663
680
@@ -677,6 +694,7 @@ func (j *ServiceTestJig) AddRCAntiAffinity(rc *v1.ReplicationController) {
677
694
})
678
695
}
679
696
697
+ // CreatePDBOrFail returns a PodDisruptionBudget for the given ReplicationController, or fails if a PodDisruptionBudget isn't ready
680
698
func (j * ServiceTestJig ) CreatePDBOrFail (namespace string , rc * v1.ReplicationController ) * policyv1beta1.PodDisruptionBudget {
681
699
pdb := j .newPDBTemplate (namespace , rc )
682
700
newPdb , err := j .Client .PolicyV1beta1 ().PodDisruptionBudgets (namespace ).Create (pdb )
@@ -733,6 +751,7 @@ func (j *ServiceTestJig) RunOrFail(namespace string, tweak func(rc *v1.Replicati
733
751
return result
734
752
}
735
753
754
+ // Scale scales pods to the given replicas
736
755
func (j * ServiceTestJig ) Scale (namespace string , replicas int ) {
737
756
rc := j .Name
738
757
scale , err := j .Client .CoreV1 ().ReplicationControllers (namespace ).GetScale (rc , metav1.GetOptions {})
@@ -839,6 +858,7 @@ func newNetexecPodSpec(podName string, httpPort, udpPort int32, hostNetwork bool
839
858
return pod
840
859
}
841
860
861
+ // LaunchNetexecPodOnNode launches a netexec pod on the given node.
842
862
func (j * ServiceTestJig ) LaunchNetexecPodOnNode (f * Framework , nodeName , podName string , httpPort , udpPort int32 , hostNetwork bool ) {
843
863
Logf ("Creating netexec pod %q on node %v in namespace %q" , podName , nodeName , f .Namespace .Name )
844
864
pod := newNetexecPodSpec (podName , httpPort , udpPort , hostNetwork )
@@ -887,10 +907,12 @@ func (j *ServiceTestJig) LaunchEchoserverPodOnNode(f *Framework, nodeName, podNa
887
907
Logf ("Echo server pod %q in namespace %q running" , pod .Name , f .Namespace .Name )
888
908
}
889
909
910
+ // TestReachableHTTP tests that the given host serves HTTP on the given port.
890
911
func (j * ServiceTestJig ) TestReachableHTTP (host string , port int , timeout time.Duration ) {
891
912
j .TestReachableHTTPWithRetriableErrorCodes (host , port , []int {}, timeout )
892
913
}
893
914
915
+ // TestReachableHTTPWithRetriableErrorCodes tests that the given host serves HTTP on the given port with the given retriableErrCodes.
894
916
func (j * ServiceTestJig ) TestReachableHTTPWithRetriableErrorCodes (host string , port int , retriableErrCodes []int , timeout time.Duration ) {
895
917
pollfn := func () (bool , error ) {
896
918
result := PokeHTTP (host , port , "/echo?msg=hello" ,
@@ -913,6 +935,7 @@ func (j *ServiceTestJig) TestReachableHTTPWithRetriableErrorCodes(host string, p
913
935
}
914
936
}
915
937
938
+ // TestNotReachableHTTP tests that a HTTP request doesn't connect to the given host and port.
916
939
func (j * ServiceTestJig ) TestNotReachableHTTP (host string , port int , timeout time.Duration ) {
917
940
pollfn := func () (bool , error ) {
918
941
result := PokeHTTP (host , port , "/" , nil )
@@ -927,6 +950,7 @@ func (j *ServiceTestJig) TestNotReachableHTTP(host string, port int, timeout tim
927
950
}
928
951
}
929
952
953
+ // TestRejectedHTTP tests that the given host rejects a HTTP request on the given port.
930
954
func (j * ServiceTestJig ) TestRejectedHTTP (host string , port int , timeout time.Duration ) {
931
955
pollfn := func () (bool , error ) {
932
956
result := PokeHTTP (host , port , "/" , nil )
@@ -941,6 +965,7 @@ func (j *ServiceTestJig) TestRejectedHTTP(host string, port int, timeout time.Du
941
965
}
942
966
}
943
967
968
+ // TestReachableUDP tests that the given host serves UDP on the given port.
944
969
func (j * ServiceTestJig ) TestReachableUDP (host string , port int , timeout time.Duration ) {
945
970
pollfn := func () (bool , error ) {
946
971
result := PokeUDP (host , port , "echo hello" , & UDPPokeParams {
@@ -958,6 +983,7 @@ func (j *ServiceTestJig) TestReachableUDP(host string, port int, timeout time.Du
958
983
}
959
984
}
960
985
986
+ // TestNotReachableUDP tests that the given host doesn't serve UDP on the given port.
961
987
func (j * ServiceTestJig ) TestNotReachableUDP (host string , port int , timeout time.Duration ) {
962
988
pollfn := func () (bool , error ) {
963
989
result := PokeUDP (host , port , "echo hello" , & UDPPokeParams {Timeout : 3 * time .Second })
@@ -971,6 +997,7 @@ func (j *ServiceTestJig) TestNotReachableUDP(host string, port int, timeout time
971
997
}
972
998
}
973
999
1000
+ // TestRejectedUDP tests that the given host rejects a UDP request on the given port.
974
1001
func (j * ServiceTestJig ) TestRejectedUDP (host string , port int , timeout time.Duration ) {
975
1002
pollfn := func () (bool , error ) {
976
1003
result := PokeUDP (host , port , "echo hello" , & UDPPokeParams {Timeout : 3 * time .Second })
@@ -984,6 +1011,7 @@ func (j *ServiceTestJig) TestRejectedUDP(host string, port int, timeout time.Dur
984
1011
}
985
1012
}
986
1013
1014
+ // GetHTTPContent returns the content of the given url by HTTP.
987
1015
func (j * ServiceTestJig ) GetHTTPContent (host string , port int , timeout time.Duration , url string ) bytes.Buffer {
988
1016
var body bytes.Buffer
989
1017
if pollErr := wait .PollImmediate (Poll , timeout , func () (bool , error ) {
@@ -1028,6 +1056,7 @@ func testHTTPHealthCheckNodePort(ip string, port int, request string) (bool, err
1028
1056
return false , fmt .Errorf ("unexpected HTTP response code %s from health check responder at %s" , resp .Status , url )
1029
1057
}
1030
1058
1059
+ // TestHTTPHealthCheckNodePort tests a HTTP connection by the given request to the given host and port.
1031
1060
func (j * ServiceTestJig ) TestHTTPHealthCheckNodePort (host string , port int , request string , timeout time.Duration , expectSucceed bool , threshold int ) error {
1032
1061
count := 0
1033
1062
condition := func () (bool , error ) {
@@ -1063,6 +1092,7 @@ type ServiceTestFixture struct {
1063
1092
Image string
1064
1093
}
1065
1094
1095
+ // NewServerTest creates a new ServiceTestFixture for the tests.
1066
1096
func NewServerTest (client clientset.Interface , namespace string , serviceName string ) * ServiceTestFixture {
1067
1097
t := & ServiceTestFixture {}
1068
1098
t .Client = client
@@ -1127,6 +1157,7 @@ func (t *ServiceTestFixture) DeleteService(serviceName string) error {
1127
1157
return err
1128
1158
}
1129
1159
1160
+ // Cleanup cleans all ReplicationControllers and Services which this object holds.
1130
1161
func (t * ServiceTestFixture ) Cleanup () []error {
1131
1162
var errs []error
1132
1163
for rcName := range t .rcs {
@@ -1175,6 +1206,7 @@ func (t *ServiceTestFixture) Cleanup() []error {
1175
1206
return errs
1176
1207
}
1177
1208
1209
+ // GetIngressPoint returns a host on which ingress serves.
1178
1210
func GetIngressPoint (ing * v1.LoadBalancerIngress ) string {
1179
1211
host := ing .IP
1180
1212
if host == "" {
@@ -1206,6 +1238,7 @@ func UpdateService(c clientset.Interface, namespace, serviceName string, update
1206
1238
return service , err
1207
1239
}
1208
1240
1241
+ // GetContainerPortsByPodUID returns a PortsByPodUID map on the given endpoints.
1209
1242
func GetContainerPortsByPodUID (endpoints * v1.Endpoints ) PortsByPodUID {
1210
1243
m := PortsByPodUID {}
1211
1244
for _ , ss := range endpoints .Subsets {
@@ -1222,7 +1255,10 @@ func GetContainerPortsByPodUID(endpoints *v1.Endpoints) PortsByPodUID {
1222
1255
return m
1223
1256
}
1224
1257
1258
+ // PortsByPodName maps pod name to ports.
1225
1259
type PortsByPodName map [string ][]int
1260
+
1261
+ // PortsByPodUID maps UID to ports.
1226
1262
type PortsByPodUID map [types.UID ][]int
1227
1263
1228
1264
func translatePodNameToUIDOrFail (c clientset.Interface , ns string , expectedEndpoints PortsByPodName ) PortsByPodUID {
@@ -1261,6 +1297,7 @@ func validatePortsOrFail(endpoints PortsByPodUID, expectedEndpoints PortsByPodUI
1261
1297
}
1262
1298
}
1263
1299
1300
+ // ValidateEndpointsOrFail validates that the given service exists and is served by the given expectedEndpoints.
1264
1301
func ValidateEndpointsOrFail (c clientset.Interface , namespace , serviceName string , expectedEndpoints PortsByPodName ) {
1265
1302
ginkgo .By (fmt .Sprintf ("waiting up to %v for service %s in namespace %s to expose endpoints %v" , ServiceStartTimeout , serviceName , namespace , expectedEndpoints ))
1266
1303
i := 1
@@ -1348,6 +1385,7 @@ func StartServeHostnameService(c clientset.Interface, svc *v1.Service, ns string
1348
1385
return podNames , serviceIP , nil
1349
1386
}
1350
1387
1388
+ // StopServeHostnameService stops the given service.
1351
1389
func StopServeHostnameService (clientset clientset.Interface , ns , name string ) error {
1352
1390
if err := DeleteRCAndWaitForGC (clientset , ns , name ); err != nil {
1353
1391
return err
@@ -1439,6 +1477,7 @@ func VerifyServeHostnameServiceUp(c clientset.Interface, ns, host string, expect
1439
1477
return nil
1440
1478
}
1441
1479
1480
+ // VerifyServeHostnameServiceDown verifies that the given service isn't served.
1442
1481
func VerifyServeHostnameServiceDown (c clientset.Interface , host string , serviceIP string , servicePort int ) error {
1443
1482
ipPort := net .JoinHostPort (serviceIP , strconv .Itoa (servicePort ))
1444
1483
// The current versions of curl included in CentOS and RHEL distros
@@ -1466,13 +1505,15 @@ func CleanupServiceResources(c clientset.Interface, loadBalancerName, region, zo
1466
1505
TestContext .CloudConfig .Provider .CleanupServiceResources (c , loadBalancerName , region , zone )
1467
1506
}
1468
1507
1508
+ // DescribeSvc logs the output of kubectl describe svc for the given namespace
1469
1509
func DescribeSvc (ns string ) {
1470
1510
Logf ("\n Output of kubectl describe svc:\n " )
1471
1511
desc , _ := RunKubectl (
1472
1512
"describe" , "svc" , fmt .Sprintf ("--namespace=%v" , ns ))
1473
1513
Logf (desc )
1474
1514
}
1475
1515
1516
+ // CreateServiceSpec returns a Service object for testing.
1476
1517
func CreateServiceSpec (serviceName , externalName string , isHeadless bool , selector map [string ]string ) * v1.Service {
1477
1518
headlessService := & v1.Service {
1478
1519
ObjectMeta : metav1.ObjectMeta {
@@ -1502,6 +1543,7 @@ func EnableAndDisableInternalLB() (enable func(svc *v1.Service), disable func(sv
1502
1543
return TestContext .CloudConfig .Provider .EnableAndDisableInternalLB ()
1503
1544
}
1504
1545
1546
+ // GetServiceLoadBalancerCreationTimeout returns a timeout value for creating a load balancer of a service.
1505
1547
func GetServiceLoadBalancerCreationTimeout (cs clientset.Interface ) time.Duration {
1506
1548
if nodes := GetReadySchedulableNodesOrDie (cs ); len (nodes .Items ) > LargeClusterMinNodesNumber {
1507
1549
return LoadBalancerCreateTimeoutLarge
0 commit comments