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

Migrate upgrade tests to use the upgrade framework #951

Merged
merged 1 commit into from
Nov 21, 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
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, ...) = %v, want nil", ing.Namespace, ing.Name, err)
}

deleteOptions := &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
Expand Down
78 changes: 29 additions & 49 deletions cmd/e2e-test/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"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"
)

func TestBasic(t *testing.T) {
Expand Down Expand Up @@ -83,7 +84,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, ...) = %v, want nil", ing.Namespace, ing.Name, err)
}

deleteOptions := &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
Expand Down Expand Up @@ -191,7 +195,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, ...) = %v, want nil", ing.Namespace, ing.Name, err)
}

deleteOptions := &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
Expand All @@ -203,43 +210,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 @@ -284,14 +254,20 @@ func TestFrontendResourceDeletion(t *testing.T) {

ing := fuzz.NewIngressBuilder(s.Namespace, "ing1", "").
AddPath(host, "/", svcName, port80).AddTLS([]string{}, cert.Name).Build()
ingKey := common.NamespacedName(ing)

crud := e2e.IngressCRUD{C: Framework.Clientset}
if _, err := crud.Create(ing); err != nil {
t.Fatalf("crud.Create(%s/%s) = %v, want nil; Ingress: %v", ing.Namespace, ing.Name, err, ing)
t.Fatalf("crud.Create(%s) = %v, want nil; Ingress: %v", ingKey, err, ing)
}
t.Logf("Ingress created (%s)", ingKey)
if ing, err = e2e.WaitForIngress(s, ing, &e2e.WaitForIngressOptions{ExpectUnreachable: true}); err != nil {
t.Fatalf("error waiting for Ingress %s to stabilize: %v", ingKey, err)
}
gclb, err := e2e.WhiteboxTest(ing, s, Framework.Cloud, "")
if err != nil {
t.Fatalf("e2e.WhiteboxTest(%s, ...)", ingKey)
}
t.Logf("Ingress created (%s/%s)", s.Namespace, ing.Name)
ing = waitForStableIngress(true, ing, s, t)
gclb := whiteboxTest(ing, s, t, "")

// Update ingress with desired frontend resource configuration.
ingBuilder := fuzz.NewIngressBuilderFromExisting(ing)
Expand All @@ -304,10 +280,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) = %v, want nil; ingress: %v", ingKey, err, ing)
}
t.Logf("Ingress updated (%s)", ingKey)
if ing, err = e2e.WaitForIngress(s, ing, &e2e.WaitForIngressOptions{ExpectUnreachable: true}); err != nil {
t.Fatalf("error waiting for Ingress %s to stabilize: %v", ingKey, err)
}
t.Logf("Ingress updated (%s/%s)", ing.Namespace, ing.Name)
ing = waitForStableIngress(true, ing, s, t)

deleteOptions := &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
Expand All @@ -316,14 +294,16 @@ func TestFrontendResourceDeletion(t *testing.T) {
}
// Wait for unused frontend resources to be deleted.
if err := e2e.WaitForFrontendResourceDeletion(ctx, Framework.Cloud, gclb, deleteOptions); err != nil {
t.Errorf("e2e.WaitForIngressDeletion(..., %q, _) = %v, want nil", ing.Name, err)
t.Errorf("e2e.WaitForIngressDeletion(..., %q, _) = %v, want nil", ingKey, err)
}
if gclb, err = e2e.WhiteboxTest(ing, s, Framework.Cloud, ""); err != nil {
t.Fatalf("e2e.WhiteboxTest(%s, ...) = %v, want nil", ingKey, err)
}
whiteboxTest(ing, s, t, "")
deleteOptions = &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
}
if err := e2e.WaitForIngressDeletion(ctx, gclb, s, ing, deleteOptions); err != nil {
t.Errorf("e2e.WaitForIngressDeletion(..., %q, _) = %v, want nil", ing.Name, err)
t.Errorf("e2e.WaitForIngressDeletion(..., %q, _) = %v, want nil", ingKey, err)
}
})
}
Expand Down
98 changes: 67 additions & 31 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 All @@ -49,25 +49,33 @@ func TestFinalizer(t *testing.T) {

crud := e2e.IngressCRUD{C: Framework.Clientset}
ing.Namespace = s.Namespace
ingKey := common.NamespacedName(ing)
if _, err := crud.Create(ing); err != nil {
t.Fatalf("create(%s/%s) = %v, want nil; Ingress: %v", ing.Namespace, ing.Name, err, ing)
t.Fatalf("create(%s) = %v, want nil; Ingress: %v", ingKey, err, ing)
}
t.Logf("Ingress created (%s)", ingKey)

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

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, ...) = %v, want nil", ingKey, err)
}

deleteOptions := &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
}
if err := e2e.WaitForIngressDeletion(ctx, gclb, s, ing, deleteOptions); err != nil {
t.Errorf("e2e.WaitForIngressDeletion(..., %q, nil) = %v, want nil", ing.Name, err)
t.Errorf("e2e.WaitForIngressDeletion(..., %q, nil) = %v, want nil", ingKey, err)
}
})
}
Expand All @@ -93,36 +101,43 @@ func TestFinalizerIngressClassChange(t *testing.T) {

crud := e2e.IngressCRUD{C: Framework.Clientset}
ing.Namespace = s.Namespace
ingKey := common.NamespacedName(ing)
if _, err := crud.Create(ing); err != nil {
t.Fatalf("create(%s/%s) = %v, want nil; Ingress: %v", ing.Namespace, ing.Name, err, ing)
t.Fatalf("create(%s) = %v, want nil; Ingress: %v", ingKey, err, ing)
}
t.Logf("Ingress created (%s)", ingKey)
ing, err := e2e.WaitForIngress(s, ing, &e2e.WaitForIngressOptions{ExpectUnreachable: true})
if err != nil {
t.Fatalf("error waiting for Ingress %s to stabilize: %v", ingKey, err)
}
t.Logf("Ingress created (%s/%s)", s.Namespace, ing.Name)
ing = waitForStableIngress(true, ing, s, t)

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, ...) = %v, want nil", ingKey, err)
}

// Change Ingress class
newIngClass := "nginx"
ing = fuzz.NewIngressBuilderFromExisting(ing).SetIngressClass(newIngClass).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) = %v, want nil; ingress: %v", ingKey, err, ing)
}
t.Logf("Ingress (%s/%s) class changed to %s", s.Namespace, ing.Name, newIngClass)
t.Logf("Ingress (%s) class changed to %s", ingKey, newIngClass)

deleteOptions := &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
}
if err := e2e.WaitForFinalizerDeletion(ctx, gclb, s, ing.Name, deleteOptions); err != nil {
t.Errorf("e2e.WaitForFinalizerDeletion(..., %q, _) = %v, want nil", ing.Name, err)
}
t.Logf("Finalizer for Ingress (%s/%s) deleted", s.Namespace, ing.Name)
t.Logf("Finalizer for Ingress (%s) deleted", ingKey)
})
}

Expand Down Expand Up @@ -151,19 +166,25 @@ func TestFinalizerIngressesWithSharedResources(t *testing.T) {

crud := e2e.IngressCRUD{C: Framework.Clientset}
ing.Namespace = s.Namespace
ingKey := common.NamespacedName(ing)
if _, err := crud.Create(ing); err != nil {
t.Fatalf("create(%s/%s) = %v, want nil; Ingress: %v", ing.Namespace, ing.Name, err, ing)
t.Fatalf("create(%s) = %v, want nil; Ingress: %v", ingKey, err, ing)
}
t.Logf("Ingress created (%s/%s)", s.Namespace, ing.Name)
t.Logf("Ingress created (%s)", ingKey)

otherIng.Namespace = s.Namespace
otherIngKey := common.NamespacedName(ing)
if _, err := crud.Create(otherIng); err != nil {
t.Fatalf("create(%s/%s) = %v, want nil; Ingress: %v", otherIng.Namespace, otherIng.Name, err, otherIng)
t.Fatalf("create(%s) = %v, want nil; Ingress: %v", otherIngKey, err, otherIng)
}
t.Logf("Ingress created (%s/%s)", s.Namespace, otherIng.Name)
t.Logf("Ingress created (%s)", otherIngKey)

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

ingFinalizers := ing.GetFinalizers()
if len(ingFinalizers) != 1 || ingFinalizers[0] != common.FinalizerKey {
Expand All @@ -175,22 +196,28 @@ 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, ...) = %v, want nil", ingKey, err)
}
otherGclb, err := e2e.WhiteboxTest(otherIng, s, Framework.Cloud, "")
if err != nil {
t.Fatalf("e2e.WhiteboxTest(%s)", otherIngKey)
}

// SkipBackends ensure that we dont wait on deletion of shared backends.
deleteOptions := &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
SkipBackends: true,
}
if err := e2e.WaitForIngressDeletion(ctx, gclb, s, ing, deleteOptions); err != nil {
t.Errorf("e2e.WaitForIngressDeletion(..., %q, nil) = %v, want nil", ing.Name, err)
t.Errorf("e2e.WaitForIngressDeletion(..., %q, nil) = %v, want nil", ingKey, err)
}
deleteOptions = &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
}
if err := e2e.WaitForIngressDeletion(ctx, otherGclb, s, otherIng, deleteOptions); err != nil {
t.Errorf("e2e.WaitForIngressDeletion(..., %q, nil) = %v, want nil", otherIng.Name, err)
t.Errorf("e2e.WaitForIngressDeletion(..., %q, nil) = %v, want nil", otherIngKey, err)
}
})
}
Expand All @@ -217,19 +244,26 @@ func TestUpdateTo1dot7(t *testing.T) {

crud := e2e.IngressCRUD{C: Framework.Clientset}
ing.Namespace = s.Namespace
ingKey := common.NamespacedName(ing)
if _, err := crud.Create(ing); err != nil {
t.Fatalf("create(%s/%s) = %v, want nil; Ingress: %v", ing.Namespace, ing.Name, err, ing)
t.Fatalf("create(%s) = %v, want nil; Ingress: %v", ingKey, err, ing)
}
t.Logf("Ingress created (%s)", ingKey)

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

// 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, ...) = %v, want nil", ingKey, err)
}

for {
// While k8s master is upgrading, it will return a connection refused
Expand All @@ -247,11 +281,13 @@ func TestUpdateTo1dot7(t *testing.T) {

// Wait for finalizer to be added and verify that correct finalizer is added to the ingress after the upgrade.
if err := e2e.WaitForFinalizer(s, ing.Name); err != nil {
t.Errorf("e2e.WaitForFinalizer(_, %q) = %v, want nil", ing.Name, err)
t.Errorf("e2e.WaitForFinalizer(_, %q) = %v, want nil", ingKey, err)
}

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

// 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 @@ -260,7 +296,7 @@ func TestUpdateTo1dot7(t *testing.T) {
SkipDefaultBackend: true,
}
if err := e2e.WaitForIngressDeletion(context.Background(), gclb, s, ing, deleteOptions); err != nil {
t.Errorf("e2e.WaitForIngressDeletion(..., %q, nil) = %v, want nil", ing.Name, err)
t.Errorf("e2e.WaitForIngressDeletion(..., %q, nil) = %v, want nil", ingKey, err)
}
})
}
Expand Down
Loading