Skip to content

Commit

Permalink
update on AccessLogPolicy and TargetGroupPolicy e2e-tests (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhail-aws authored Nov 18, 2023
1 parent 7c2c8ab commit af28cb1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 74 deletions.
1 change: 1 addition & 0 deletions test/pkg/test/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ func (env *Framework) ExpectDeleted(ctx context.Context, objects ...client.Objec
if err != nil {
// not found is probably OK - means it was deleted elsewhere
if !errors.IsNotFound(err) {
env.Log.Error(err)
Expect(err).ToNot(HaveOccurred())
}
}
Expand Down
58 changes: 0 additions & 58 deletions test/pkg/test/target_group_policy.go
Original file line number Diff line number Diff line change
@@ -1,59 +1 @@
package test

import (
anv1alpha1 "github.com/aws/aws-application-networking-k8s/pkg/apis/applicationnetworking/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gwv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gwv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
)

type TargetGroupPolicyConfig struct {
PolicyName string
Protocol *string
ProtocolVersion *string
HealthCheck *anv1alpha1.HealthCheckConfig
}

func (env *Framework) CreateTargetGroupPolicy(
service *corev1.Service,
config *TargetGroupPolicyConfig,
) *anv1alpha1.TargetGroupPolicy {
return &anv1alpha1.TargetGroupPolicy{
TypeMeta: metav1.TypeMeta{
Kind: "TargetGroupPolicy",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: service.Namespace,
Name: config.PolicyName,
},
Spec: anv1alpha1.TargetGroupPolicySpec{
TargetRef: &gwv1alpha2.PolicyTargetReference{
Kind: gwv1beta1.Kind("Service"),
Name: gwv1beta1.ObjectName(service.Name),
},
Protocol: config.Protocol,
ProtocolVersion: config.ProtocolVersion,
HealthCheck: config.HealthCheck,
},
}
}

func (env *Framework) UpdateTargetGroupPolicy(
policy *anv1alpha1.TargetGroupPolicy,
config *TargetGroupPolicyConfig,
) *anv1alpha1.TargetGroupPolicy {
if config.Protocol != nil {
policy.Spec.Protocol = config.Protocol
}

if config.ProtocolVersion != nil {
policy.Spec.ProtocolVersion = config.ProtocolVersion
}

if config.HealthCheck != nil {
policy.Spec.HealthCheck = config.HealthCheck
}

return policy
}
4 changes: 3 additions & 1 deletion test/suites/integration/access_log_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package integration

import (
"fmt"
"math/rand"
"strconv"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -35,7 +37,6 @@ var _ = Describe("Access Log Policy", Ordered, func() {
const (
k8sResourceName = "test-access-log-policy"
k8sResourceName2 = "test-access-log-policy-secondary"
bucketName = "k8s-test-lattice-bucket"
logGroupName = "k8s-test-lattice-log-group"
logGroup2Name = "k8s-test-lattice-log-group-secondary"
deliveryStreamName = "k8s-test-lattice-delivery-stream"
Expand Down Expand Up @@ -80,6 +81,7 @@ var _ = Describe("Access Log Policy", Ordered, func() {
logGroup2Arn string
deliveryStreamArn string
roleArn string
bucketName = "eks-gateway-api-access-log-test-" + strconv.Itoa(rand.Int())
)

BeforeAll(func() {
Expand Down
70 changes: 55 additions & 15 deletions test/suites/integration/target_group_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,28 @@ package integration
import (
"time"

"github.com/aws/aws-application-networking-k8s/pkg/apis/applicationnetworking/v1alpha1"
"github.com/aws/aws-application-networking-k8s/test/pkg/test"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/vpclattice"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
gwv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gwv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"

anv1alpha1 "github.com/aws/aws-application-networking-k8s/pkg/apis/applicationnetworking/v1alpha1"
"github.com/aws/aws-application-networking-k8s/test/pkg/test"
)

var _ = Describe("Target Group Policy Tests", Ordered, func() {
var (
deployment *appsv1.Deployment
service *corev1.Service
httpRoute *gwv1.HTTPRoute
policy *v1alpha1.TargetGroupPolicy
policy *anv1alpha1.TargetGroupPolicy
)

BeforeAll(func() {
Expand All @@ -34,22 +39,23 @@ var _ = Describe("Target Group Policy Tests", Ordered, func() {
})

It("Update Protocol replaces the Target Group with new one", func() {
policy = testFramework.CreateTargetGroupPolicy(service, &test.TargetGroupPolicyConfig{
policy = createTargetGroupPolicy(service, &TargetGroupPolicyConfig{
PolicyName: "test-policy",
Protocol: aws.String(vpclattice.TargetGroupProtocolHttp),
})

testFramework.ExpectCreated(ctx, policy)

tg := testFramework.GetTargetGroup(ctx, service)

Expect(*tg.Protocol).To(Equal(vpclattice.TargetGroupProtocolHttp))

testFramework.UpdateTargetGroupPolicy(policy, &test.TargetGroupPolicyConfig{
Protocol: aws.String(vpclattice.TargetGroupProtocolHttps),
})
err := testFramework.Client.Get(ctx, client.ObjectKeyFromObject(policy), policy)
Expect(err).Should(BeNil())

policy.Spec.Protocol = aws.String(vpclattice.TargetGroupProtocolHttps)
err = testFramework.Client.Update(ctx, policy)
Expect(err).Should(BeNil())

testFramework.ExpectUpdated(ctx, policy)
testFramework.VerifyTargetGroupNotFound(tg)

httpsTG := testFramework.GetTargetGroupWithProtocol(ctx, service, "https", "http1")
Expand All @@ -58,11 +64,11 @@ var _ = Describe("Target Group Policy Tests", Ordered, func() {
})

It("Delete Target Group Policy reset health check config for HTTP and HTTP1 Target Group", func() {
policy = testFramework.CreateTargetGroupPolicy(service, &test.TargetGroupPolicyConfig{
policy = createTargetGroupPolicy(service, &TargetGroupPolicyConfig{
PolicyName: "test-policy",
Protocol: aws.String(vpclattice.TargetGroupProtocolHttp),
ProtocolVersion: aws.String(vpclattice.TargetGroupProtocolVersionHttp1),
HealthCheck: &v1alpha1.HealthCheckConfig{
HealthCheck: &anv1alpha1.HealthCheckConfig{
IntervalSeconds: aws.Int64(7),
StatusMatch: aws.String("200,204"),
},
Expand All @@ -72,9 +78,7 @@ var _ = Describe("Target Group Policy Tests", Ordered, func() {

Eventually(func(g Gomega) {
tgSummary := testFramework.GetTargetGroup(ctx, service)

tg := testFramework.GetFullTargetGroupFromSummary(ctx, tgSummary)

g.Expect(*tg.Config.HealthCheck.ProtocolVersion).To(Equal(vpclattice.TargetGroupProtocolVersionHttp1))
g.Expect(*tg.Config.HealthCheck.Protocol).To(Equal(vpclattice.TargetGroupProtocolHttp))
g.Expect(*tg.Config.HealthCheck.HealthCheckIntervalSeconds).To(BeEquivalentTo(7))
Expand Down Expand Up @@ -106,7 +110,7 @@ var _ = Describe("Target Group Policy Tests", Ordered, func() {
})

It("Delete Target Group Policy create HTTP and HTTP1 Target Group", func() {
policy = testFramework.CreateTargetGroupPolicy(service, &test.TargetGroupPolicyConfig{
policy = createTargetGroupPolicy(service, &TargetGroupPolicyConfig{
PolicyName: "test-policy",
Protocol: aws.String(vpclattice.TargetGroupProtocolHttps),
ProtocolVersion: aws.String(vpclattice.TargetGroupProtocolVersionHttp2),
Expand All @@ -128,7 +132,12 @@ var _ = Describe("Target Group Policy Tests", Ordered, func() {
AfterEach(func() {
testFramework.ExpectDeleted(
ctx,
policy,
&anv1alpha1.TargetGroupPolicy{
ObjectMeta: metav1.ObjectMeta{
Name: policy.Name,
Namespace: policy.Namespace,
},
},
)
})

Expand All @@ -141,3 +150,34 @@ var _ = Describe("Target Group Policy Tests", Ordered, func() {
)
})
})

type TargetGroupPolicyConfig struct {
PolicyName string
Protocol *string
ProtocolVersion *string
HealthCheck *anv1alpha1.HealthCheckConfig
}

func createTargetGroupPolicy(
service *corev1.Service,
config *TargetGroupPolicyConfig,
) *anv1alpha1.TargetGroupPolicy {
return &anv1alpha1.TargetGroupPolicy{
TypeMeta: metav1.TypeMeta{
Kind: "TargetGroupPolicy",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: service.Namespace,
Name: config.PolicyName,
},
Spec: anv1alpha1.TargetGroupPolicySpec{
TargetRef: &gwv1alpha2.PolicyTargetReference{
Kind: gwv1beta1.Kind("Service"),
Name: gwv1beta1.ObjectName(service.Name),
},
Protocol: config.Protocol,
ProtocolVersion: config.ProtocolVersion,
HealthCheck: config.HealthCheck,
},
}
}

0 comments on commit af28cb1

Please sign in to comment.