Skip to content

Commit d0dce25

Browse files
authored
CP/DP Split: Add ability to set loadBalancerClass for load balancer Service (#3319)
Add ability to set loadBalancerClass for load balancer Service Problem: We would like the ability to specify the loadBalanacerClass field on a load balancer service. Solution: Add ability to set loadBalancerClass for load balancer Service. Testing: Manually tested that deploying NGF with the nginx.service.loadBalancerClass Helm flag would correctly set the field. Also tested that modifying the NginxProxy resource would set the loadBalancerClass when the service was re-created (the field can only be set upon creation).
1 parent 5084be8 commit d0dce25

File tree

7 files changed

+30
-0
lines changed

7 files changed

+30
-0
lines changed

apis/v1alpha2/nginxproxy_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,12 @@ type ServiceSpec struct {
517517
// +optional
518518
LoadBalancerIP *string `json:"loadBalancerIP,omitempty"`
519519

520+
// LoadBalancerClass is the class of the load balancer implementation this Service belongs to.
521+
// Requires service type to be LoadBalancer.
522+
//
523+
// +optional
524+
LoadBalancerClass *string `json:"loadBalancerClass,omitempty"`
525+
520526
// Annotations contain any Service-specific annotations.
521527
//
522528
// +optional

apis/v1alpha2/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.

charts/nginx-gateway-fabric/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,10 @@ nginx:
427427
# -- The static IP address for the load balancer. Requires nginx.service.type set to LoadBalancer.
428428
# loadBalancerIP: ""
429429

430+
# -- LoadBalancerClass is the class of the load balancer implementation this Service belongs to.
431+
# Requires nginx.service.type set to LoadBalancer.
432+
# loadBalancerClass: ""
433+
430434
# -- The IP ranges (CIDR) that are allowed to access the load balancer. Requires nginx.service.type set to LoadBalancer.
431435
# loadBalancerSourceRanges: []
432436

config/crd/bases/gateway.nginx.org_nginxproxies.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3482,6 +3482,11 @@ spec:
34823482
- Cluster
34833483
- Local
34843484
type: string
3485+
loadBalancerClass:
3486+
description: |-
3487+
LoadBalancerClass is the class of the load balancer implementation this Service belongs to.
3488+
Requires service type to be LoadBalancer.
3489+
type: string
34853490
loadBalancerIP:
34863491
description: LoadBalancerIP is a static IP address for the
34873492
load balancer. Requires service type to be LoadBalancer.

deploy/crds.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4067,6 +4067,11 @@ spec:
40674067
- Cluster
40684068
- Local
40694069
type: string
4070+
loadBalancerClass:
4071+
description: |-
4072+
LoadBalancerClass is the class of the load balancer implementation this Service belongs to.
4073+
Requires service type to be LoadBalancer.
4074+
type: string
40704075
loadBalancerIP:
40714076
description: LoadBalancerIP is a static IP address for the
40724077
load balancer. Requires service type to be LoadBalancer.

internal/mode/static/provisioner/objects.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,9 @@ func buildNginxService(
460460
if serviceCfg.LoadBalancerIP != nil {
461461
svc.Spec.LoadBalancerIP = *serviceCfg.LoadBalancerIP
462462
}
463+
if serviceCfg.LoadBalancerClass != nil {
464+
svc.Spec.LoadBalancerClass = serviceCfg.LoadBalancerClass
465+
}
463466
if serviceCfg.LoadBalancerSourceRanges != nil {
464467
svc.Spec.LoadBalancerSourceRanges = serviceCfg.LoadBalancerSourceRanges
465468
}

internal/mode/static/provisioner/objects_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ func TestBuildNginxResourceObjects_NginxProxyConfig(t *testing.T) {
253253
ServiceType: helpers.GetPointer(ngfAPIv1alpha2.ServiceTypeNodePort),
254254
ExternalTrafficPolicy: helpers.GetPointer(ngfAPIv1alpha2.ExternalTrafficPolicyCluster),
255255
LoadBalancerIP: helpers.GetPointer("1.2.3.4"),
256+
LoadBalancerClass: helpers.GetPointer("myLoadBalancerClass"),
256257
LoadBalancerSourceRanges: []string{"5.6.7.8"},
257258
},
258259
Deployment: &ngfAPIv1alpha2.DeploymentSpec{
@@ -299,6 +300,7 @@ func TestBuildNginxResourceObjects_NginxProxyConfig(t *testing.T) {
299300
g.Expect(svc.Spec.Type).To(Equal(corev1.ServiceTypeNodePort))
300301
g.Expect(svc.Spec.ExternalTrafficPolicy).To(Equal(corev1.ServiceExternalTrafficPolicyTypeCluster))
301302
g.Expect(svc.Spec.LoadBalancerIP).To(Equal("1.2.3.4"))
303+
g.Expect(*svc.Spec.LoadBalancerClass).To(Equal("myLoadBalancerClass"))
302304
g.Expect(svc.Spec.LoadBalancerSourceRanges).To(Equal([]string{"5.6.7.8"}))
303305

304306
depObj := objects[5]

0 commit comments

Comments
 (0)