Skip to content

Commit a11d4ef

Browse files
authored
Merge pull request #4227 from zac-nixon/main
add ip target tests for gateway api
2 parents 03de3e4 + 592cfaa commit a11d4ef

15 files changed

+376
-158
lines changed

pkg/gateway/model/model_build_target_group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ func (builder *targetGroupBuilderImpl) buildTargetGroupHealthCheckPath(targetGro
552552
return nil
553553
}
554554

555-
if targetGroupProps != nil && targetGroupProps.HealthCheckConfig.HealthCheckPath != nil {
555+
if targetGroupProps != nil && targetGroupProps.HealthCheckConfig != nil && targetGroupProps.HealthCheckConfig.HealthCheckPath != nil {
556556
return targetGroupProps.HealthCheckConfig.HealthCheckPath
557557
}
558558

pkg/gateway/model/model_build_target_group_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,11 +1792,22 @@ func Test_buildTargetGroupHealthCheckPath(t *testing.T) {
17921792
name: "default - tcp",
17931793
hcProtocol: elbv2model.ProtocolTCP,
17941794
},
1795+
{
1796+
name: "default - tcp - with cfg",
1797+
hcProtocol: elbv2model.ProtocolTCP,
1798+
targetGroupProps: &elbv2gw.TargetGroupProps{},
1799+
},
17951800
{
17961801
name: "default - http",
17971802
hcProtocol: elbv2model.ProtocolHTTP,
17981803
expected: &httpDefaultPath,
17991804
},
1805+
{
1806+
name: "default - http - with cfg",
1807+
hcProtocol: elbv2model.ProtocolHTTP,
1808+
expected: &httpDefaultPath,
1809+
targetGroupProps: &elbv2gw.TargetGroupProps{},
1810+
},
18001811
{
18011812
name: "default - grpc",
18021813
hcProtocol: elbv2model.ProtocolHTTP,

test/e2e/gateway/alb_instance_target.go

Lines changed: 0 additions & 68 deletions
This file was deleted.

test/e2e/gateway/alb_instance_target_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
"sigs.k8s.io/aws-load-balancer-controller/test/framework/verifier"
1212
)
1313

14-
var _ = Describe("test k8s alb gateway reconciled by the aws load balancer controller", func() {
14+
var _ = Describe("test k8s alb gateway using instance targets reconciled by the aws load balancer controller", func() {
1515
var (
1616
ctx context.Context
17-
stack ALBInstanceTestStack
17+
stack ALBTestStack
1818
dnsName string
1919
lbARN string
2020
)
@@ -23,7 +23,7 @@ var _ = Describe("test k8s alb gateway reconciled by the aws load balancer contr
2323
Skip("Skipping gateway tests")
2424
}
2525
ctx = context.Background()
26-
stack = ALBInstanceTestStack{}
26+
stack = ALBTestStack{}
2727
})
2828
AfterEach(func() {
2929
stack.Cleanup(ctx, tf)
@@ -35,12 +35,14 @@ var _ = Describe("test k8s alb gateway reconciled by the aws load balancer contr
3535
lbcSpec := elbv2gw.LoadBalancerConfigurationSpec{
3636
Scheme: &interf,
3737
}
38+
tgSpec := elbv2gw.TargetGroupConfigurationSpec{}
39+
3840
By("deploying stack", func() {
39-
err := stack.Deploy(ctx, tf, lbcSpec)
41+
err := stack.Deploy(ctx, tf, lbcSpec, tgSpec)
4042
Expect(err).NotTo(HaveOccurred())
4143
})
4244

43-
By("checking service status for lb dns name", func() {
45+
By("checking gateway status for lb dns name", func() {
4446
dnsName = stack.GetLoadBalancerIngressHostName()
4547
Expect(dnsName).ToNot(BeEmpty())
4648
})
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package gateway
2+
3+
import (
4+
"context"
5+
"fmt"
6+
. "github.com/onsi/ginkgo/v2"
7+
. "github.com/onsi/gomega"
8+
elbv2gw "sigs.k8s.io/aws-load-balancer-controller/apis/gateway/v1beta1"
9+
"sigs.k8s.io/aws-load-balancer-controller/test/framework/http"
10+
"sigs.k8s.io/aws-load-balancer-controller/test/framework/utils"
11+
"sigs.k8s.io/aws-load-balancer-controller/test/framework/verifier"
12+
)
13+
14+
var _ = Describe("test k8s alb gateway using ip targets reconciled by the aws load balancer controller", func() {
15+
var (
16+
ctx context.Context
17+
stack ALBTestStack
18+
dnsName string
19+
lbARN string
20+
)
21+
BeforeEach(func() {
22+
if !tf.Options.EnableGatewayTests {
23+
Skip("Skipping gateway tests")
24+
}
25+
ctx = context.Background()
26+
stack = ALBTestStack{}
27+
})
28+
AfterEach(func() {
29+
stack.Cleanup(ctx, tf)
30+
})
31+
Context("with ALB ip target configuration", func() {
32+
BeforeEach(func() {})
33+
It("should provision internet-facing load balancer resources", func() {
34+
interf := elbv2gw.LoadBalancerSchemeInternetFacing
35+
lbcSpec := elbv2gw.LoadBalancerConfigurationSpec{
36+
Scheme: &interf,
37+
}
38+
ipTargetType := elbv2gw.TargetTypeIP
39+
tgSpec := elbv2gw.TargetGroupConfigurationSpec{
40+
DefaultConfiguration: elbv2gw.TargetGroupProps{
41+
TargetType: &ipTargetType,
42+
},
43+
}
44+
45+
By("deploying stack", func() {
46+
err := stack.Deploy(ctx, tf, lbcSpec, tgSpec)
47+
Expect(err).NotTo(HaveOccurred())
48+
})
49+
50+
By("checking gateway status for lb dns name", func() {
51+
dnsName = stack.GetLoadBalancerIngressHostName()
52+
Expect(dnsName).ToNot(BeEmpty())
53+
})
54+
55+
By("querying AWS loadbalancer from the dns name", func() {
56+
var err error
57+
lbARN, err = tf.LBManager.FindLoadBalancerByDNSName(ctx, dnsName)
58+
Expect(err).NotTo(HaveOccurred())
59+
Expect(lbARN).ToNot(BeEmpty())
60+
})
61+
62+
tgMap := map[string]string{
63+
"80": "HTTP",
64+
}
65+
66+
targetNumber := int(*stack.albResourceStack.commonStack.dp.Spec.Replicas)
67+
68+
By("verifying AWS loadbalancer resources", func() {
69+
err := verifier.VerifyAWSLoadBalancerResources(ctx, tf, lbARN, verifier.LoadBalancerExpectation{
70+
Type: "application",
71+
Scheme: "internet-facing",
72+
TargetType: "ip",
73+
Listeners: stack.albResourceStack.getListenersPortMap(),
74+
TargetGroups: tgMap,
75+
NumTargets: targetNumber,
76+
TargetGroupHC: &verifier.TargetGroupHC{
77+
Protocol: "HTTP",
78+
Port: "traffic-port",
79+
Path: "/",
80+
Interval: 15,
81+
Timeout: 5,
82+
HealthyThreshold: 3,
83+
UnhealthyThreshold: 3,
84+
},
85+
})
86+
Expect(err).NotTo(HaveOccurred())
87+
})
88+
By("waiting for target group targets to be healthy", func() {
89+
err := verifier.WaitUntilTargetsAreHealthy(ctx, tf, lbARN, targetNumber)
90+
Expect(err).NotTo(HaveOccurred())
91+
})
92+
By("waiting until DNS name is available", func() {
93+
err := utils.WaitUntilDNSNameAvailable(ctx, dnsName)
94+
Expect(err).NotTo(HaveOccurred())
95+
})
96+
By("sending http request to the lb", func() {
97+
url := fmt.Sprintf("http://%v/any-path", dnsName)
98+
err := tf.HTTPVerifier.VerifyURL(url, http.ResponseCodeMatches(200))
99+
Expect(err).NotTo(HaveOccurred())
100+
})
101+
})
102+
})
103+
})

test/e2e/gateway/alb_resource_stack.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
1111
)
1212

13-
func newALBResourceStack(dp *appsv1.Deployment, svc *corev1.Service, gwc *gwv1.GatewayClass, gw *gwv1.Gateway, lbc *elbv2gw.LoadBalancerConfiguration, httpr *gwv1.HTTPRoute, baseName string, enablePodReadinessGate bool) *albResourceStack {
13+
func newALBResourceStack(dp *appsv1.Deployment, svc *corev1.Service, gwc *gwv1.GatewayClass, gw *gwv1.Gateway, lbc *elbv2gw.LoadBalancerConfiguration, tgc *elbv2gw.TargetGroupConfiguration, httpr *gwv1.HTTPRoute, baseName string, enablePodReadinessGate bool) *albResourceStack {
1414

15-
commonStack := newCommonResourceStack(dp, svc, gwc, gw, lbc, baseName, enablePodReadinessGate)
15+
commonStack := newCommonResourceStack(dp, svc, gwc, gw, lbc, tgc, baseName, enablePodReadinessGate)
1616
return &albResourceStack{
1717
httpr: httpr,
1818
commonStack: commonStack,

test/e2e/gateway/alb_test_helper.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package gateway
2+
3+
import (
4+
"context"
5+
corev1 "k8s.io/api/core/v1"
6+
elbv2gw "sigs.k8s.io/aws-load-balancer-controller/apis/gateway/v1beta1"
7+
"sigs.k8s.io/aws-load-balancer-controller/test/framework"
8+
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
9+
)
10+
11+
type ALBTestStack struct {
12+
albResourceStack *albResourceStack
13+
}
14+
15+
func (s *ALBTestStack) Deploy(ctx context.Context, f *framework.Framework, lbConfSpec elbv2gw.LoadBalancerConfigurationSpec, tgConfSpec elbv2gw.TargetGroupConfigurationSpec) error {
16+
dp := buildDeploymentSpec(f.Options.TestImageRegistry)
17+
svc := buildServiceSpec()
18+
gwc := buildGatewayClassSpec("gateway.k8s.aws/alb")
19+
gw := buildBasicGatewaySpec(gwc, gwv1.HTTPProtocolType)
20+
lbc := buildLoadBalancerConfig(lbConfSpec)
21+
tgc := buildTargetGroupConfig(tgConfSpec, svc)
22+
httpr := buildHTTPRoute()
23+
s.albResourceStack = newALBResourceStack(dp, svc, gwc, gw, lbc, tgc, httpr, "alb-gateway-e2e", false)
24+
25+
return s.albResourceStack.Deploy(ctx, f)
26+
}
27+
28+
func (s *ALBTestStack) ScaleDeployment(ctx context.Context, f *framework.Framework, numReplicas int32) error {
29+
return s.albResourceStack.ScaleDeployment(ctx, f, numReplicas)
30+
}
31+
32+
func (s *ALBTestStack) Cleanup(ctx context.Context, f *framework.Framework) {
33+
s.albResourceStack.Cleanup(ctx, f)
34+
}
35+
36+
func (s *ALBTestStack) GetLoadBalancerIngressHostName() string {
37+
return s.albResourceStack.GetLoadBalancerIngressHostname()
38+
}
39+
40+
func (s *ALBTestStack) GetWorkerNodes(ctx context.Context, f *framework.Framework) ([]corev1.Node, error) {
41+
allNodes := &corev1.NodeList{}
42+
err := f.K8sClient.List(ctx, allNodes)
43+
if err != nil {
44+
return nil, err
45+
}
46+
nodeList := []corev1.Node{}
47+
for _, node := range allNodes.Items {
48+
if _, notarget := node.Labels["node.kubernetes.io/exclude-from-external-load-balancers"]; !notarget {
49+
nodeList = append(nodeList, node)
50+
}
51+
}
52+
return nodeList, nil
53+
}

0 commit comments

Comments
 (0)