Skip to content

Commit a1131f5

Browse files
committed
test/ccm: Add support for verifying NLB health check configuration
Extend the CCM load balancer test to verify health check configuration for both Classic Load Balancers (CLB) and Network Load Balancers (NLB). IPv6 dual-stack clusters use NLB, while single-stack/IPv4 primary use CLB. The test now checks that health check port and path are correctly configured to 10256/healthz for both load balancer types by querying target group configuration for NLB and load balancer description for CLB.
1 parent c503cfb commit a1131f5

File tree

2 files changed

+63
-9
lines changed

2 files changed

+63
-9
lines changed

test/extended/cloud_controller_manager/ccm.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,18 @@ spec:
152152
region := exutil.GetClusterRegion(oc)
153153
sess := exutil.InitAwsSession(region)
154154
elbClient := exutil.NewELBClient(sess)
155-
healthCheck, err := elbClient.GetLBHealthCheckPortPath(lbName)
156-
o.Expect(err).NotTo(o.HaveOccurred(), "unable to get health check port and path")
155+
156+
expectedHealthCheck := fmt.Sprintf("HTTP:%s%s", healthCheckPort, healthCheckPath)
157+
var healthCheck string
158+
if isIPv6Primary {
159+
healthCheck, err = elbClient.GetNLBHealthCheckPortPath(lbName)
160+
o.Expect(err).NotTo(o.HaveOccurred(), "unable to get NLB health check port and path")
161+
} else {
162+
healthCheck, err = elbClient.GetCLBHealthCheckPortPath(lbName)
163+
o.Expect(err).NotTo(o.HaveOccurred(), "unable to get CLB health check port and path")
164+
}
157165
e2e.Logf("Health check port and path: %v", healthCheck)
158-
o.Expect(healthCheck).To(o.Equal(fmt.Sprintf("HTTP:%s%s", healthCheckPort, healthCheckPath)))
166+
o.Expect(healthCheck).To(o.Equal(expectedHealthCheck))
159167
})
160168
})
161169

test/extended/util/aws_client.go

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package util
22

33
import (
44
"encoding/base64"
5+
"fmt"
56
"os"
67

78
"github.com/aws/aws-sdk-go/aws"
89
"github.com/aws/aws-sdk-go/aws/session"
910
"github.com/aws/aws-sdk-go/service/elb"
11+
"github.com/aws/aws-sdk-go/service/elbv2"
1012
g "github.com/onsi/ginkgo/v2"
1113
o "github.com/onsi/gomega"
1214
"github.com/tidwall/gjson"
@@ -46,18 +48,20 @@ func InitAwsSession(region string) *session.Session {
4648
}
4749

4850
type ELBClient struct {
49-
svc *elb.ELB
51+
svc *elb.ELB
52+
svcV2 *elbv2.ELBV2
5053
}
5154

5255
// NewELBClient creates an ECRClient
5356
func NewELBClient(sess *session.Session) *ELBClient {
5457
return &ELBClient{
55-
svc: elb.New(sess),
58+
svc: elb.New(sess),
59+
svcV2: elbv2.New(sess),
5660
}
5761
}
5862

59-
// GetLBHealthCheckPortPath get load balance health check port and path
60-
func (elbClient *ELBClient) GetLBHealthCheckPortPath(lbName string) (string, error) {
63+
// GetLBHealthCheckPortPath get load balance health check port and path for Classic Load Balancer
64+
func (elbClient *ELBClient) GetCLBHealthCheckPortPath(lbName string) (string, error) {
6165
input := &elb.DescribeLoadBalancersInput{
6266
LoadBalancerNames: []*string{
6367
aws.String(lbName),
@@ -66,12 +70,12 @@ func (elbClient *ELBClient) GetLBHealthCheckPortPath(lbName string) (string, err
6670

6771
result, err := elbClient.svc.DescribeLoadBalancers(input)
6872
if err != nil {
69-
e2e.Logf("Failed to describe load balancer: %v", err)
73+
e2e.Logf("Failed to describe classic load balancer: %v", err)
7074
return "", err
7175
}
7276

7377
if len(result.LoadBalancerDescriptions) == 0 {
74-
e2e.Logf("Failed to get load balancers: %v", err)
78+
e2e.Logf("Failed to get classic load balancers: %v", err)
7579
}
7680

7781
healthCheck := result.LoadBalancerDescriptions[0].HealthCheck
@@ -80,3 +84,45 @@ func (elbClient *ELBClient) GetLBHealthCheckPortPath(lbName string) (string, err
8084
}
8185
return *healthCheck.Target, nil
8286
}
87+
88+
// GetNLBHealthCheckPortPath get load balance health check port and path for Network/Application Load Balancer
89+
func (elbClient *ELBClient) GetNLBHealthCheckPortPath(lbName string) (string, error) {
90+
// Describe the load balancer
91+
input := &elbv2.DescribeLoadBalancersInput{
92+
Names: []*string{aws.String(lbName)},
93+
}
94+
result, err := elbClient.svcV2.DescribeLoadBalancers(input)
95+
if err != nil {
96+
e2e.Logf("Failed to describe NLB: %v", err)
97+
return "", err
98+
}
99+
100+
if len(result.LoadBalancers) == 0 {
101+
e2e.Logf("No NLB found with name: %s", lbName)
102+
return "", nil
103+
}
104+
105+
// Get target groups for this load balancer
106+
tgInput := &elbv2.DescribeTargetGroupsInput{
107+
LoadBalancerArn: result.LoadBalancers[0].LoadBalancerArn,
108+
}
109+
tgResult, err := elbClient.svcV2.DescribeTargetGroups(tgInput)
110+
if err != nil {
111+
e2e.Logf("Failed to describe target groups: %v", err)
112+
return "", err
113+
}
114+
115+
if len(tgResult.TargetGroups) == 0 {
116+
e2e.Logf("No target groups found for NLB: %s", lbName)
117+
return "", nil
118+
}
119+
120+
// Get health check configuration from the first target group
121+
tg := tgResult.TargetGroups[0]
122+
protocol := aws.StringValue(tg.HealthCheckProtocol)
123+
path := aws.StringValue(tg.HealthCheckPath)
124+
port := aws.StringValue(tg.HealthCheckPort)
125+
126+
// Format: "HTTP:10256/healthz"
127+
return fmt.Sprintf("%s:%s%s", protocol, port, path), nil
128+
}

0 commit comments

Comments
 (0)