Skip to content

Commit

Permalink
Remove unused function and clean up redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiatong Wang committed Apr 19, 2019
1 parent 10fc2a1 commit 9f2fa7d
Showing 1 changed file with 13 additions and 33 deletions.
46 changes: 13 additions & 33 deletions test/e2e/framework/service_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,18 +507,18 @@ 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)
if err == nil {
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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 9f2fa7d

Please sign in to comment.