Skip to content

Commit

Permalink
Update e2e tests for custom health check firewall port fix
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerhance committed Aug 18, 2020
1 parent 806b7ef commit 54885c3
Showing 1 changed file with 39 additions and 14 deletions.
53 changes: 39 additions & 14 deletions cmd/e2e-test/healthcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"context"
"fmt"
"testing"

"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud"
Expand Down Expand Up @@ -51,6 +52,14 @@ func TestHealthCheck(t *testing.T) {
RequestPath: pstring("/my-path"),
},
},
{
desc: "override healthcheck and port with NEG",
beConfig: fuzz.NewBackendConfigBuilder("", "backendconfig-1").Build(),
want: &backendconfig.HealthCheckConfig{
RequestPath: pstring("/my-path"),
Port: pint64(9000), // Purposely does not match deployment, we verify it separately
},
},
} {
tc := tc // Capture tc as we are running this in parallel.
Framework.RunWithSandbox(tc.desc, t, func(t *testing.T, s *e2e.Sandbox) {
Expand All @@ -68,12 +77,20 @@ func TestHealthCheck(t *testing.T) {
}
t.Logf("BackendConfig created (%s/%s) ", s.Namespace, tc.beConfig.Name)

_, err := e2e.CreateEchoService(s, "service-1", backendConfigAnnotation)
svc, err := e2e.CreateEchoService(s, "service-1", backendConfigAnnotation)
if err != nil {
t.Fatalf("error creating echo service: %v", err)
}
t.Logf("Echo service created (%s/%s)", s.Namespace, "service-1")

// Update service for NEG
if tc.want.Port != nil {
svc.Annotations[annotations.NEGAnnotationKey] = `{"ingress":true}`
if _, err := Framework.Clientset.CoreV1().Services(s.Namespace).Update(svc); err != nil {
t.Fatalf("error updating port on svc: %v", err)
}
}

ing := fuzz.NewIngressBuilder(s.Namespace, "ingress-1", "").
DefaultBackend("service-1", intstr.FromInt(80)).
Build()
Expand All @@ -83,9 +100,15 @@ func TestHealthCheck(t *testing.T) {
}
t.Logf("Ingress created (%s/%s)", s.Namespace, ing.Name)

ing, err = e2e.WaitForIngress(s, ing, nil)
if err != nil {
t.Fatalf("error waiting for Ingress to stabilize: %v", err)
// If health check port does not match deployment, then the deployment will be unreachable
if tc.want.Port != nil {
options := &e2e.WaitForIngressOptions{ExpectUnreachable: true}
ing, _ = e2e.WaitForIngress(s, ing, options)
} else {
ing, err = e2e.WaitForIngress(s, ing, nil)
if err != nil {
t.Fatalf("error waiting for Ingress to stabilize: %v", err)
}
}
t.Logf("GCLB resources created (%s/%s)", s.Namespace, ing.Name)

Expand All @@ -96,8 +119,9 @@ func TestHealthCheck(t *testing.T) {
if err != nil {
t.Fatalf("Error getting GCP resources for LB with IP = %q: %v", vip, err)
}

verifyHealthCheck(t, gclb, tc.want)
if err := verifyHealthCheck(t, gclb, tc.want); err != nil {
t.Fatal(err)
}

// Wait for GCLB resources to be deleted.
if err := crud.Delete(s.Namespace, ing.Name); err != nil {
Expand All @@ -116,7 +140,7 @@ func TestHealthCheck(t *testing.T) {
}
}

func verifyHealthCheck(t *testing.T, gclb *fuzz.GCLB, want *backendconfig.HealthCheckConfig) {
func verifyHealthCheck(t *testing.T, gclb *fuzz.GCLB, want *backendconfig.HealthCheckConfig) error {
// We assume there is a single service for now. The logic will have to be
// changed if there is more than one backend service.
for _, bs := range gclb.BackendService {
Expand Down Expand Up @@ -149,26 +173,27 @@ func verifyHealthCheck(t *testing.T, gclb *fuzz.GCLB, want *backendconfig.Health
}

if want.CheckIntervalSec != nil && hc.GA.CheckIntervalSec != *want.CheckIntervalSec {
t.Errorf("HealthCheck %v checkIntervalSec = %d, want %d", rID.Key, hc.GA.CheckIntervalSec, *want.CheckIntervalSec)
return fmt.Errorf("HealthCheck %v checkIntervalSec = %d, want %d", rID.Key, hc.GA.CheckIntervalSec, *want.CheckIntervalSec)
}
if want.TimeoutSec != nil && hc.GA.TimeoutSec != *want.TimeoutSec {
t.Errorf("HealthCheck %v timeoutSec = %d, want %d", rID.Key, hc.GA.TimeoutSec, *want.TimeoutSec)
return fmt.Errorf("HealthCheck %v timeoutSec = %d, want %d", rID.Key, hc.GA.TimeoutSec, *want.TimeoutSec)
}
if want.HealthyThreshold != nil && hc.GA.HealthyThreshold != *want.HealthyThreshold {
t.Errorf("HealthCheck %v healthyThreshold = %d, want %d", rID.Key, hc.GA.HealthyThreshold, *want.HealthyThreshold)
return fmt.Errorf("HealthCheck %v healthyThreshold = %d, want %d", rID.Key, hc.GA.HealthyThreshold, *want.HealthyThreshold)
}
if want.UnhealthyThreshold != nil && hc.GA.UnhealthyThreshold != *want.UnhealthyThreshold {
t.Errorf("HealthCheck %v unhealthThreshold = %d, want %d", rID.Key, hc.GA.UnhealthyThreshold, *want.UnhealthyThreshold)
return fmt.Errorf("HealthCheck %v unhealthThreshold = %d, want %d", rID.Key, hc.GA.UnhealthyThreshold, *want.UnhealthyThreshold)
}
if want.Type != nil {
t.Errorf("HealthCheck %v type = %s, want %s", rID.Key, hc.GA.Type, *want.Type)
return fmt.Errorf("HealthCheck %v type = %s, want %s", rID.Key, hc.GA.Type, *want.Type)
}
if want.Port != nil && common.port != *want.Port {
t.Errorf("HealthCheck %v port = %d, want %d", rID.Key, common.port, *want.Port)
return fmt.Errorf("HealthCheck %v port = %d, want %d", rID.Key, common.port, *want.Port)
}
if want.RequestPath != nil && common.requestPath != *want.RequestPath {
t.Errorf("HealthCheck %v requestPath = %q, want %q", rID.Key, common.requestPath, *want.RequestPath)
return fmt.Errorf("HealthCheck %v requestPath = %q, want %q", rID.Key, common.requestPath, *want.RequestPath)
}
}
}
return nil
}

0 comments on commit 54885c3

Please sign in to comment.