diff --git a/apis/v1alpha2/nginxproxy_types.go b/apis/v1alpha2/nginxproxy_types.go index 3a0a3ccc73..7c716824fa 100644 --- a/apis/v1alpha2/nginxproxy_types.go +++ b/apis/v1alpha2/nginxproxy_types.go @@ -517,6 +517,12 @@ type ServiceSpec struct { // +optional LoadBalancerIP *string `json:"loadBalancerIP,omitempty"` + // LoadBalancerClass is the class of the load balancer implementation this Service belongs to. + // Requires service type to be LoadBalancer. + // + // +optional + LoadBalancerClass *string `json:"loadBalancerClass,omitempty"` + // Annotations contain any Service-specific annotations. // // +optional diff --git a/apis/v1alpha2/zz_generated.deepcopy.go b/apis/v1alpha2/zz_generated.deepcopy.go index 54e5c760b2..60bf2cd9cd 100644 --- a/apis/v1alpha2/zz_generated.deepcopy.go +++ b/apis/v1alpha2/zz_generated.deepcopy.go @@ -530,6 +530,11 @@ func (in *ServiceSpec) DeepCopyInto(out *ServiceSpec) { *out = new(string) **out = **in } + if in.LoadBalancerClass != nil { + in, out := &in.LoadBalancerClass, &out.LoadBalancerClass + *out = new(string) + **out = **in + } if in.Annotations != nil { in, out := &in.Annotations, &out.Annotations *out = make(map[string]string, len(*in)) diff --git a/charts/nginx-gateway-fabric/values.yaml b/charts/nginx-gateway-fabric/values.yaml index bd2872e9ad..c41ea7bb9c 100644 --- a/charts/nginx-gateway-fabric/values.yaml +++ b/charts/nginx-gateway-fabric/values.yaml @@ -427,6 +427,10 @@ nginx: # -- The static IP address for the load balancer. Requires nginx.service.type set to LoadBalancer. # loadBalancerIP: "" + # -- LoadBalancerClass is the class of the load balancer implementation this Service belongs to. + # Requires nginx.service.type set to LoadBalancer. + # loadBalancerClass: "" + # -- The IP ranges (CIDR) that are allowed to access the load balancer. Requires nginx.service.type set to LoadBalancer. # loadBalancerSourceRanges: [] diff --git a/config/crd/bases/gateway.nginx.org_nginxproxies.yaml b/config/crd/bases/gateway.nginx.org_nginxproxies.yaml index b07a013fd8..0e28520896 100644 --- a/config/crd/bases/gateway.nginx.org_nginxproxies.yaml +++ b/config/crd/bases/gateway.nginx.org_nginxproxies.yaml @@ -3482,6 +3482,11 @@ spec: - Cluster - Local type: string + loadBalancerClass: + description: |- + LoadBalancerClass is the class of the load balancer implementation this Service belongs to. + Requires service type to be LoadBalancer. + type: string loadBalancerIP: description: LoadBalancerIP is a static IP address for the load balancer. Requires service type to be LoadBalancer. diff --git a/deploy/crds.yaml b/deploy/crds.yaml index c08c007d12..56cd27eacc 100644 --- a/deploy/crds.yaml +++ b/deploy/crds.yaml @@ -4067,6 +4067,11 @@ spec: - Cluster - Local type: string + loadBalancerClass: + description: |- + LoadBalancerClass is the class of the load balancer implementation this Service belongs to. + Requires service type to be LoadBalancer. + type: string loadBalancerIP: description: LoadBalancerIP is a static IP address for the load balancer. Requires service type to be LoadBalancer. diff --git a/internal/mode/static/provisioner/objects.go b/internal/mode/static/provisioner/objects.go index f925b9c133..93ee801fef 100644 --- a/internal/mode/static/provisioner/objects.go +++ b/internal/mode/static/provisioner/objects.go @@ -460,6 +460,9 @@ func buildNginxService( if serviceCfg.LoadBalancerIP != nil { svc.Spec.LoadBalancerIP = *serviceCfg.LoadBalancerIP } + if serviceCfg.LoadBalancerClass != nil { + svc.Spec.LoadBalancerClass = serviceCfg.LoadBalancerClass + } if serviceCfg.LoadBalancerSourceRanges != nil { svc.Spec.LoadBalancerSourceRanges = serviceCfg.LoadBalancerSourceRanges } diff --git a/internal/mode/static/provisioner/objects_test.go b/internal/mode/static/provisioner/objects_test.go index 0871f846c9..aa3a8dd747 100644 --- a/internal/mode/static/provisioner/objects_test.go +++ b/internal/mode/static/provisioner/objects_test.go @@ -253,6 +253,7 @@ func TestBuildNginxResourceObjects_NginxProxyConfig(t *testing.T) { ServiceType: helpers.GetPointer(ngfAPIv1alpha2.ServiceTypeNodePort), ExternalTrafficPolicy: helpers.GetPointer(ngfAPIv1alpha2.ExternalTrafficPolicyCluster), LoadBalancerIP: helpers.GetPointer("1.2.3.4"), + LoadBalancerClass: helpers.GetPointer("myLoadBalancerClass"), LoadBalancerSourceRanges: []string{"5.6.7.8"}, }, Deployment: &ngfAPIv1alpha2.DeploymentSpec{ @@ -299,6 +300,7 @@ func TestBuildNginxResourceObjects_NginxProxyConfig(t *testing.T) { g.Expect(svc.Spec.Type).To(Equal(corev1.ServiceTypeNodePort)) g.Expect(svc.Spec.ExternalTrafficPolicy).To(Equal(corev1.ServiceExternalTrafficPolicyTypeCluster)) g.Expect(svc.Spec.LoadBalancerIP).To(Equal("1.2.3.4")) + g.Expect(*svc.Spec.LoadBalancerClass).To(Equal("myLoadBalancerClass")) g.Expect(svc.Spec.LoadBalancerSourceRanges).To(Equal([]string{"5.6.7.8"})) depObj := objects[5]