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

Use backendconfig v1 for e2e tests #1045

Merged
merged 3 commits into from
Apr 7, 2020
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
157 changes: 157 additions & 0 deletions cmd/e2e-test/affinity_beta_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/*
Copyright 2018 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 main

import (
"context"
"fmt"
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/util/retry"
"k8s.io/ingress-gce/pkg/annotations"
backendconfigbeta "k8s.io/ingress-gce/pkg/apis/backendconfig/v1beta1"
"k8s.io/ingress-gce/pkg/e2e"
"k8s.io/ingress-gce/pkg/e2e/adapter"
"k8s.io/ingress-gce/pkg/fuzz"
"k8s.io/ingress-gce/pkg/fuzz/features"
)

func TestAffinityBeta(t *testing.T) {
t.Parallel()

affinityTransitions := []affinityTransition{
// "http with cookie based affinity."
{affinity: "GENERATED_COOKIE"},
// no affinity
{affinity: "NONE"},
// http with cookie based affinity and 60s ttl.
{affinity: "GENERATED_COOKIE", ttl: 60},
// client ip affinity.
{affinity: "CLIENT_IP"},
}

Framework.RunWithSandbox("affinity-v1beta1", t, func(t *testing.T, s *e2e.Sandbox) {
t.Parallel()
ctx := context.Background()

backendConfigAnnotation := map[string]string{
annotations.BetaBackendConfigKey: `{"default":"backendconfigbeta"}`,
}
affinityType := "CLIENT_IP"
beConfig := &backendconfigbeta.BackendConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "backendconfigbeta",
},
Spec: backendconfigbeta.BackendConfigSpec{
SessionAffinity: &backendconfigbeta.SessionAffinityConfig{
AffinityType: affinityType,
},
},
}
if _, err := Framework.BackendConfigClient.CloudV1beta1().BackendConfigs(s.Namespace).Create(beConfig); err != nil {
t.Fatalf("CloudV1beta1().BackendConfigs(%q).Create(%#v) = %v, want nil", s.Namespace, beConfig, err)
}
t.Logf("BackendConfig created (%s/%s) ", s.Namespace, beConfig.Name)

svcName := "service-1"
_, err := e2e.CreateEchoService(s, svcName, backendConfigAnnotation)
if err != nil {
t.Fatalf("e2e.CreateEchoService(_, %q, %q) = %v, want nil", svcName, backendConfigAnnotation, err)
}
t.Logf("Echo service created (%s/%s)", s.Namespace, svcName)

ing := fuzz.NewIngressBuilder(s.Namespace, "ingress-1", "").
AddPath("test.com", "/", svcName, intstr.FromInt(80)).
Build()
crud := adapter.IngressCRUD{C: Framework.Clientset}
if _, err := crud.Create(ing); err != nil {
t.Fatalf("crud.Create(%#v) = %v, want nil", ing, err)
}
ingKey := fmt.Sprintf("%s/%s", s.Namespace, ing.Name)
t.Logf("Ingress created (%s)", ingKey)

ing, err = e2e.WaitForIngress(s, ing, nil)
if err != nil {
t.Fatalf("e2e.WaitForIngress(_, %q, nil) = %v, want nil", ingKey, err)
}
t.Logf("GCLB resources created (%s)", ingKey)

vip := ing.Status.LoadBalancer.Ingress[0].IP
t.Logf("Ingress %s VIP = %s", ingKey, vip)

params := &fuzz.GCLBForVIPParams{VIP: vip, Validators: fuzz.FeatureValidators(features.All)}
gclb, err := fuzz.GCLBForVIP(context.Background(), Framework.Cloud, params)
if err != nil {
t.Fatalf("fuzz.GCLBForVIP(_, _, %q) = %v, want nil; fail to get GCP resources for LB with IP(%q)", vip, err, vip)
}

// Check conformity.
if err := verifyAffinity(t, gclb, s.Namespace, svcName, affinityType, 0); err != nil {
t.Error(err)
}

for _, transition := range affinityTransitions {
// Test modifications.
if err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
bc, err := Framework.BackendConfigClient.CloudV1beta1().BackendConfigs(s.Namespace).Get(beConfig.Name, metav1.GetOptions{})
if err != nil {
return err
}
if bc.Spec.SessionAffinity == nil {
bc.Spec.SessionAffinity = &backendconfigbeta.SessionAffinityConfig{}
}
bc.Spec.SessionAffinity.AffinityType = transition.affinity
bc.Spec.SessionAffinity.AffinityCookieTtlSec = &transition.ttl
_, err = Framework.BackendConfigClient.CloudV1beta1().BackendConfigs(s.Namespace).Update(bc)
return err
}); err != nil {
t.Errorf("CloudV1beta1().BackendConfigs(%q).Update(%#v) = %v, want nil", s.Namespace, transition, err)
}

if waitErr := wait.Poll(transitionPollInterval, transitionPollTimeout, func() (bool, error) {
gclb, err = fuzz.GCLBForVIP(context.Background(), Framework.Cloud, params)
if err != nil {
t.Logf("Error getting GCP resources for LB with IP(%q): %v", vip, err)
return false, nil
}
if err := verifyAffinity(t, gclb, s.Namespace, svcName, transition.affinity, transition.ttl); err != nil {
return false, nil
}
return true, nil
}); waitErr != nil {
t.Errorf("Error waiting for BackendConfig affinity transition propagation to GCLB, last seen error: %v", err)
}
}

// Wait for GCLB resources to be deleted.
if err := crud.Delete(s.Namespace, ing.Name); err != nil {
t.Errorf("crud.Delete(%q) = %v, want nil", ingKey, err)
}

deleteOptions := &fuzz.GCLBDeleteOptions{
SkipDefaultBackend: true,
}
t.Logf("Waiting for GCLB resources to be deleted (%s)", ingKey)
if err := e2e.WaitForGCLBDeletion(ctx, Framework.Cloud, gclb, deleteOptions); err != nil {
t.Errorf("e2e.WaitForGCLBDeletion(_, _, %q, %#v) = %v, want nil", gclb.VIP, deleteOptions, err)
}
t.Logf("GCLB resources deleted (%s)", ingKey)
})
}
32 changes: 18 additions & 14 deletions cmd/e2e-test/affinity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ import (
"testing"
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/util/retry"
"k8s.io/ingress-gce/pkg/annotations"
backendconfig "k8s.io/ingress-gce/pkg/apis/backendconfig/v1beta1"
backendconfig "k8s.io/ingress-gce/pkg/apis/backendconfig/v1"
"k8s.io/ingress-gce/pkg/e2e"
"k8s.io/ingress-gce/pkg/e2e/adapter"
"k8s.io/ingress-gce/pkg/fuzz"
"k8s.io/ingress-gce/pkg/fuzz/features"
"k8s.io/ingress-gce/pkg/utils"
)

const (
transitionPollTimeout = 10 * time.Minute
tansitionPollInterval = 30 * time.Second
transitionPollTimeout = 10 * time.Minute
transitionPollInterval = 30 * time.Second
)

type affinityTransition struct {
Expand Down Expand Up @@ -89,7 +89,9 @@ func TestAffinity(t *testing.T) {
annotations.BetaBackendConfigKey: `{"default":"backendconfig-1"}`,
}

if _, err := Framework.BackendConfigClient.CloudV1beta1().BackendConfigs(s.Namespace).Create(tc.beConfig); err != nil {
bcCRUD := adapter.BackendConfigCRUD{C: Framework.BackendConfigClient}
tc.beConfig.Namespace = s.Namespace
if _, err := bcCRUD.Create(tc.beConfig); err != nil {
t.Fatalf("error creating BackendConfig: %v", err)
}
t.Logf("BackendConfig created (%s/%s) ", s.Namespace, tc.beConfig.Name)
Expand All @@ -103,7 +105,7 @@ func TestAffinity(t *testing.T) {
ing := fuzz.NewIngressBuilder(s.Namespace, "ingress-1", "").
AddPath("test.com", "/", "service-1", intstr.FromInt(80)).
Build()
crud := e2e.IngressCRUD{C: Framework.Clientset}
crud := adapter.IngressCRUD{C: Framework.Clientset}
if _, err := crud.Create(ing); err != nil {
t.Fatalf("error creating Ingress spec: %v", err)
}
Expand Down Expand Up @@ -131,7 +133,7 @@ func TestAffinity(t *testing.T) {

// Test modifications
if err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
bc, err := Framework.BackendConfigClient.CloudV1beta1().BackendConfigs(s.Namespace).Get(tc.beConfig.Name, metav1.GetOptions{})
bc, err := bcCRUD.Get(tc.beConfig.Namespace, tc.beConfig.Name)
if err != nil {
return err
}
Expand All @@ -140,13 +142,13 @@ func TestAffinity(t *testing.T) {
}
bc.Spec.SessionAffinity.AffinityType = tc.transition.affinity
bc.Spec.SessionAffinity.AffinityCookieTtlSec = &tc.transition.ttl
_, err = Framework.BackendConfigClient.CloudV1beta1().BackendConfigs(s.Namespace).Update(bc)
_, err = bcCRUD.Update(bc)
return err
}); err != nil {
t.Errorf("Failed to update BackendConfig affinity settings for %s: %v", t.Name(), err)
}

if err := wait.Poll(tansitionPollInterval, transitionPollTimeout, func() (bool, error) {
if err := wait.Poll(transitionPollInterval, transitionPollTimeout, func() (bool, error) {
gclb, err = fuzz.GCLBForVIP(context.Background(), Framework.Cloud, params)
if err != nil {
t.Logf("error getting GCP resources for LB with IP = %q: %v", vip, err)
Expand Down Expand Up @@ -225,7 +227,9 @@ func TestILBSA(t *testing.T) {
annotations.NEGAnnotationKey: negVal.String(),
}

if _, err := Framework.BackendConfigClient.CloudV1beta1().BackendConfigs(s.Namespace).Create(tc.beConfig); err != nil {
bcCRUD := adapter.BackendConfigCRUD{C: Framework.BackendConfigClient}
tc.beConfig.Namespace = s.Namespace
if _, err := bcCRUD.Create(tc.beConfig); err != nil {
t.Fatalf("error creating BackendConfig: %v", err)
}
t.Logf("BackendConfig created (%s/%s) ", s.Namespace, tc.beConfig.Name)
Expand All @@ -240,7 +244,7 @@ func TestILBSA(t *testing.T) {
AddPath("test.com", "/", "service-1", intstr.FromInt(80)).
ConfigureForILB().
Build()
crud := e2e.IngressCRUD{C: Framework.Clientset}
crud := adapter.IngressCRUD{C: Framework.Clientset}
if _, err := crud.Create(ing); err != nil {
t.Fatalf("error creating Ingress spec: %v", err)
}
Expand Down Expand Up @@ -268,7 +272,7 @@ func TestILBSA(t *testing.T) {

// Test modifications
if err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
bc, err := Framework.BackendConfigClient.CloudV1beta1().BackendConfigs(s.Namespace).Get(tc.beConfig.Name, metav1.GetOptions{})
bc, err := bcCRUD.Get(tc.beConfig.Namespace, tc.beConfig.Name)
if err != nil {
return err
}
Expand All @@ -277,13 +281,13 @@ func TestILBSA(t *testing.T) {
}
bc.Spec.SessionAffinity.AffinityType = tc.transition.affinity
bc.Spec.SessionAffinity.AffinityCookieTtlSec = &tc.transition.ttl
_, err = Framework.BackendConfigClient.CloudV1beta1().BackendConfigs(s.Namespace).Update(bc)
_, err = bcCRUD.Update(bc)
return err
}); err != nil {
t.Errorf("Failed to update BackendConfig affinity settings for %s: %v", t.Name(), err)
}

if err := wait.Poll(tansitionPollInterval, transitionPollTimeout, func() (bool, error) {
if err := wait.Poll(transitionPollInterval, transitionPollTimeout, func() (bool, error) {
gclb, err = fuzz.GCLBForVIP(context.Background(), Framework.Cloud, params)
if err != nil {
t.Logf("error getting GCP resources for LB with IP = %q: %v", vip, err)
Expand Down
5 changes: 3 additions & 2 deletions cmd/e2e-test/app_protocols_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/ingress-gce/pkg/annotations"
"k8s.io/ingress-gce/pkg/e2e"
"k8s.io/ingress-gce/pkg/e2e/adapter"
"k8s.io/ingress-gce/pkg/fuzz"
"k8s.io/ingress-gce/pkg/fuzz/features"
)
Expand Down Expand Up @@ -62,7 +63,7 @@ func TestAppProtocol(t *testing.T) {
DefaultBackend("service-1", intstr.FromString("https-port")).
AddPath("test.com", "/", "service-1", intstr.FromString("https-port")).
Build()
crud := e2e.IngressCRUD{C: Framework.Clientset}
crud := adapter.IngressCRUD{C: Framework.Clientset}
if _, err := crud.Create(ing); err != nil {
t.Fatalf("error creating Ingress spec: %v", err)
}
Expand Down Expand Up @@ -132,7 +133,7 @@ func TestAppProtocolTransition(t *testing.T) {
DefaultBackend("service-1", intstr.FromString("https-port")).
AddPath("test.com", "/", "service-1", intstr.FromString("https-port")).
Build()
crud := e2e.IngressCRUD{C: Framework.Clientset}
crud := adapter.IngressCRUD{C: Framework.Clientset}
if _, err := crud.Create(ing); err != nil {
t.Fatalf("error creating Ingress spec: %v", err)
}
Expand Down
11 changes: 7 additions & 4 deletions cmd/e2e-test/backend_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/ingress-gce/pkg/e2e/adapter"

"k8s.io/ingress-gce/pkg/annotations"
backendconfigv1beta1 "k8s.io/ingress-gce/pkg/apis/backendconfig/v1beta1"
backendconfigv1 "k8s.io/ingress-gce/pkg/apis/backendconfig/v1"
"k8s.io/ingress-gce/pkg/e2e"
"k8s.io/ingress-gce/pkg/fuzz"
)
Expand All @@ -44,7 +45,7 @@ func TestBackendConfigNegatives(t *testing.T) {
for _, tc := range []struct {
desc string
svcAnnotations map[string]string
backendConfig *backendconfigv1beta1.BackendConfig
backendConfig *backendconfigv1.BackendConfig
secretName string
expectedMsg string
}{
Expand Down Expand Up @@ -80,7 +81,9 @@ func TestBackendConfigNegatives(t *testing.T) {
t.Parallel()

if tc.backendConfig != nil {
if _, err := Framework.BackendConfigClient.CloudV1beta1().BackendConfigs(s.Namespace).Create(tc.backendConfig); err != nil {
tc.backendConfig.Namespace = s.Namespace
bcCRUD := adapter.BackendConfigCRUD{C: Framework.BackendConfigClient}
if _, err := bcCRUD.Create(tc.backendConfig); err != nil {
t.Fatalf("Error creating backend config: %v", err)
}
t.Logf("Backend config %s/%s created", s.Namespace, tc.backendConfig.Name)
Expand All @@ -104,7 +107,7 @@ func TestBackendConfigNegatives(t *testing.T) {
testIng := fuzz.NewIngressBuilder(s.Namespace, "ingress-1", "").
AddPath("test.com", "/", "service-1", port80).
Build()
crud := e2e.IngressCRUD{C: Framework.Clientset}
crud := adapter.IngressCRUD{C: Framework.Clientset}
testIng, err := crud.Create(testIng)
if err != nil {
t.Fatalf("error creating Ingress spec: %v", err)
Expand Down
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 @@ -23,6 +23,7 @@ import (

"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/ingress-gce/pkg/e2e"
"k8s.io/ingress-gce/pkg/e2e/adapter"
"k8s.io/ingress-gce/pkg/fuzz"
)

Expand Down Expand Up @@ -98,7 +99,7 @@ func TestBasicHTTPS(t *testing.T) {
}
t.Logf("Echo service created (%s/%s)", s.Namespace, "service-1")

crud := e2e.IngressCRUD{C: Framework.Clientset}
crud := adapter.IngressCRUD{C: Framework.Clientset}
if _, err := crud.Create(ing); err != nil {
t.Fatalf("error creating Ingress spec: %v", err)
}
Expand Down
Loading