Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup e2e tests to use whitebox testing #901

Merged
merged 1 commit into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 6 additions & 29 deletions cmd/e2e-test/basic_https_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/ingress-gce/pkg/e2e"
"k8s.io/ingress-gce/pkg/fuzz"
"k8s.io/ingress-gce/pkg/fuzz/features"
)

func TestBasicHTTPS(t *testing.T) {
Expand All @@ -37,19 +36,14 @@ func TestBasicHTTPS(t *testing.T) {
ingBuilder *fuzz.IngressBuilder
hosts []string
certType e2e.CertType

numForwardingRules int
numBackendServices int
}{
{
desc: "http(s) one path via pre-shared cert",
ingBuilder: fuzz.NewIngressBuilder("", "ingress-1", "").
DefaultBackend("service-1", port80).
AddPath("test.com", "/", "service-1", port80),
hosts: []string{"test.com"},
certType: e2e.GCPCert,
numForwardingRules: 2,
numBackendServices: 1,
hosts: []string{"test.com"},
certType: e2e.GCPCert,
},
{
desc: "http(s) multi-path multi-TLS",
Expand All @@ -58,10 +52,8 @@ func TestBasicHTTPS(t *testing.T) {
AddPath("foo.com", "/", "service-1", port80).
AddPath("bar.com", "/", "service-1", port80).
AddPath("baz.com", "/", "service-1", port80),
hosts: []string{"foo.com", "bar.com", "baz.com"},
certType: e2e.K8sCert,
numForwardingRules: 2,
numBackendServices: 1,
hosts: []string{"foo.com", "bar.com", "baz.com"},
certType: e2e.K8sCert,
},
{
desc: "http(s) multi-path multi-pre-shared cert",
Expand All @@ -71,9 +63,7 @@ func TestBasicHTTPS(t *testing.T) {
AddPath("foo.com", "/", "service-1", port80).
AddPath("bar.com", "/", "service-1", port80).
AddPath("baz.com", "/", "service-1", port80),
certType: e2e.GCPCert,
numForwardingRules: 2,
numBackendServices: 1,
certType: e2e.GCPCert,
},
} {
tc := tc // Capture tc as we are running this in parallel.
Expand Down Expand Up @@ -121,20 +111,7 @@ func TestBasicHTTPS(t *testing.T) {
t.Logf("GCLB resources created (%s/%s)", s.Namespace, ing.Name)

// Perform whitebox testing.
if len(ing.Status.LoadBalancer.Ingress) < 1 {
t.Fatalf("Ingress does not have an IP: %+v", ing.Status)
}

vip := ing.Status.LoadBalancer.Ingress[0].IP
t.Logf("Ingress %s/%s VIP = %s", s.Namespace, ing.Name, vip)
gclb, err := fuzz.GCLBForVIP(context.Background(), Framework.Cloud, vip, fuzz.FeatureValidators(features.All))
if err != nil {
t.Fatalf("Error getting GCP resources for LB with IP = %q: %v", vip, err)
}

if err := e2e.PerformWhiteboxTests(s, ing, gclb); err != nil {
t.Fatalf("Error performing whitebox tests: %v", err)
}
gclb := whiteboxTest(ing, s, t)

deleteOptions := &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
Expand Down
63 changes: 35 additions & 28 deletions cmd/e2e-test/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,8 @@ func TestBasic(t *testing.T) {
}
t.Logf("GCLB resources createdd (%s/%s)", s.Namespace, tc.ing.Name)

if len(ing.Status.LoadBalancer.Ingress) < 1 {
t.Fatalf("Ingress does not have an IP: %+v", ing.Status)
}

vip := ing.Status.LoadBalancer.Ingress[0].IP
t.Logf("Ingress %s/%s VIP = %s", s.Namespace, tc.ing.Name, vip)
gclb, err := fuzz.GCLBForVIP(context.Background(), Framework.Cloud, vip, fuzz.FeatureValidators(features.All))
if err != nil {
t.Fatalf("Error getting GCP resources for LB with IP = %q: %v", vip, err)
}

if err := e2e.PerformWhiteboxTests(s, tc.ing, gclb); err != nil {
t.Fatalf("Error performing whitebox tests: %v", err)
}
// Perform whitebox testing.
gclb := whiteboxTest(ing, s, t)

deleteOptions := &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
Expand Down Expand Up @@ -199,20 +187,7 @@ func TestEdge(t *testing.T) {
t.Logf("GCLB resources createdd (%s/%s)", s.Namespace, tc.ing.Name)

// Perform whitebox testing.
if len(ing.Status.LoadBalancer.Ingress) < 1 {
t.Fatalf("Ingress does not have an IP: %+v", ing.Status)
}

vip := ing.Status.LoadBalancer.Ingress[0].IP
t.Logf("Ingress %s/%s VIP = %s", s.Namespace, tc.ing.Name, vip)
gclb, err := fuzz.GCLBForVIP(context.Background(), Framework.Cloud, vip, fuzz.FeatureValidators(features.All))
if err != nil {
t.Fatalf("Error getting GCP resources for LB with IP = %q: %v", vip, err)
}

if err := e2e.PerformWhiteboxTests(s, tc.ing, gclb); err != nil {
t.Fatalf("Error performing whitebox tests: %v", err)
}
gclb := whiteboxTest(ing, s, t)

deleteOptions := &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
Expand All @@ -223,3 +198,35 @@ func TestEdge(t *testing.T) {
})
}
}

func waitForStableIngress(expectUnreachable bool, ing *v1beta1.Ingress, s *e2e.Sandbox, t *testing.T) *v1beta1.Ingress {
options := &e2e.WaitForIngressOptions{
ExpectUnreachable: expectUnreachable,
}

ing, err := e2e.WaitForIngress(s, ing, options)
if err != nil {
t.Fatalf("error waiting for Ingress to stabilize: %v", err)
}

s.PutStatus(e2e.Stable)
return ing
}

func whiteboxTest(ing *v1beta1.Ingress, s *e2e.Sandbox, t *testing.T) *fuzz.GCLB {
if len(ing.Status.LoadBalancer.Ingress) < 1 {
t.Fatalf("Ingress does not have an IP: %+v", ing.Status)
}

vip := ing.Status.LoadBalancer.Ingress[0].IP
t.Logf("Ingress %s/%s VIP = %s", s.Namespace, ing.Name, vip)
gclb, err := fuzz.GCLBForVIP(context.Background(), Framework.Cloud, vip, fuzz.FeatureValidators(features.All))
if err != nil {
t.Fatalf("Error getting GCP resources for LB with IP = %q: %v", vip, err)
}

if err := e2e.PerformWhiteboxTests(s, ing, gclb); err != nil {
t.Fatalf("Error performing whitebox tests: %v", err)
}
return gclb
}
46 changes: 11 additions & 35 deletions cmd/e2e-test/finalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ import (
"context"
"testing"

"k8s.io/api/networking/v1beta1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/ingress-gce/pkg/e2e"
"k8s.io/ingress-gce/pkg/fuzz"
"k8s.io/ingress-gce/pkg/fuzz/features"
"k8s.io/ingress-gce/pkg/utils/common"
)

Expand All @@ -34,8 +32,6 @@ func TestFinalizer(t *testing.T) {
t.Parallel()
ctx := context.Background()
port80 := intstr.FromInt(80)
numForwardingRules := 1
numBackendServices := 2
svcName := "service-1"
ing := fuzz.NewIngressBuilder("", "ingress-1", "").
AddPath("foo.com", "/", svcName, port80).
Expand All @@ -62,7 +58,8 @@ func TestFinalizer(t *testing.T) {
t.Fatalf("GetFinalizers() = %+v, want [%q]", ingFinalizers, common.FinalizerKey)
}

gclb := checkGCLB(t, s, ing, numForwardingRules, numBackendServices)
// Perform whitebox testing.
gclb := whiteboxTest(ing, s, t)

deleteOptions := &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
Expand All @@ -79,8 +76,6 @@ func TestFinalizerIngressClassChange(t *testing.T) {
t.Parallel()
ctx := context.Background()
port80 := intstr.FromInt(80)
numForwardingRules := 1
numBackendServices := 2
svcName := "service-1"
ing := fuzz.NewIngressBuilder("", "ingress-1", "").
AddPath("foo.com", "/", svcName, port80).
Expand All @@ -107,7 +102,8 @@ func TestFinalizerIngressClassChange(t *testing.T) {
t.Fatalf("GetFinalizers() = %+v, want [%q]", ingFinalizers, common.FinalizerKey)
}

gclb := checkGCLB(t, s, ing, numForwardingRules, numBackendServices)
// Perform whitebox testing.
gclb := whiteboxTest(ing, s, t)

// Change Ingress class
newIngClass := "nginx"
Expand All @@ -134,8 +130,6 @@ func TestFinalizerIngressesWithSharedResources(t *testing.T) {
t.Parallel()
ctx := context.Background()
port80 := intstr.FromInt(80)
numForwardingRules := 1
numBackendServices := 2
svcName := "service-1"
ing := fuzz.NewIngressBuilder("", "ingress-1", "").
AddPath("foo.com", "/", svcName, port80).
Expand Down Expand Up @@ -178,8 +172,9 @@ func TestFinalizerIngressesWithSharedResources(t *testing.T) {
t.Fatalf("GetFinalizers() = %+v, want [%q]", otherIngFinalizers, common.FinalizerKey)
}

gclb := checkGCLB(t, s, ing, numForwardingRules, numBackendServices)
otherGclb := checkGCLB(t, s, otherIng, numForwardingRules, numBackendServices)
// Perform whitebox testing.
gclb := whiteboxTest(ing, s, t)
otherGclb := whiteboxTest(otherIng, s, t)

// SkipBackends ensure that we dont wait on deletion of shared backends.
deleteOptions := &fuzz.GCLBDeleteOptions{
Expand All @@ -204,8 +199,6 @@ func TestFinalizerIngressesWithSharedResources(t *testing.T) {
// other versions.
func TestUpdateTo1dot7(t *testing.T) {
port80 := intstr.FromInt(80)
numForwardingRules := 1
numBackendServices := 2
svcName := "service-1"
ing := fuzz.NewIngressBuilder("", "ingress-1", "").
AddPath("foo.com", "/", svcName, port80).
Expand Down Expand Up @@ -233,8 +226,8 @@ func TestUpdateTo1dot7(t *testing.T) {
if l := len(ingFinalizers); l != 0 {
t.Fatalf("GetFinalizers() = %d, want 0", l)
}

checkGCLB(t, s, ing, numForwardingRules, numBackendServices)
// Perform whitebox testing.
whiteboxTest(ing, s, t)

for {
// While k8s master is upgrading, it will return a connection refused
Expand All @@ -255,7 +248,8 @@ func TestUpdateTo1dot7(t *testing.T) {
t.Errorf("e2e.WaitForFinalizer(_, %q) = %v, want nil", ing.Name, err)
}

gclb := checkGCLB(t, s, ing, numForwardingRules, numBackendServices)
// Perform whitebox testing.
gclb := whiteboxTest(ing, s, t)

// If the Master has upgraded and the Ingress is stable,
// we delete the Ingress and exit out of the loop to indicate that
Expand All @@ -268,21 +262,3 @@ func TestUpdateTo1dot7(t *testing.T) {
}
})
}

func checkGCLB(t *testing.T, s *e2e.Sandbox, ing *v1beta1.Ingress, numForwardingRules, numBackendServices int) *fuzz.GCLB {
// Perform whitebox testing.
if len(ing.Status.LoadBalancer.Ingress) < 1 {
t.Fatalf("Ingress does not have an IP: %+v", ing.Status)
}
vip := ing.Status.LoadBalancer.Ingress[0].IP
t.Logf("Ingress %s/%s VIP = %s", s.Namespace, ing.Name, vip)
gclb, err := fuzz.GCLBForVIP(context.Background(), Framework.Cloud, vip, fuzz.FeatureValidators(features.All))
if err != nil {
t.Fatalf("GCLBForVIP(..., %q, _) = %v, want nil; error getting GCP resources for LB with IP", vip, err)
}

if err = e2e.CheckGCLB(gclb, numForwardingRules, numBackendServices); err != nil {
t.Error(err)
}
return gclb
}
37 changes: 10 additions & 27 deletions cmd/e2e-test/neg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ func TestNEG(t *testing.T) {
}

for _, tc := range []struct {
desc string
ingress *v1beta1.Ingress
services map[string]serviceAttr
expectNegBackend bool
expectIgBackend bool
numBackendServices int
desc string
ingress *v1beta1.Ingress
services map[string]serviceAttr
expectNegBackend bool
expectIgBackend bool
}{
{
desc: "Create a ingress with 2 NEG services of different types",
Expand All @@ -69,9 +68,8 @@ func TestNEG(t *testing.T) {
svcType: v1.ServiceTypeNodePort,
},
},
expectNegBackend: true,
expectIgBackend: false,
numBackendServices: 2,
expectNegBackend: true,
expectIgBackend: false,
},
{
desc: "Create a ingress with 1 NEG service and 1 non-NEG service with default backend",
Expand All @@ -86,9 +84,8 @@ func TestNEG(t *testing.T) {
svcType: v1.ServiceTypeClusterIP,
},
},
expectNegBackend: true,
expectIgBackend: true,
numBackendServices: 3,
expectNegBackend: true,
expectIgBackend: true,
},
} {
tc := tc // Capture tc as we are running this in parallel.
Expand Down Expand Up @@ -119,21 +116,7 @@ func TestNEG(t *testing.T) {
t.Logf("GCLB resources created (%s/%s)", s.Namespace, ing.Name)

// Perform whitebox testing.
if len(ing.Status.LoadBalancer.Ingress) < 1 {
t.Fatalf("Ingress does not have an IP: %+v", ing.Status)
}

vip := ing.Status.LoadBalancer.Ingress[0].IP
t.Logf("Ingress %s/%s VIP = %s", s.Namespace, ing.Name, vip)
gclb, err := fuzz.GCLBForVIP(context.Background(), Framework.Cloud, vip,
fuzz.FeatureValidators(features.All))
if err != nil {
t.Fatalf("Error getting GCP resources for LB with IP = %q: %v", vip, err)
}

if err := e2e.PerformWhiteboxTests(s, ing, gclb); err != nil {
t.Fatalf("Error performing whitebox tests: %v", err)
}
gclb := whiteboxTest(ing, s, t)

// TODO(mixia): The below checks should be merged into PerformWhiteboxTests().
if (len(gclb.NetworkEndpointGroup) > 0) != tc.expectNegBackend {
Expand Down
Loading