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 20, 2019
1 parent a2e96e0 commit 26ad076
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 175 deletions.
3 changes: 2 additions & 1 deletion cmd/e2e-test/basic_https_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"testing"

"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/ingress-gce/cmd/e2e-test/common"
"k8s.io/ingress-gce/pkg/e2e"
"k8s.io/ingress-gce/pkg/fuzz"
)
Expand Down Expand Up @@ -111,7 +112,7 @@ 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 := common.WhiteboxTest(ing, s, t, Framework.Cloud, "")

deleteOptions := &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
Expand Down
42 changes: 3 additions & 39 deletions cmd/e2e-test/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"k8s.io/api/networking/v1beta1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/ingress-gce/cmd/e2e-test/common"
"k8s.io/ingress-gce/pkg/e2e"
"k8s.io/ingress-gce/pkg/fuzz"
"k8s.io/ingress-gce/pkg/fuzz/features"
Expand Down Expand Up @@ -83,7 +84,7 @@ 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 := common.WhiteboxTest(ing, s, t, Framework.Cloud, "")

deleteOptions := &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
Expand Down Expand Up @@ -191,7 +192,7 @@ 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 := common.WhiteboxTest(ing, s, t, Framework.Cloud, "")

deleteOptions := &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
Expand All @@ -202,40 +203,3 @@ 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
}
65 changes: 65 additions & 0 deletions cmd/e2e-test/common/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package common

import (
"context"
"testing"

"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud"
"k8s.io/api/networking/v1beta1"
"k8s.io/ingress-gce/pkg/e2e"
"k8s.io/ingress-gce/pkg/fuzz"
"k8s.io/ingress-gce/pkg/fuzz/features"
)

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, cloud cloud.Cloud, 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(), 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
}
41 changes: 21 additions & 20 deletions cmd/e2e-test/finalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import (
"testing"

"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/ingress-gce/cmd/e2e-test/common"
"k8s.io/ingress-gce/pkg/e2e"
"k8s.io/ingress-gce/pkg/fuzz"
"k8s.io/ingress-gce/pkg/utils/common"
finalizer "k8s.io/ingress-gce/pkg/utils/common"
)

// TestFinalizer asserts that finalizer is added/ removed appropriately during the life cycle
Expand Down Expand Up @@ -53,15 +54,15 @@ 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 = common.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)
if len(ingFinalizers) != 1 || ingFinalizers[0] != finalizer.FinalizerKey {
t.Fatalf("GetFinalizers() = %+v, want [%q]", ingFinalizers, finalizer.FinalizerKey)
}

// Perform whitebox testing.
gclb := whiteboxTest(ing, s, t, "")
gclb := common.WhiteboxTest(ing, s, t, Framework.Cloud, "")

deleteOptions := &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
Expand Down Expand Up @@ -97,15 +98,15 @@ 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 = common.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)
if len(ingFinalizers) != 1 || ingFinalizers[0] != finalizer.FinalizerKey {
t.Fatalf("GetFinalizers() = %+v, want [%q]", ingFinalizers, finalizer.FinalizerKey)
}

// Perform whitebox testing.
gclb := whiteboxTest(ing, s, t, "")
gclb := common.WhiteboxTest(ing, s, t, Framework.Cloud, "")

// Change Ingress class
newIngClass := "nginx"
Expand Down Expand Up @@ -162,21 +163,21 @@ 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 = common.WaitForStableIngress(true, ing, s, t)
otherIng = common.WaitForStableIngress(true, otherIng, s, t)

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

// Perform whitebox testing.
gclb := whiteboxTest(ing, s, t, "")
otherGclb := whiteboxTest(otherIng, s, t, "")
gclb := common.WhiteboxTest(ing, s, t, Framework.Cloud, "")
otherGclb := common.WhiteboxTest(otherIng, s, t, Framework.Cloud, "")

// SkipBackends ensure that we dont wait on deletion of shared backends.
deleteOptions := &fuzz.GCLBDeleteOptions{
Expand Down Expand Up @@ -221,15 +222,15 @@ 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 = common.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, "")
common.WhiteboxTest(ing, s, t, Framework.Cloud, "")

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

// Perform whitebox testing.
gclb := whiteboxTest(ing, s, t, "")
gclb := common.WhiteboxTest(ing, s, t, Framework.Cloud, "")

// 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
3 changes: 2 additions & 1 deletion cmd/e2e-test/neg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/api/networking/v1beta1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/ingress-gce/cmd/e2e-test/common"
"k8s.io/ingress-gce/pkg/annotations"
"k8s.io/ingress-gce/pkg/e2e"
"k8s.io/ingress-gce/pkg/fuzz"
Expand Down Expand Up @@ -116,7 +117,7 @@ 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 := common.WhiteboxTest(ing, s, t, Framework.Cloud, "")

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

0 comments on commit 26ad076

Please sign in to comment.