diff --git a/cmd/e2e-test/basic_https_test.go b/cmd/e2e-test/basic_https_test.go index 058c3bae17..f9c775df26 100644 --- a/cmd/e2e-test/basic_https_test.go +++ b/cmd/e2e-test/basic_https_test.go @@ -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, diff --git a/cmd/e2e-test/basic_test.go b/cmd/e2e-test/basic_test.go index 97b4365442..7247f6dcc2 100644 --- a/cmd/e2e-test/basic_test.go +++ b/cmd/e2e-test/basic_test.go @@ -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, @@ -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, @@ -202,40 +208,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 -} diff --git a/cmd/e2e-test/finalizer_test.go b/cmd/e2e-test/finalizer_test.go index 4cd3689f5d..33890b5fe9 100644 --- a/cmd/e2e-test/finalizer_test.go +++ b/cmd/e2e-test/finalizer_test.go @@ -18,14 +18,14 @@ 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/utils/common" + "k8s.io/ingress-gce/pkg/fuzz/features" + finalizer "k8s.io/ingress-gce/pkg/utils/common" ) // TestFinalizer asserts that finalizer is added/ removed appropriately during the life cycle @@ -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) + 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, 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, @@ -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) + 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, 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" @@ -162,21 +175,33 @@ 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 { - 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, 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{ @@ -221,7 +246,11 @@ 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() @@ -229,7 +258,10 @@ func TestUpdateTo1dot7(t *testing.T) { 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 @@ -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 diff --git a/cmd/e2e-test/neg_test.go b/cmd/e2e-test/neg_test.go index d8f5e4d1dd..d902c647fb 100644 --- a/cmd/e2e-test/neg_test.go +++ b/cmd/e2e-test/neg_test.go @@ -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" ) @@ -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 { @@ -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 { diff --git a/cmd/e2e-test/upgrade/basic_http.go b/cmd/e2e-test/upgrade/basic_http.go new file mode 100644 index 0000000000..12fdecb7a6 --- /dev/null +++ b/cmd/e2e-test/upgrade/basic_http.go @@ -0,0 +1,136 @@ +/* +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 upgrade + +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" +) + +var ( + port80 = intstr.FromInt(80) + ingName = "ing1" +) + +// Finalizer implements e2e.UpgradeTest interface. +type BasicHTTP struct { + t *testing.T + s *e2e.Sandbox + framework *e2e.Framework + crud e2e.IngressCRUD + ing *v1beta1.Ingress +} + +// NewBasicHTTPUpgradeTest returns an upgrade test that tests the basic behavior +// of an ingress with http load-balancer. +func NewBasicHTTPUpgradeTest() e2e.UpgradeTest { + return &BasicHTTP{} +} + +// Name implements e2e.UpgradeTest.Init. +func (bh *BasicHTTP) Name() string { + return "BasicHTTPUpgrade" +} + +// Init implements e2e.UpgradeTest.Init. +func (bh *BasicHTTP) Init(t *testing.T, s *e2e.Sandbox, framework *e2e.Framework) error { + bh.t = t + bh.s = s + bh.framework = framework + return nil +} + +// PreUpgrade implements e2e.UpgradeTest.PreUpgrade. +func (bh *BasicHTTP) PreUpgrade() error { + _, err := e2e.CreateEchoService(bh.s, svcName, nil) + if err != nil { + bh.t.Fatalf("error creating echo service: %v", err) + } + bh.t.Logf("Echo service created (%s/%s)", bh.s.Namespace, svcName) + + ing := fuzz.NewIngressBuilder(bh.s.Namespace, ingName, ""). + AddPath("foo.com", "/", svcName, port80). + Build() + bh.crud = e2e.IngressCRUD{C: bh.framework.Clientset} + if _, err := bh.crud.Create(ing); err != nil { + bh.t.Fatalf("error creating Ingress %s/%s: %v", ing.Namespace, ing.Name, err) + } + bh.t.Logf("Ingress created (%s/%s)", bh.s.Namespace, ing.Name) + + if ing, err = e2e.WaitForIngress(bh.s, ing, &e2e.WaitForIngressOptions{ExpectUnreachable: true}); err != nil { + bh.t.Fatalf("error waiting for Ingress to stabilize: %v", err) + } + bh.s.PutStatus(e2e.Stable) + bh.t.Logf("GCLB resources created (%s/%s)", bh.s.Namespace, ing.Name) + + if _, err := e2e.WhiteboxTest(ing, bh.s, bh.framework.Cloud, ""); err != nil { + bh.t.Fatalf("e2e.WhiteboxTest(%s/%s, ...)", ing.Namespace, ing.Name) + } + return nil +} + +// DuringUpgrade implements e2e.UpgradeTest.DuringUpgrade. +func (bh *BasicHTTP) DuringUpgrade() error { + return nil +} + +// PostUpgrade implements e2e.UpgradeTest.PostUpgrade +func (bh *BasicHTTP) PostUpgrade() error { + // force ingress update. only add path once + newIng := fuzz.NewIngressBuilderFromExisting(bh.ing). + AddPath("bar.com", "/", "service-1", port80). + Build() + // TODO: does the path need to be different for each upgrade + if _, err := bh.crud.Update(newIng); err != nil { + bh.t.Fatalf("error updating Ingress %s/%s: %v", newIng.Namespace, newIng.Name, err) + } else { + // If Ingress upgrade succeeds, we update the status on this Ingress + // to Unstable. It is set back to Stable after WaitForIngress below + // finishes successfully. + bh.s.PutStatus(e2e.Unstable) + } + + // Verify the Ingress has stabilized after the master upgrade and we + // trigger an Ingress update + ing, err := e2e.WaitForIngress(bh.s, bh.ing, &e2e.WaitForIngressOptions{ExpectUnreachable: true}) + if err != nil { + bh.t.Fatalf("error waiting for Ingress to stabilize: %v", err) + } + bh.s.PutStatus(e2e.Stable) + bh.t.Logf("GCLB is stable (%s/%s)", bh.s.Namespace, ing.Name) + gclb, err := e2e.WhiteboxTest(ing, bh.s, bh.framework.Cloud, "") + if err != nil { + bh.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 + // the test is done. + deleteOptions := &fuzz.GCLBDeleteOptions{ + SkipDefaultBackend: true, + } + + if err := e2e.WaitForIngressDeletion(context.Background(), gclb, bh.s, ing, deleteOptions); err != nil { // Sometimes times out waiting + bh.t.Errorf("e2e.WaitForIngressDeletion(..., %q, nil) = %v, want nil", ing.Name, err) + } + return nil +} diff --git a/cmd/e2e-test/upgrade/neg.go b/cmd/e2e-test/upgrade/neg.go index 45c8149fb7..e60e496d5b 100644 --- a/cmd/e2e-test/upgrade/neg.go +++ b/cmd/e2e-test/upgrade/neg.go @@ -47,6 +47,11 @@ func NewStandaloneNegUpgradeTest() e2e.UpgradeTest { return &StandaloneNeg{} } +// Name implements e2e.UpgradeTest.Init. +func (sn *StandaloneNeg) Name() string { + return "StandaloneNegUpgrade" +} + // Init implements e2e.UpgradeTest.Init. func (sn *StandaloneNeg) Init(t *testing.T, s *e2e.Sandbox, framework *e2e.Framework) error { sn.t = t diff --git a/cmd/e2e-test/upgrade_test.go b/cmd/e2e-test/upgrade_test.go index 4ec01b73d4..1f5c3129ff 100644 --- a/cmd/e2e-test/upgrade_test.go +++ b/cmd/e2e-test/upgrade_test.go @@ -17,132 +17,35 @@ limitations under the License. package main import ( - "context" "testing" - "k8s.io/api/networking/v1beta1" - "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/ingress-gce/cmd/e2e-test/upgrade" "k8s.io/ingress-gce/pkg/e2e" - "k8s.io/ingress-gce/pkg/fuzz" ) -func TestUpgrade(t *testing.T) { - t.Parallel() - - port80 := intstr.FromInt(80) - - for _, tc := range []struct { - desc string - ing *v1beta1.Ingress - }{ - { - desc: "http default backend", - ing: fuzz.NewIngressBuilder("", "ingress-1", ""). - AddPath("foo.com", "/", "service-1", port80). - Build(), - }, - } { - tc := tc // Capture tc as we are running this in parallel. - Framework.RunWithSandbox(tc.desc, t, func(t *testing.T, s *e2e.Sandbox) { - t.Parallel() - - _, err := e2e.CreateEchoService(s, "service-1", nil) - if err != nil { - t.Fatalf("error creating echo service: %v", err) - } - t.Logf("Echo service created (%s/%s)", s.Namespace, "service-1") - - tc.ing.Namespace = s.Namespace // namespace depends on sandbox - crud := e2e.IngressCRUD{C: Framework.Clientset} - if _, err := crud.Create(tc.ing); err != nil { - t.Fatalf("error creating Ingress spec: %v", err) - } - t.Logf("Ingress created (%s/%s)", s.Namespace, tc.ing.Name) - s.PutStatus(e2e.Unstable) - - ing := waitForStableIngress(true, tc.ing, s, t) - t.Logf("GCLB resources created (%s/%s)", s.Namespace, tc.ing.Name) - - whiteboxTest(ing, s, t, "") - - for { - // While k8s master is upgrading, it will return a connection refused - // error for any k8s resource we try to hit. We loop until the - // master upgrade has finished. - if s.MasterUpgrading() { - continue - } - - if s.MasterUpgraded() { - t.Logf("Detected master upgrade, adding a path to Ingress to force Ingress update") - // force ingress update. only add path once - newIng := fuzz.NewIngressBuilderFromExisting(tc.ing). - AddPath("bar.com", "/", "service-1", port80). - Build() - newIng.Namespace = s.Namespace // namespace depends on sandbox - // TODO: does the path need to be different for each upgrade - if _, err := crud.Update(newIng); err != nil { - t.Fatalf("error creating Ingress spec: %v", err) - } else { - // If Ingress upgrade succeeds, we update the status on this Ingress - // to Unstable. It is set back to Stable after WaitForIngress below - // finishes successfully. - s.PutStatus(e2e.Unstable) - } - - break - } - } - - // Verify the Ingress has stabilized after the master upgrade and we - // trigger an Ingress update - ing = waitForStableIngress(true, ing, s, t) - t.Logf("GCLB is stable (%s/%s)", s.Namespace, tc.ing.Name) - 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 - // the test is done. - deleteOptions := &fuzz.GCLBDeleteOptions{ - SkipDefaultBackend: true, - } - - if err := e2e.WaitForIngressDeletion(context.Background(), gclb, s, ing, deleteOptions); err != nil { // Sometimes times out waiting - t.Errorf("e2e.WaitForIngressDeletion(..., %q, nil) = %v, want nil", ing.Name, err) - } - }) - } -} - -// TODO: migrate existing upgrade tests to the generic upgrade test. func TestGenericUpgrade(t *testing.T) { t.Parallel() - for _, tc := range []struct { - desc string - test e2e.UpgradeTest - }{ - { - desc: "standalone NEG should work for upgrade", - test: upgrade.NewStandaloneNegUpgradeTest(), - }, + for _, test := range []e2e.UpgradeTest{ + upgrade.NewBasicHTTPUpgradeTest(), + upgrade.NewStandaloneNegUpgradeTest(), } { - tc := tc // Capture tc as we are running this in parallel. - Framework.RunWithSandbox(tc.desc, t, func(t *testing.T, s *e2e.Sandbox) { + test := test // Capture test as we are running this in parallel. + desc := test.Name() + Framework.RunWithSandbox(desc, t, func(t *testing.T, s *e2e.Sandbox) { t.Parallel() - t.Logf("Running upgrade test %v", tc.desc) - if err := tc.test.Init(t, s, Framework); err != nil { - t.Fatalf("For upgrade test %v, step Init failed due to %v", tc.desc, err) + t.Logf("Running upgrade test %v", desc) + if err := test.Init(t, s, Framework); err != nil { + t.Fatalf("For upgrade test %v, step Init failed due to %v", desc, err) } s.PutStatus(e2e.Unstable) func() { // always mark the test as stable in order to unblock other upgrade tests. defer s.PutStatus(e2e.Stable) - if err := tc.test.PreUpgrade(); err != nil { - t.Fatalf("For upgrade test %v, step PreUpgrade failed due to %v", tc.desc, err) + if err := test.PreUpgrade(); err != nil { + t.Fatalf("For upgrade test %v, step PreUpgrade failed due to %v", desc, err) } }() @@ -151,21 +54,20 @@ func TestGenericUpgrade(t *testing.T) { // error for any k8s resource we try to hit. We loop until the // master upgrade has finished. if s.MasterUpgrading() { - if err := tc.test.DuringUpgrade(); err != nil { - t.Fatalf("For upgrade test %v, step DuringUpgrade failed due to %v", tc.desc, err) + if err := test.DuringUpgrade(); err != nil { + t.Fatalf("For upgrade test %v, step DuringUpgrade failed due to %v", desc, err) } continue } if s.MasterUpgraded() { - t.Logf("Detected master upgrade, continuing upgrade test %v", tc.desc) + t.Logf("Detected master upgrade, continuing upgrade test %v", desc) break } } - if err := tc.test.PostUpgrade(); err != nil { - t.Fatalf("For upgrade test %v, step PostUpgrade failed due to %v", tc.desc, err) + if err := test.PostUpgrade(); err != nil { + t.Fatalf("For upgrade test %v, step PostUpgrade failed due to %v", desc, err) } - }) } } diff --git a/pkg/e2e/helpers.go b/pkg/e2e/helpers.go index 526d53bd55..54fb76e5a1 100644 --- a/pkg/e2e/helpers.go +++ b/pkg/e2e/helpers.go @@ -140,8 +140,32 @@ func WaitForFinalizer(s *Sandbox, ingName string) error { }) } -// PerformWhiteboxTests runs the whitebox tests against the Ingress. -func PerformWhiteboxTests(s *Sandbox, ing *v1beta1.Ingress, gclb *fuzz.GCLB) error { +// WhiteboxTest retrieves GCP load-balancer for Ingress VIP and runs the whitebox tests. +func WhiteboxTest(ing *v1beta1.Ingress, s *Sandbox, cloud cloud.Cloud, region string) (*fuzz.GCLB, error) { + if len(ing.Status.LoadBalancer.Ingress) < 1 { + return nil, fmt.Errorf("ingress does not have an IP: %+v", ing.Status) + } + + vip := ing.Status.LoadBalancer.Ingress[0].IP + klog.Infof("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 { + return nil, fmt.Errorf("error getting GCP resources for LB with IP = %q: %v", vip, err) + } + + if err := performWhiteboxTests(s, ing, gclb); err != nil { + return nil, fmt.Errorf("error performing whitebox tests: %v", err) + } + return gclb, nil +} + +// performWhiteboxTests runs the whitebox tests against the Ingress. +func performWhiteboxTests(s *Sandbox, ing *v1beta1.Ingress, gclb *fuzz.GCLB) error { validator, err := fuzz.NewIngressValidator(s.ValidatorEnv, ing, []fuzz.Feature{}, whitebox.AllTests, nil) if err != nil { return err diff --git a/pkg/e2e/interfaces.go b/pkg/e2e/interfaces.go index 2d3a2b80ff..adebae637f 100644 --- a/pkg/e2e/interfaces.go +++ b/pkg/e2e/interfaces.go @@ -23,6 +23,8 @@ import ( // UpgradeTest is an interface for writing generic upgrade test. // TODO: add version compatibility into the interface type UpgradeTest interface { + // Name returns the name/description of the test. + Name() string // Init initialized the Upgrade Test. Init(t *testing.T, s *Sandbox, framework *Framework) error // PreUpgrade runs before master upgrade.