Skip to content

Commit 4844275

Browse files
authored
feature: add load balancer name to IngressClassParams (#4290)
* chore: fix prefixlistsids typo in readme * feat: add loadBalancerName to IngressClassParams * feat: add loadBalancerName to IngressClassParams
1 parent 5199c55 commit 4844275

File tree

6 files changed

+63
-0
lines changed

6 files changed

+63
-0
lines changed

apis/elbv2/v1beta1/ingressclassparams_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ type IPAMConfiguration struct {
117117
// IngressClassParamsSpec defines the desired state of IngressClassParams
118118
// +kubebuilder:validation:XValidation:rule="!(has(self.prefixListsIDs) && has(self.PrefixListsIDs))", message="cannot specify both 'prefixListsIDs' and 'PrefixListsIDs' fields"
119119
type IngressClassParamsSpec struct {
120+
// LoadBalancerName defines the name of the load balancer that will be created with this IngressClassParams.
121+
// +optional
122+
LoadBalancerName string `json:"loadBalancerName,omitempty"`
123+
120124
// CertificateArn specifies the ARN of the certificates for all Ingresses that belong to IngressClass with this IngressClassParams.
121125
// +optional
122126
CertificateArn []string `json:"certificateArn,omitempty"`

config/crd/bases/elbv2.k8s.aws_ingressclassparams.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ spec:
149149
- value
150150
type: object
151151
type: array
152+
loadBalancerName:
153+
description: LoadBalancerName defines the name of the load balancer
154+
that will be created with this IngressClassParams.
155+
type: string
152156
minimumLoadBalancerCapacity:
153157
description: MinimumLoadBalancerCapacity define the capacity reservation
154158
for LoadBalancers for all Ingress that belong to IngressClass with

docs/guide/ingress/ingress_class.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ You can use IngressClassParams to enforce settings for a set of Ingresses.
7676
- key: org
7777
value: my-org
7878
```
79+
- with loadBalancerName
80+
```
81+
apiVersion: elbv2.k8s.aws/v1beta1
82+
kind: IngressClassParams
83+
metadata:
84+
name: awesome-class
85+
spec:
86+
loadBalancerName: name-1
87+
```
7988
- with namespaceSelector
8089
```
8190
apiVersion: elbv2.k8s.aws/v1beta1
@@ -214,6 +223,14 @@ You can use IngressClassParams to enforce settings for a set of Ingresses.
214223

215224
### IngressClassParams specification
216225

226+
#### spec.loadBalancerName
227+
`loadBalancerName` is an optional setting.
228+
229+
Cluster administrators can use the `loadBalancerName` field to specify name of the load balancer that will be provisioned by the controller.
230+
231+
1. If `loadBalancerName` is set, one load balancer per `IngressClass` will be provisioned. LBC will ignore the `alb.ingress.kubernetes.io/load-balancer-name` annotation.
232+
2. If `loadBalancerName` is not set, Ingresses with this IngressClass can continue to use `alb.ingress.kubernetes.io/load-balancer-name annotation` to specify name of the load balancer.
233+
217234
#### spec.namespaceSelector
218235
`namespaceSelector` is an optional setting that follows general Kubernetes
219236
[label selector](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors)

helm/aws-load-balancer-controller/crds/crds.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ spec:
148148
- value
149149
type: object
150150
type: array
151+
loadBalancerName:
152+
description: LoadBalancerName defines the name of the load balancer
153+
that will be created with this IngressClassParams.
154+
type: string
151155
minimumLoadBalancerCapacity:
152156
description: MinimumLoadBalancerCapacity define the capacity reservation
153157
for LoadBalancers for all Ingress that belong to IngressClass with

pkg/ingress/model_build_load_balancer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ var invalidLoadBalancerNamePattern = regexp.MustCompile("[[:^alnum:]]")
9999
func (t *defaultModelBuildTask) buildLoadBalancerName(_ context.Context, scheme elbv2model.LoadBalancerScheme) (string, error) {
100100
explicitNames := sets.String{}
101101
for _, member := range t.ingGroup.Members {
102+
if member.IngClassConfig.IngClassParams != nil && member.IngClassConfig.IngClassParams.Spec.LoadBalancerName != "" {
103+
loadBalancerName := member.IngClassConfig.IngClassParams.Spec.LoadBalancerName
104+
explicitNames.Insert(loadBalancerName)
105+
continue
106+
}
102107
rawName := ""
103108
if exists := t.annotationParser.ParseStringAnnotation(annotations.IngressSuffixLoadBalancerName, &rawName, member.Ing.Annotations); !exists {
104109
continue

pkg/ingress/model_build_load_balancer_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,35 @@ func Test_defaultModelBuildTask_buildLoadBalancerName(t *testing.T) {
573573
},
574574
want: "foo",
575575
},
576+
{
577+
name: "name IngressClassParams",
578+
fields: fields{
579+
ingGroup: Group{
580+
ID: GroupID{Namespace: "awesome-ns", Name: "ing-1"},
581+
Members: []ClassifiedIngress{
582+
{
583+
Ing: &networking.Ingress{
584+
ObjectMeta: metav1.ObjectMeta{
585+
Namespace: "awesome-ns",
586+
Name: "ing-1",
587+
Annotations: map[string]string{
588+
"alb.ingress.kubernetes.io/load-balancer-name": "name-2",
589+
},
590+
},
591+
},
592+
IngClassConfig: ClassConfiguration{
593+
IngClassParams: &v1beta1.IngressClassParams{
594+
Spec: v1beta1.IngressClassParamsSpec{
595+
LoadBalancerName: "name-1",
596+
},
597+
},
598+
},
599+
},
600+
},
601+
},
602+
},
603+
want: "name-1",
604+
},
576605
{
577606
name: "trim name annotation",
578607
fields: fields{

0 commit comments

Comments
 (0)