Skip to content

Commit 9f2fa7d

Browse files
author
Jiatong Wang
committed
Remove unused function and clean up redundant code
1 parent 10fc2a1 commit 9f2fa7d

File tree

1 file changed

+13
-33
lines changed

1 file changed

+13
-33
lines changed

test/e2e/framework/service_util.go

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -507,18 +507,18 @@ func (j *ServiceTestJig) UpdateService(namespace, name string, update func(*v1.S
507507
for i := 0; i < 3; i++ {
508508
service, err := j.Client.CoreV1().Services(namespace).Get(name, metav1.GetOptions{})
509509
if err != nil {
510-
return nil, fmt.Errorf("Failed to get Service %q: %v", name, err)
510+
return nil, fmt.Errorf("failed to get Service %q: %v", name, err)
511511
}
512512
update(service)
513513
service, err = j.Client.CoreV1().Services(namespace).Update(service)
514514
if err == nil {
515515
return service, nil
516516
}
517517
if !errors.IsConflict(err) && !errors.IsServerTimeout(err) {
518-
return nil, fmt.Errorf("Failed to update Service %q: %v", name, err)
518+
return nil, fmt.Errorf("failed to update Service %q: %v", name, err)
519519
}
520520
}
521-
return nil, fmt.Errorf("Too many retries updating Service %q", name)
521+
return nil, fmt.Errorf("too many retries updating Service %q", name)
522522
}
523523

524524
// UpdateServiceOrFail fetches a service, calls the update function on it, and
@@ -573,10 +573,7 @@ func (j *ServiceTestJig) ChangeServiceNodePortOrFail(namespace, name string, ini
573573
func (j *ServiceTestJig) WaitForLoadBalancerOrFail(namespace, name string, timeout time.Duration) *v1.Service {
574574
Logf("Waiting up to %v for service %q to have a LoadBalancer", timeout, name)
575575
service := j.waitForConditionOrFail(namespace, name, timeout, "have a load balancer", func(svc *v1.Service) bool {
576-
if len(svc.Status.LoadBalancer.Ingress) > 0 {
577-
return true
578-
}
579-
return false
576+
return len(svc.Status.LoadBalancer.Ingress) > 0
580577
})
581578
return service
582579
}
@@ -591,10 +588,7 @@ func (j *ServiceTestJig) WaitForLoadBalancerDestroyOrFail(namespace, name string
591588

592589
Logf("Waiting up to %v for service %q to have no LoadBalancer", timeout, name)
593590
service := j.waitForConditionOrFail(namespace, name, timeout, "have no load balancer", func(svc *v1.Service) bool {
594-
if len(svc.Status.LoadBalancer.Ingress) == 0 {
595-
return true
596-
}
597-
return false
591+
return len(svc.Status.LoadBalancer.Ingress) == 0
598592
})
599593
return service
600594
}
@@ -757,7 +751,6 @@ func (j *ServiceTestJig) Scale(namespace string, replicas int) {
757751
if err := j.waitForPodsReady(namespace, pods); err != nil {
758752
Failf("Failed waiting for pods to be running: %v", err)
759753
}
760-
return
761754
}
762755

763756
func (j *ServiceTestJig) waitForPdbReady(namespace string) error {
@@ -772,7 +765,7 @@ func (j *ServiceTestJig) waitForPdbReady(namespace string) error {
772765
}
773766
}
774767

775-
return fmt.Errorf("Timeout waiting for PDB %q to be ready", j.Name)
768+
return fmt.Errorf("timeout waiting for PDB %q to be ready", j.Name)
776769
}
777770

778771
func (j *ServiceTestJig) waitForPodsCreated(namespace string, replicas int) ([]string, error) {
@@ -800,13 +793,13 @@ func (j *ServiceTestJig) waitForPodsCreated(namespace string, replicas int) ([]s
800793
}
801794
Logf("Found %d/%d pods - will retry", len(found), replicas)
802795
}
803-
return nil, fmt.Errorf("Timeout waiting for %d pods to be created", replicas)
796+
return nil, fmt.Errorf("timeout waiting for %d pods to be created", replicas)
804797
}
805798

806799
func (j *ServiceTestJig) waitForPodsReady(namespace string, pods []string) error {
807800
timeout := 2 * time.Minute
808801
if !CheckPodsRunningReady(j.Client, namespace, pods, timeout) {
809-
return fmt.Errorf("Timeout waiting for %d pods to be ready", len(pods))
802+
return fmt.Errorf("timeout waiting for %d pods to be ready", len(pods))
810803
}
811804
return nil
812805
}
@@ -1010,7 +1003,7 @@ func testHTTPHealthCheckNodePort(ip string, port int, request string) (bool, err
10101003
url := fmt.Sprintf("http://%s%s", ipPort, request)
10111004
if ip == "" || port == 0 {
10121005
Failf("Got empty IP for reachability check (%s)", url)
1013-
return false, fmt.Errorf("Invalid input ip or port")
1006+
return false, fmt.Errorf("invalid input ip or port")
10141007
}
10151008
Logf("Testing HTTP health check on %v", url)
10161009
resp, err := httpGetNoConnectionPoolTimeout(url, 5*time.Second)
@@ -1031,7 +1024,7 @@ func testHTTPHealthCheckNodePort(ip string, port int, request string) (bool, err
10311024
if resp.StatusCode == 200 {
10321025
return true, nil
10331026
}
1034-
return false, fmt.Errorf("Unexpected HTTP response code %s from health check responder at %s", resp.Status, url)
1027+
return false, fmt.Errorf("unexpected HTTP response code %s from health check responder at %s", resp.Status, url)
10351028
}
10361029

10371030
func (j *ServiceTestJig) TestHTTPHealthCheckNodePort(host string, port int, request string, timeout time.Duration, expectSucceed bool, threshold int) error {
@@ -1106,20 +1099,6 @@ func (t *ServiceTestFixture) BuildServiceSpec() *v1.Service {
11061099
return service
11071100
}
11081101

1109-
// CreateWebserverRC creates rc-backed pods with the well-known webserver
1110-
// configuration and records it for cleanup.
1111-
func (t *ServiceTestFixture) CreateWebserverRC(replicas int32) *v1.ReplicationController {
1112-
rcSpec := RcByNamePort(t.Name, replicas, t.Image, 80, v1.ProtocolTCP, t.Labels, nil)
1113-
rcAct, err := t.CreateRC(rcSpec)
1114-
if err != nil {
1115-
Failf("Failed to create rc %s: %v", rcSpec.Name, err)
1116-
}
1117-
if err := VerifyPods(t.Client, t.Namespace, t.Name, false, replicas); err != nil {
1118-
Failf("Failed to create %d pods with name %s: %v", replicas, t.Name, err)
1119-
}
1120-
return rcAct
1121-
}
1122-
11231102
// CreateRC creates a replication controller and records it for cleanup.
11241103
func (t *ServiceTestFixture) CreateRC(rc *v1.ReplicationController) (*v1.ReplicationController, error) {
11251104
rc, err := t.Client.CoreV1().ReplicationControllers(t.Namespace).Create(rc)
@@ -1349,7 +1328,7 @@ func StartServeHostnameService(c clientset.Interface, svc *v1.Service, ns string
13491328
}
13501329

13511330
if len(createdPods) != replicas {
1352-
return podNames, "", fmt.Errorf("Incorrect number of running pods: %v", len(createdPods))
1331+
return podNames, "", fmt.Errorf("incorrect number of running pods: %v", len(createdPods))
13531332
}
13541333

13551334
for i := range createdPods {
@@ -1362,7 +1341,7 @@ func StartServeHostnameService(c clientset.Interface, svc *v1.Service, ns string
13621341
return podNames, "", err
13631342
}
13641343
if service.Spec.ClusterIP == "" {
1365-
return podNames, "", fmt.Errorf("Service IP is blank for %v", name)
1344+
return podNames, "", fmt.Errorf("service IP is blank for %v", name)
13661345
}
13671346
serviceIP := service.Spec.ClusterIP
13681347
return podNames, serviceIP, nil
@@ -1481,6 +1460,7 @@ func VerifyServeHostnameServiceDown(c clientset.Interface, host string, serviceI
14811460
return fmt.Errorf("waiting for service to be down timed out")
14821461
}
14831462

1463+
// CleanupServiceResources cleans up service Type=LoadBalancer resources.
14841464
func CleanupServiceResources(c clientset.Interface, loadBalancerName, region, zone string) {
14851465
TestContext.CloudConfig.Provider.CleanupServiceResources(c, loadBalancerName, region, zone)
14861466
}

0 commit comments

Comments
 (0)