Skip to content

Commit 2d87f07

Browse files
authored
Merge pull request #3124 from Ankitasw/elb-health-check
Add support for custom protocol for ELB health checks
2 parents db14d13 + 512922d commit 2d87f07

15 files changed

+141
-21
lines changed

api/v1alpha3/awscluster_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func (r *AWSCluster) ConvertTo(dstRaw conversion.Hub) error {
6161
// Assumes restored and dst are non-nil.
6262
func restoreControlPlaneLoadBalancer(restored, dst *infrav1.AWSLoadBalancerSpec) {
6363
dst.Name = restored.Name
64+
dst.HealthCheckProtocol = restored.HealthCheckProtocol
6465
}
6566

6667
// ConvertFrom converts the v1beta1 AWSCluster receiver to a v1alpha3 AWSCluster.

api/v1alpha3/zz_generated.conversion.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha4/awscluster_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error {
5252
// Assumes restored and dst are non-nil.
5353
func restoreControlPlaneLoadBalancer(restored, dst *infrav1.AWSLoadBalancerSpec) {
5454
dst.Name = restored.Name
55+
dst.HealthCheckProtocol = restored.HealthCheckProtocol
5556
}
5657

5758
// ConvertFrom converts the v1beta1 AWSCluster receiver to a v1alpha4 AWSCluster.

api/v1alpha4/zz_generated.conversion.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta1/awscluster_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ type AWSLoadBalancerSpec struct {
177177
// +optional
178178
Subnets []string `json:"subnets,omitempty"`
179179

180+
// HealthCheckProtocol sets the protocol type for classic ELB health check target
181+
// default value is ClassicELBProtocolSSL
182+
// +optional
183+
HealthCheckProtocol *ClassicELBProtocol `json:"healthCheckProtocol,omitempty"`
184+
180185
// AdditionalSecurityGroups sets the security groups used by the load balancer. Expected to be security group IDs
181186
// This is optional - if not provided new security groups will be created for the load balancer
182187
// +optional

api/v1beta1/awscluster_webhook.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ func (r *AWSCluster) ValidateUpdate(old runtime.Object) error {
115115
r.Spec.ControlPlaneLoadBalancer.Name, "field is immutable"),
116116
)
117117
}
118+
119+
// Block the update for HealthCheckProtocol :
120+
// - if it was not set in old spec but added in new spec
121+
// - if it was set in old spec but changed in new spec
122+
if !reflect.DeepEqual(newLoadBalancer.HealthCheckProtocol, existingLoadBalancer.HealthCheckProtocol) {
123+
allErrs = append(allErrs,
124+
field.Invalid(field.NewPath("spec", "controlPlaneLoadBalancer", "healthCheckProtocol"),
125+
newLoadBalancer.HealthCheckProtocol, "field is immutable once set"),
126+
)
127+
}
118128
}
119129

120130
if !reflect.DeepEqual(oldC.Spec.ControlPlaneEndpoint, clusterv1.APIEndpoint{}) &&

api/v1beta1/awscluster_webhook_test.go

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,16 @@ func TestAWSCluster_ValidateCreate(t *testing.T) {
4646
name string
4747
cluster *AWSCluster
4848
wantErr bool
49-
expect func(t *testing.T, res *AWSLoadBalancerSpec)
49+
expect func(g *WithT, res *AWSLoadBalancerSpec)
5050
}{
5151
// The SSHKeyName tests were moved to sshkeyname_test.go
5252
{
5353
name: "Default nil scheme to `internet-facing`",
5454
cluster: &AWSCluster{
5555
Spec: AWSClusterSpec{},
5656
},
57-
expect: func(t *testing.T, res *AWSLoadBalancerSpec) {
58-
t.Helper()
59-
60-
if res.Scheme.String() != ClassicELBSchemeInternetFacing.String() {
61-
t.Error("Expected internet-facing defaulting for nil loadbalancer schemes")
62-
}
57+
expect: func(g *WithT, res *AWSLoadBalancerSpec) {
58+
g.Expect(res.Scheme.String(), ClassicELBSchemeInternetFacing.String())
6359
},
6460
wantErr: false,
6561
},
@@ -70,12 +66,8 @@ func TestAWSCluster_ValidateCreate(t *testing.T) {
7066
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{Scheme: &ClassicELBSchemeIncorrectInternetFacing},
7167
},
7268
},
73-
expect: func(t *testing.T, res *AWSLoadBalancerSpec) {
74-
t.Helper()
75-
76-
if res.Scheme.String() != ClassicELBSchemeInternetFacing.String() {
77-
t.Error("Expected internet-facing defaulting for supported incorrect scheme: Internet-facing")
78-
}
69+
expect: func(g *WithT, res *AWSLoadBalancerSpec) {
70+
g.Expect(res.Scheme.String(), ClassicELBSchemeInternetFacing.String())
7971
},
8072
wantErr: false,
8173
},
@@ -131,7 +123,7 @@ func TestAWSCluster_ValidateCreate(t *testing.T) {
131123
return err == nil
132124
}, 10*time.Second).Should(Equal(true))
133125

134-
tt.expect(t, c.Spec.ControlPlaneLoadBalancer)
126+
tt.expect(g, c.Spec.ControlPlaneLoadBalancer)
135127
})
136128
}
137129
}
@@ -368,6 +360,56 @@ func TestAWSCluster_ValidateUpdate(t *testing.T) {
368360
},
369361
wantErr: true,
370362
},
363+
{
364+
name: "Should fail if controlPlaneLoadBalancer healthcheckprotocol is updated",
365+
oldCluster: &AWSCluster{
366+
Spec: AWSClusterSpec{
367+
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{
368+
HealthCheckProtocol: &ClassicELBProtocolTCP,
369+
},
370+
},
371+
},
372+
newCluster: &AWSCluster{
373+
Spec: AWSClusterSpec{
374+
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{
375+
HealthCheckProtocol: &ClassicELBProtocolSSL,
376+
},
377+
},
378+
},
379+
wantErr: true,
380+
},
381+
{
382+
name: "Should pass if controlPlaneLoadBalancer healthcheckprotocol is same after update",
383+
oldCluster: &AWSCluster{
384+
Spec: AWSClusterSpec{
385+
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{
386+
HealthCheckProtocol: &ClassicELBProtocolTCP,
387+
},
388+
},
389+
},
390+
newCluster: &AWSCluster{
391+
Spec: AWSClusterSpec{
392+
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{
393+
HealthCheckProtocol: &ClassicELBProtocolTCP,
394+
},
395+
},
396+
},
397+
wantErr: false,
398+
},
399+
{
400+
name: "Should fail if controlPlaneLoadBalancer healthcheckprotocol is changed to non-default if it was not set before update",
401+
oldCluster: &AWSCluster{
402+
Spec: AWSClusterSpec{},
403+
},
404+
newCluster: &AWSCluster{
405+
Spec: AWSClusterSpec{
406+
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{
407+
HealthCheckProtocol: &ClassicELBProtocolTCP,
408+
},
409+
},
410+
},
411+
wantErr: true,
412+
},
371413
}
372414
for _, tt := range tests {
373415
t.Run(tt.name, func(t *testing.T) {

api/v1beta1/network_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ func (e ClassicELBScheme) String() string {
5454
// ClassicELBProtocol defines listener protocols for a classic load balancer.
5555
type ClassicELBProtocol string
5656

57+
func (e ClassicELBProtocol) String() string {
58+
return string(e)
59+
}
60+
5761
var (
5862
// ClassicELBProtocolTCP defines the ELB API string representing the TCP protocol.
5963
ClassicELBProtocolTCP = ClassicELBProtocol("TCP")

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_awsclusters.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,10 @@ spec:
16511651
registered instances in its Availability Zone only. \n Defaults
16521652
to false."
16531653
type: boolean
1654+
healthCheckProtocol:
1655+
description: HealthCheckProtocol sets the protocol type for classic
1656+
ELB health check target default value is ClassicELBProtocolSSL
1657+
type: string
16541658
name:
16551659
description: Name sets the name of the classic ELB load balancer.
16561660
As per AWS, the name must be unique within your set of load

0 commit comments

Comments
 (0)