Skip to content

Commit

Permalink
Migrate upgrade tests to use the upgrade framework
Browse files Browse the repository at this point in the history
  • Loading branch information
skmatti committed Nov 21, 2019
1 parent 55f5179 commit 3ef83d5
Show file tree
Hide file tree
Showing 9 changed files with 264 additions and 189 deletions.
5 changes: 4 additions & 1 deletion cmd/e2e-test/basic_https_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ func TestBasicHTTPS(t *testing.T) {
t.Logf("GCLB resources created (%s/%s)", s.Namespace, ing.Name)

// Perform whitebox testing.
gclb := whiteboxTest(ing, s, t, "")
gclb, err := e2e.WhiteboxTest(ing, s, Framework.Cloud, "")
if err != nil {
t.Fatalf("e2e.WhiteboxTest(%s/%s, ...)", ing.Namespace, ing.Name)
}

deleteOptions := &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
Expand Down
66 changes: 22 additions & 44 deletions cmd/e2e-test/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ func TestBasic(t *testing.T) {
t.Logf("GCLB resources createdd (%s/%s)", s.Namespace, tc.ing.Name)

// Perform whitebox testing.
gclb := whiteboxTest(ing, s, t, "")
gclb, err := e2e.WhiteboxTest(ing, s, Framework.Cloud, "")
if err != nil {
t.Fatalf("e2e.WhiteboxTest(%s/%s, ...)", ing.Namespace, ing.Name)
}

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

// Perform whitebox testing.
gclb := whiteboxTest(ing, s, t, "")
gclb, err := e2e.WhiteboxTest(ing, s, Framework.Cloud, "")
if err != nil {
t.Fatalf("e2e.WhiteboxTest(%s/%s, ...)", ing.Namespace, ing.Name)
}

deleteOptions := &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
Expand All @@ -203,43 +209,6 @@ 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, region string) *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)
params := &fuzz.GCLBForVIPParams{
VIP: vip,
Region: region,
Validators: fuzz.FeatureValidators(features.All),
}
gclb, err := fuzz.GCLBForVIP(context.Background(), Framework.Cloud, params)
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
}

// TestFrontendResourceDeletion asserts that unused GCP frontend resources are
// deleted. This also tests that necessary GCP frontend resources exist.
func TestFrontendResourceDeletion(t *testing.T) {
Expand Down Expand Up @@ -290,8 +259,13 @@ func TestFrontendResourceDeletion(t *testing.T) {
t.Fatalf("crud.Create(%s/%s) = %v, want nil; Ingress: %v", ing.Namespace, ing.Name, err, ing)
}
t.Logf("Ingress created (%s/%s)", s.Namespace, ing.Name)
ing = waitForStableIngress(true, ing, s, t)
gclb := whiteboxTest(ing, s, t, "")
if ing, err = e2e.WaitForIngress(s, ing, &e2e.WaitForIngressOptions{ExpectUnreachable: true}); err != nil {
t.Fatalf("Error waiting for Ingress to stabilize: %v", err)
}
gclb, err := e2e.WhiteboxTest(ing, s, Framework.Cloud, "")
if err != nil {
t.Fatalf("e2e.WhiteboxTest(%s/%s, ...)", ing.Namespace, ing.Name)
}

// Update ingress with desired frontend resource configuration.
ingBuilder := fuzz.NewIngressBuilderFromExisting(ing)
Expand All @@ -304,10 +278,12 @@ func TestFrontendResourceDeletion(t *testing.T) {
ing = ingBuilder.Build()

if _, err := crud.Update(ing); err != nil {
t.Fatalf("update(%s/%s) = %v, want nil; ingress: %v", ing.Namespace, ing.Name, err, ing)
t.Fatalf("Update(%s/%s) = %v, want nil; ingress: %v", ing.Namespace, ing.Name, err, ing)
}
t.Logf("Ingress updated (%s/%s)", ing.Namespace, ing.Name)
ing = waitForStableIngress(true, ing, s, t)
if ing, err = e2e.WaitForIngress(s, ing, &e2e.WaitForIngressOptions{ExpectUnreachable: true}); err != nil {
t.Fatalf("Error waiting for Ingress to stabilize: %v", err)
}

deleteOptions := &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
Expand All @@ -318,7 +294,9 @@ func TestFrontendResourceDeletion(t *testing.T) {
if err := e2e.WaitForFrontendResourceDeletion(ctx, Framework.Cloud, gclb, deleteOptions); err != nil {
t.Errorf("e2e.WaitForIngressDeletion(..., %q, _) = %v, want nil", ing.Name, err)
}
whiteboxTest(ing, s, t, "")
if gclb, err = e2e.WhiteboxTest(ing, s, Framework.Cloud, ""); err != nil {
t.Fatalf("e2e.WhiteboxTest(%s/%s, ...)", ing.Namespace, ing.Name)
}
deleteOptions = &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
}
Expand Down
60 changes: 47 additions & 13 deletions cmd/e2e-test/finalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ package main

import (
"context"
"k8s.io/api/networking/v1beta1"
"k8s.io/ingress-gce/pkg/fuzz/features"
"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 Down Expand Up @@ -53,15 +53,22 @@ func TestFinalizer(t *testing.T) {
t.Fatalf("create(%s/%s) = %v, want nil; Ingress: %v", ing.Namespace, ing.Name, err, ing)
}
t.Logf("Ingress created (%s/%s)", s.Namespace, ing.Name)
ing = waitForStableIngress(true, ing, s, t)

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

ingFinalizers := ing.GetFinalizers()
if len(ingFinalizers) != 1 || ingFinalizers[0] != common.FinalizerKey {
t.Fatalf("GetFinalizers() = %+v, want [%q]", ingFinalizers, common.FinalizerKey)
}

// Perform whitebox testing.
gclb := whiteboxTest(ing, s, t, "")
gclb, err := e2e.WhiteboxTest(ing, s, Framework.Cloud, "")
if err != nil {
t.Fatalf("e2e.WhiteboxTest(%s/%s, ...)", ing.Namespace, ing.Name)
}

deleteOptions := &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
Expand Down Expand Up @@ -97,15 +104,21 @@ func TestFinalizerIngressClassChange(t *testing.T) {
t.Fatalf("create(%s/%s) = %v, want nil; Ingress: %v", ing.Namespace, ing.Name, err, ing)
}
t.Logf("Ingress created (%s/%s)", s.Namespace, ing.Name)
ing = waitForStableIngress(true, ing, s, t)
ing, err := e2e.WaitForIngress(s, ing, &e2e.WaitForIngressOptions{ExpectUnreachable: true})
if err != nil {
t.Fatalf("error waiting for Ingress to stabilize: %v", err)
}

ingFinalizers := ing.GetFinalizers()
if len(ingFinalizers) != 1 || ingFinalizers[0] != common.FinalizerKey {
t.Fatalf("GetFinalizers() = %+v, want [%q]", ingFinalizers, common.FinalizerKey)
}

// Perform whitebox testing.
gclb := whiteboxTest(ing, s, t, "")
gclb, err := e2e.WhiteboxTest(ing, s, Framework.Cloud, "")
if err != nil {
t.Fatalf("e2e.WhiteboxTest(%s/%s, ...)", ing.Namespace, ing.Name)
}

// Change Ingress class
newIngClass := "nginx"
Expand Down Expand Up @@ -162,8 +175,14 @@ func TestFinalizerIngressesWithSharedResources(t *testing.T) {
}
t.Logf("Ingress created (%s/%s)", s.Namespace, otherIng.Name)

ing = waitForStableIngress(true, ing, s, t)
otherIng = waitForStableIngress(true, otherIng, s, t)
ing, err = e2e.WaitForIngress(s, ing, &e2e.WaitForIngressOptions{ExpectUnreachable: true})
if err != nil {
t.Fatalf("error waiting for Ingress to stabilize: %v", err)
}
otherIng, err = e2e.WaitForIngress(s, otherIng, &e2e.WaitForIngressOptions{ExpectUnreachable: true})
if err != nil {
t.Fatalf("error waiting for Ingress to stabilize: %v", err)
}

ingFinalizers := ing.GetFinalizers()
if len(ingFinalizers) != 1 || ingFinalizers[0] != common.FinalizerKey {
Expand All @@ -175,8 +194,14 @@ func TestFinalizerIngressesWithSharedResources(t *testing.T) {
}

// Perform whitebox testing.
gclb := whiteboxTest(ing, s, t, "")
otherGclb := whiteboxTest(otherIng, s, t, "")
gclb, err := e2e.WhiteboxTest(ing, s, Framework.Cloud, "")
if err != nil {
t.Fatalf("e2e.WhiteboxTest(%s/%s, ...)", ing.Namespace, ing.Name)
}
otherGclb, err := e2e.WhiteboxTest(otherIng, s, Framework.Cloud, "")
if err != nil {
t.Fatalf("e2e.WhiteboxTest(%s/%s, ...)", otherIng.Namespace, otherIng.Name)
}

// SkipBackends ensure that we dont wait on deletion of shared backends.
deleteOptions := &fuzz.GCLBDeleteOptions{
Expand Down Expand Up @@ -221,15 +246,22 @@ func TestUpdateTo1dot7(t *testing.T) {
t.Fatalf("create(%s/%s) = %v, want nil; Ingress: %v", ing.Namespace, ing.Name, err, ing)
}
t.Logf("Ingress created (%s/%s)", s.Namespace, ing.Name)
ing = waitForStableIngress(true, ing, s, t)

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

// Check that finalizer is not added in old version in which finalizer add is not enabled.
ingFinalizers := ing.GetFinalizers()
if l := len(ingFinalizers); l != 0 {
t.Fatalf("GetFinalizers() = %d, want 0", l)
}
// Perform whitebox testing.
whiteboxTest(ing, s, t, "")
gclb, err := e2e.WhiteboxTest(ing, s, Framework.Cloud, "")
if err != nil {
t.Fatalf("e2e.WhiteboxTest(%s/%s, ...)", ing.Namespace, ing.Name)
}

for {
// While k8s master is upgrading, it will return a connection refused
Expand All @@ -251,7 +283,9 @@ func TestUpdateTo1dot7(t *testing.T) {
}

// Perform whitebox testing.
gclb := whiteboxTest(ing, s, t, "")
if gclb, err = e2e.WhiteboxTest(ing, s, Framework.Cloud, ""); err != nil {
t.Fatalf("e2e.WhiteboxTest(%s/%s, ...)", ing.Namespace, ing.Name)
}

// If the Master has upgraded and the Ingress is stable,
// we delete the Ingress and exit out of the loop to indicate that
Expand Down
21 changes: 6 additions & 15 deletions cmd/e2e-test/neg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"k8s.io/ingress-gce/pkg/annotations"
"k8s.io/ingress-gce/pkg/e2e"
"k8s.io/ingress-gce/pkg/fuzz"
"k8s.io/ingress-gce/pkg/fuzz/features"
"k8s.io/ingress-gce/pkg/neg/types/shared"
)

Expand Down Expand Up @@ -116,7 +115,10 @@ func TestNEG(t *testing.T) {
t.Logf("GCLB resources created (%s/%s)", s.Namespace, ing.Name)

// Perform whitebox testing.
gclb := whiteboxTest(ing, s, t, "")
gclb, err := e2e.WhiteboxTest(ing, s, Framework.Cloud, "")
if err != nil {
t.Fatalf("e2e.WhiteboxTest(%s/%s, ...)", ing.Namespace, ing.Name)
}

// TODO(mixia): The below checks should be merged into PerformWhiteboxTests().
if (len(gclb.NetworkEndpointGroup) > 0) != tc.expectNegBackend {
Expand Down Expand Up @@ -205,20 +207,9 @@ func TestNEGTransition(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)
params := &fuzz.GCLBForVIPParams{VIP: vip, Validators: fuzz.FeatureValidators(features.All)}
gclb, err := fuzz.GCLBForVIP(context.Background(), Framework.Cloud, params)
gclb, err := e2e.WhiteboxTest(ing, s, Framework.Cloud, "")
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)
t.Fatalf("e2e.WhiteboxTest(%s/%s, ...)", ing.Namespace, ing.Name)
}

if tc.negGC {
Expand Down
Loading

0 comments on commit 3ef83d5

Please sign in to comment.