From 9f2fa7d2691b1cd7c69fbd6b7e28a83320a57be4 Mon Sep 17 00:00:00 2001 From: Jiatong Wang Date: Wed, 17 Apr 2019 23:30:39 -0700 Subject: [PATCH] Remove unused function and clean up redundant code --- test/e2e/framework/service_util.go | 46 +++++++++--------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/test/e2e/framework/service_util.go b/test/e2e/framework/service_util.go index 60a10853ef3..5570243a73e 100644 --- a/test/e2e/framework/service_util.go +++ b/test/e2e/framework/service_util.go @@ -507,7 +507,7 @@ func (j *ServiceTestJig) UpdateService(namespace, name string, update func(*v1.S for i := 0; i < 3; i++ { service, err := j.Client.CoreV1().Services(namespace).Get(name, metav1.GetOptions{}) if err != nil { - return nil, fmt.Errorf("Failed to get Service %q: %v", name, err) + return nil, fmt.Errorf("failed to get Service %q: %v", name, err) } update(service) service, err = j.Client.CoreV1().Services(namespace).Update(service) @@ -515,10 +515,10 @@ func (j *ServiceTestJig) UpdateService(namespace, name string, update func(*v1.S return service, nil } if !errors.IsConflict(err) && !errors.IsServerTimeout(err) { - return nil, fmt.Errorf("Failed to update Service %q: %v", name, err) + return nil, fmt.Errorf("failed to update Service %q: %v", name, err) } } - return nil, fmt.Errorf("Too many retries updating Service %q", name) + return nil, fmt.Errorf("too many retries updating Service %q", name) } // UpdateServiceOrFail fetches a service, calls the update function on it, and @@ -573,10 +573,7 @@ func (j *ServiceTestJig) ChangeServiceNodePortOrFail(namespace, name string, ini func (j *ServiceTestJig) WaitForLoadBalancerOrFail(namespace, name string, timeout time.Duration) *v1.Service { Logf("Waiting up to %v for service %q to have a LoadBalancer", timeout, name) service := j.waitForConditionOrFail(namespace, name, timeout, "have a load balancer", func(svc *v1.Service) bool { - if len(svc.Status.LoadBalancer.Ingress) > 0 { - return true - } - return false + return len(svc.Status.LoadBalancer.Ingress) > 0 }) return service } @@ -591,10 +588,7 @@ func (j *ServiceTestJig) WaitForLoadBalancerDestroyOrFail(namespace, name string Logf("Waiting up to %v for service %q to have no LoadBalancer", timeout, name) service := j.waitForConditionOrFail(namespace, name, timeout, "have no load balancer", func(svc *v1.Service) bool { - if len(svc.Status.LoadBalancer.Ingress) == 0 { - return true - } - return false + return len(svc.Status.LoadBalancer.Ingress) == 0 }) return service } @@ -757,7 +751,6 @@ func (j *ServiceTestJig) Scale(namespace string, replicas int) { if err := j.waitForPodsReady(namespace, pods); err != nil { Failf("Failed waiting for pods to be running: %v", err) } - return } func (j *ServiceTestJig) waitForPdbReady(namespace string) error { @@ -772,7 +765,7 @@ func (j *ServiceTestJig) waitForPdbReady(namespace string) error { } } - return fmt.Errorf("Timeout waiting for PDB %q to be ready", j.Name) + return fmt.Errorf("timeout waiting for PDB %q to be ready", j.Name) } func (j *ServiceTestJig) waitForPodsCreated(namespace string, replicas int) ([]string, error) { @@ -800,13 +793,13 @@ func (j *ServiceTestJig) waitForPodsCreated(namespace string, replicas int) ([]s } Logf("Found %d/%d pods - will retry", len(found), replicas) } - return nil, fmt.Errorf("Timeout waiting for %d pods to be created", replicas) + return nil, fmt.Errorf("timeout waiting for %d pods to be created", replicas) } func (j *ServiceTestJig) waitForPodsReady(namespace string, pods []string) error { timeout := 2 * time.Minute if !CheckPodsRunningReady(j.Client, namespace, pods, timeout) { - return fmt.Errorf("Timeout waiting for %d pods to be ready", len(pods)) + return fmt.Errorf("timeout waiting for %d pods to be ready", len(pods)) } return nil } @@ -1010,7 +1003,7 @@ func testHTTPHealthCheckNodePort(ip string, port int, request string) (bool, err url := fmt.Sprintf("http://%s%s", ipPort, request) if ip == "" || port == 0 { Failf("Got empty IP for reachability check (%s)", url) - return false, fmt.Errorf("Invalid input ip or port") + return false, fmt.Errorf("invalid input ip or port") } Logf("Testing HTTP health check on %v", url) resp, err := httpGetNoConnectionPoolTimeout(url, 5*time.Second) @@ -1031,7 +1024,7 @@ func testHTTPHealthCheckNodePort(ip string, port int, request string) (bool, err if resp.StatusCode == 200 { return true, nil } - return false, fmt.Errorf("Unexpected HTTP response code %s from health check responder at %s", resp.Status, url) + return false, fmt.Errorf("unexpected HTTP response code %s from health check responder at %s", resp.Status, url) } 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 { return service } -// CreateWebserverRC creates rc-backed pods with the well-known webserver -// configuration and records it for cleanup. -func (t *ServiceTestFixture) CreateWebserverRC(replicas int32) *v1.ReplicationController { - rcSpec := RcByNamePort(t.Name, replicas, t.Image, 80, v1.ProtocolTCP, t.Labels, nil) - rcAct, err := t.CreateRC(rcSpec) - if err != nil { - Failf("Failed to create rc %s: %v", rcSpec.Name, err) - } - if err := VerifyPods(t.Client, t.Namespace, t.Name, false, replicas); err != nil { - Failf("Failed to create %d pods with name %s: %v", replicas, t.Name, err) - } - return rcAct -} - // CreateRC creates a replication controller and records it for cleanup. func (t *ServiceTestFixture) CreateRC(rc *v1.ReplicationController) (*v1.ReplicationController, error) { rc, err := t.Client.CoreV1().ReplicationControllers(t.Namespace).Create(rc) @@ -1349,7 +1328,7 @@ func StartServeHostnameService(c clientset.Interface, svc *v1.Service, ns string } if len(createdPods) != replicas { - return podNames, "", fmt.Errorf("Incorrect number of running pods: %v", len(createdPods)) + return podNames, "", fmt.Errorf("incorrect number of running pods: %v", len(createdPods)) } for i := range createdPods { @@ -1362,7 +1341,7 @@ func StartServeHostnameService(c clientset.Interface, svc *v1.Service, ns string return podNames, "", err } if service.Spec.ClusterIP == "" { - return podNames, "", fmt.Errorf("Service IP is blank for %v", name) + return podNames, "", fmt.Errorf("service IP is blank for %v", name) } serviceIP := service.Spec.ClusterIP return podNames, serviceIP, nil @@ -1481,6 +1460,7 @@ func VerifyServeHostnameServiceDown(c clientset.Interface, host string, serviceI return fmt.Errorf("waiting for service to be down timed out") } +// CleanupServiceResources cleans up service Type=LoadBalancer resources. func CleanupServiceResources(c clientset.Interface, loadBalancerName, region, zone string) { TestContext.CloudConfig.Provider.CleanupServiceResources(c, loadBalancerName, region, zone) }