Skip to content
Open
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
114 changes: 114 additions & 0 deletions test/e2e/ingress2gateway/builders.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package ingress2gateway

import (
"maps"

networking "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ingressGroupOutput holds the built resources ready for creation.
type ingressGroupOutput struct {
IngressClass *networking.IngressClass
Ingresses []*networking.Ingress
}

// buildBasicIngressGroup builds an IngressGroup with 2 members:
// - member-1: admin.example.com / -> svcC
// - member-2: app.example.com /api -> svcA, /health -> svcB
//
// Includes health check annotations and user tags.
func buildBasicIngressGroup(namespace, groupName string, ipFamily string, svcAName, svcBName, svcCName string) ingressGroupOutput {
pathPrefix := networking.PathTypePrefix
ingressClassName := namespace

ingClass := &networking.IngressClass{
ObjectMeta: metav1.ObjectMeta{
Name: ingressClassName,
},
Spec: networking.IngressClassSpec{
Controller: ingressController,
},
}

sharedAnnotations := map[string]string{
annotationScheme: "internet-facing",
annotationTargetType: "ip",
annotationGroupName: groupName,
annotationTags: "Team=e2e,Component=migration",
annotationHealthCheckPath: pathHealth,
annotationHealthyThreshold: "2",
annotationUnhealthyThreshold: "3",
annotationHealthCheckInterval: "15",
}
if ipFamily == "IPv6" {
sharedAnnotations[annotationIPAddressType] = "dualstack"
}

ing1Annotations := maps.Clone(sharedAnnotations)
ing1Annotations[annotationGroupOrder] = "1"

ing2Annotations := maps.Clone(sharedAnnotations)
ing2Annotations[annotationGroupOrder] = "2"

ing1 := &networking.Ingress{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: "member-1",
Annotations: ing1Annotations,
},
Spec: networking.IngressSpec{
IngressClassName: &ingressClassName,
Rules: []networking.IngressRule{
{
Host: hostAdmin,
IngressRuleValue: networking.IngressRuleValue{
HTTP: &networking.HTTPIngressRuleValue{
Paths: []networking.HTTPIngressPath{
{Path: pathRoot, PathType: &pathPrefix, Backend: ingressBackend(svcCName)},
},
},
},
},
},
},
}

ing2 := &networking.Ingress{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: "member-2",
Annotations: ing2Annotations,
},
Spec: networking.IngressSpec{
IngressClassName: &ingressClassName,
Rules: []networking.IngressRule{
{
Host: hostApp,
IngressRuleValue: networking.IngressRuleValue{
HTTP: &networking.HTTPIngressRuleValue{
Paths: []networking.HTTPIngressPath{
{Path: pathAPI, PathType: &pathPrefix, Backend: ingressBackend(svcAName)},
{Path: pathHealth, PathType: &pathPrefix, Backend: ingressBackend(svcBName)},
},
},
},
},
},
},
}

return ingressGroupOutput{
IngressClass: ingClass,
Ingresses: []*networking.Ingress{ing1, ing2},
}
}

func ingressBackend(svcName string) networking.IngressBackend {
return networking.IngressBackend{
Service: &networking.IngressServiceBackend{
Name: svcName,
Port: networking.ServiceBackendPort{Number: 80},
},
}
}
32 changes: 32 additions & 0 deletions test/e2e/ingress2gateway/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ingress2gateway

const (
ingressController = "ingress.k8s.aws/alb"

annotationScheme = "alb.ingress.kubernetes.io/scheme"
annotationTargetType = "alb.ingress.kubernetes.io/target-type"
annotationGroupName = "alb.ingress.kubernetes.io/group.name"
annotationGroupOrder = "alb.ingress.kubernetes.io/group.order"
annotationTags = "alb.ingress.kubernetes.io/tags"
annotationHealthCheckPath = "alb.ingress.kubernetes.io/healthcheck-path"
annotationHealthyThreshold = "alb.ingress.kubernetes.io/healthy-threshold-count"
annotationUnhealthyThreshold = "alb.ingress.kubernetes.io/unhealthy-threshold-count"
annotationHealthCheckInterval = "alb.ingress.kubernetes.io/healthcheck-interval-seconds"
annotationIPAddressType = "alb.ingress.kubernetes.io/ip-address-type"
annotationDryRunPlan = "alb.ingress.kubernetes.io/dry-run-plan"

gwDryRunAnnotation = "gateway.k8s.aws/dry-run"
gwDryRunPlan = "gateway.k8s.aws/dry-run-plan"
migrationTagKey = "gateway.k8s.aws/migrated-from"

hostAdmin = "admin.example.com"
hostApp = "app.example.com"

pathRoot = "/"
pathAPI = "/api"
pathHealth = "/health"

bodyServiceA = "service-a"
bodyServiceB = "service-b"
bodyServiceC = "service-c"
)
34 changes: 34 additions & 0 deletions test/e2e/ingress2gateway/ingress2gateway_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package ingress2gateway

import (
"testing"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"sigs.k8s.io/aws-load-balancer-controller/test/framework"
)

var tf *framework.Framework

func TestIngress2Gateway(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Ingress2Gateway Suite")
}

var _ = SynchronizedBeforeSuite(func() []byte {
var err error
tf, err = framework.InitFramework()
Expect(err).NotTo(HaveOccurred())

if tf.Options.ControllerImage != "" {
err = tf.CTRLInstallationManager.UpgradeController(tf.Options.ControllerImage, true, true, false)
Expect(err).NotTo(HaveOccurred())
time.Sleep(60 * time.Second)
}
return nil
}, func(data []byte) {
var err error
tf, err = framework.InitFramework()
Expect(err).NotTo(HaveOccurred())
})
Loading
Loading