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

Added HTTPRoute Creation/Update E2E Tests #312

Merged
merged 2 commits into from
Aug 9, 2023
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ e2etest:
cd test && go test \
-p 1 \
-count 1 \
-timeout 60m \
-timeout 90m \
-v \
./suites/... \
--ginkgo.focus="${FOCUS}" \
--ginkgo.timeout=60m \
--ginkgo.timeout=90m \
--ginkgo.v
112 changes: 112 additions & 0 deletions test/suites/integration/httproute_creation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package integration

import (
"os"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
"sigs.k8s.io/gateway-api/apis/v1beta1"
"sigs.k8s.io/mcs-api/pkg/apis/v1alpha1"

"github.com/aws/aws-application-networking-k8s/pkg/latticestore"
"github.com/aws/aws-application-networking-k8s/test/pkg/test"
"github.com/aws/aws-sdk-go/service/vpclattice"
)

var _ = Describe("HTTPRoute Creation", func() {

var (
gateway *v1beta1.Gateway
deployment *appsv1.Deployment
service *v1.Service
serviceExport *v1alpha1.ServiceExport
serviceImport *v1alpha1.ServiceImport
httpRoute *v1beta1.HTTPRoute
vpcLatticeService *vpclattice.ServiceSummary
targetGroup *vpclattice.TargetGroupSummary
)

BeforeEach(func() {
gateway = testFramework.NewGateway("test-gateway", k8snamespace)
testFramework.ExpectCreated(ctx, gateway)

deployment, service = testFramework.NewElasticApp(test.ElasticSearchOptions{
Name: "port-test",
Namespace: k8snamespace,
})
})

Context("Order #1: serviceImport, httpRoute, serviceExport, & service", func() {
It("creates successfully", func() {
serviceImport = testFramework.CreateServiceImport(service)
testFramework.ExpectCreated(ctx, serviceImport)

httpRoute = testFramework.NewHttpRoute(gateway, service)
testFramework.ExpectCreated(ctx, httpRoute)

serviceExport = testFramework.CreateServiceExport(service)
testFramework.ExpectCreated(ctx, serviceExport)

testFramework.ExpectCreated(ctx, service, deployment)

verifyResourceCreation(vpcLatticeService, httpRoute, targetGroup, service)
})
})

Context("Order #2: httpRoute, serviceImport, service, & serviceExport", func() {
It("creates successfully", func() {
httpRoute = testFramework.NewHttpRoute(gateway, service)
testFramework.ExpectCreated(ctx, httpRoute)

serviceImport = testFramework.CreateServiceImport(service)
testFramework.ExpectCreated(ctx, serviceImport)

testFramework.ExpectCreated(ctx, service, deployment)

serviceExport = testFramework.CreateServiceExport(service)
testFramework.ExpectCreated(ctx, serviceExport)

verifyResourceCreation(vpcLatticeService, httpRoute, targetGroup, service)
})
})

Context("Order #3: serviceExport, httpRoute, serviceImport, & service", func() {
It("creates successfully", func() {
serviceExport = testFramework.CreateServiceExport(service)
testFramework.ExpectCreated(ctx, serviceExport)

httpRoute = testFramework.NewHttpRoute(gateway, service)
testFramework.ExpectCreated(ctx, httpRoute)

serviceImport = testFramework.CreateServiceImport(service)
testFramework.ExpectCreated(ctx, serviceImport)

testFramework.ExpectCreated(ctx, service, deployment)

verifyResourceCreation(vpcLatticeService, httpRoute, targetGroup, service)
})
})

AfterEach(func() {
testFramework.CleanTestEnvironment(ctx)
})
})

func verifyResourceCreation(
vpcLatticeService *vpclattice.ServiceSummary,
httpRoute *v1beta1.HTTPRoute,
targetGroup *vpclattice.TargetGroupSummary,
service *v1.Service,
) {
time.Sleep(3 * time.Minute) // Allow time for Lattice resources to be created

vpcLatticeService = testFramework.GetVpcLatticeService(ctx, httpRoute)
Expect(*vpcLatticeService.DnsEntry).To(ContainSubstring(latticestore.LatticeServiceName(httpRoute.Name, httpRoute.Namespace)))

targetGroup = testFramework.GetTargetGroup(ctx, service)
Expect(*targetGroup.VpcIdentifier).To(Equal(os.Getenv("CLUSTER_VPC_ID")))
Expect(*targetGroup.Protocol).To(Equal("HTTP"))
}
103 changes: 103 additions & 0 deletions test/suites/integration/httproute_update_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package integration

import (
"github.com/samber/lo"
"k8s.io/apimachinery/pkg/types"
"log"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/gateway-api/apis/v1beta1"

"github.com/aws/aws-application-networking-k8s/pkg/latticestore"
"github.com/aws/aws-application-networking-k8s/test/pkg/test"
"github.com/aws/aws-sdk-go/service/vpclattice"
)

var _ = Describe("HTTPRoute Update", func() {
Context("Create a HTTPRoute with backendref to service1, then update the HTTPRoute with backendref to service1 "+
"and service2, then update the HTTPRoute with backendref to just service2", func() {

var (
gateway *v1beta1.Gateway
pathMatchHttpRouteOne *v1beta1.HTTPRoute
pathMatchHttpRouteTwo *v1beta1.HTTPRoute
deployment1 *appsv1.Deployment
service1 *corev1.Service
deployment2 *appsv1.Deployment
service2 *corev1.Service
)

It("Updates rules correctly with corresponding target groups after each update", func() {
rlymbur marked this conversation as resolved.
Show resolved Hide resolved
gateway = testFramework.NewGateway("", "default")
deployment1, service1 = testFramework.NewHttpApp(test.HTTPAppOptions{Name: "test-v1", Namespace: "default"})
deployment2, service2 = testFramework.NewHttpApp(test.HTTPAppOptions{Name: "test-v2", Namespace: "default"})

pathMatchHttpRouteOne = testFramework.NewPathMatchHttpRoute(gateway, []client.Object{service1}, "http",
"", "default")
pathMatchHttpRouteTwo = testFramework.NewPathMatchHttpRoute(gateway, []client.Object{service1, service2}, "http",
"", "default")

// Create Kubernetes Resources
testFramework.ExpectCreated(ctx,
gateway,
pathMatchHttpRouteOne,
service1,
deployment1,
service2,
deployment2,
)

log.Println("Set the pathMatchHttpRoute to backendRefs to just service1")
checkTgs(service1, service2, true, false)

testFramework.ExpectCreated(ctx,
pathMatchHttpRouteTwo,
)
testFramework.Get(ctx, types.NamespacedName{Name: pathMatchHttpRouteTwo.Name, Namespace: pathMatchHttpRouteTwo.Namespace}, pathMatchHttpRouteTwo)
testFramework.Update(ctx, pathMatchHttpRouteTwo)

log.Println("Updated the pathMatchHttpRoute to backendRefs to service1 and service2")
checkTgs(service1, service2, true, true)

testFramework.Get(ctx, types.NamespacedName{Name: pathMatchHttpRouteOne.Name, Namespace: pathMatchHttpRouteOne.Namespace}, pathMatchHttpRouteOne)
testFramework.Update(ctx, pathMatchHttpRouteOne) // Remove pathMatchHttpRouteTwo for service2 so service is free to use again
testFramework.ExpectDeleted(ctx, pathMatchHttpRouteTwo)
testFramework.EventuallyExpectNotFound(ctx, pathMatchHttpRouteTwo)
pathMatchHttpRouteOne.Spec.Rules[0].BackendRefs[0].BackendObjectReference.Name = v1beta1.ObjectName(service2.Name)
testFramework.Update(ctx, pathMatchHttpRouteOne)

log.Println("Updated the pathMatchHttpRoute to backendRefs to just service2")
checkTgs(service1, service2, false, true)
})
})

AfterEach(func() {
testFramework.CleanTestEnvironment(ctx)
})
})

func checkTgs(service1 *corev1.Service, service2 *corev1.Service, expectedService1TgFound bool, expectedService2TgFound bool) {
Eventually(func(g Gomega) bool {
var service1TgFound = false
var service2TgFound = false

targetGroups, err := testFramework.LatticeClient.ListTargetGroupsAsList(ctx, &vpclattice.ListTargetGroupsInput{})
Expect(err).To(BeNil())

for _, targetGroup := range targetGroups {
if lo.FromPtr(targetGroup.Name) == latticestore.TargetGroupName(service1.Name, service1.Namespace) {
service1TgFound = true
}
if lo.FromPtr(targetGroup.Name) == latticestore.TargetGroupName(service2.Name, service2.Namespace) {
service2TgFound = true
}
}

return service1TgFound == expectedService1TgFound && service2TgFound == expectedService2TgFound
}).WithPolling(15 * time.Second).WithTimeout(2 * time.Minute).Should(BeTrue())
}