Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 23f271b

Browse files
committedDec 10, 2024··
Add PrefixListsIDs field to IngressClassParams
1 parent 2b3f870 commit 23f271b

File tree

6 files changed

+160
-3
lines changed

6 files changed

+160
-3
lines changed
 

‎apis/elbv2/v1beta1/ingressclassparams_types.go

+3
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ type IngressClassParamsSpec struct {
156156
// MinimumLoadBalancerCapacity define the capacity reservation for LoadBalancers for all Ingress that belong to IngressClass with this IngressClassParams.
157157
// +optional
158158
MinimumLoadBalancerCapacity *MinimumLoadBalancerCapacity `json:"minimumLoadBalancerCapacity,omitempty"`
159+
160+
// PrefixListsIDs defines the security group prefix lists for all Ingresses that belong to IngressClass with this IngressClassParams.
161+
PrefixListsIDs []string `json:"PrefixListsIDs,omitempty"`
159162
}
160163

161164
// +kubebuilder:object:root=true

‎apis/elbv2/v1beta1/zz_generated.deepcopy.go

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ spec:
5555
spec:
5656
description: IngressClassParamsSpec defines the desired state of IngressClassParams
5757
properties:
58+
PrefixListsIDs:
59+
description: PrefixListsIDs defines the security group prefix lists
60+
for all Ingresses that belong to IngressClass with this IngressClassParams.
61+
items:
62+
type: string
63+
type: array
5864
certificateArn:
5965
description: CertificateArn specifies the ARN of the certificates
6066
for all Ingresses that belong to IngressClass with this IngressClassParams.

‎docs/guide/ingress/ingress_class.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,12 @@ They may specify `capacityUnits`. If the field is specified, LBC will ignore the
251251

252252
##### spec.minimumLoadBalancerCapacity.capacityUnits
253253

254-
If `capacityUnits` is specified, it must be to valid positive value greater than 0. If set to 0, the LBC will reset the capacity reservation for the load balancer.
254+
If `capacityUnits` is specified, it must be to valid positive value greater than 0. If set to 0, the LBC will reset the capacity reservation for the load balancer.
255+
#### spec.prefixListIDs
256+
257+
`prefixListIDs` is an optional setting.
258+
259+
Cluster administrators can use `prefixListIDs` field to specify the managed prefix lists that are allowed to access the load balancers that belong to this IngressClass. You can specify the list of prefix list IDs in the `spec.prefixListIDs` field.
260+
261+
1. If `prefixListIDs` is set, the prefix lists defined will be applied to the load balancer that belong to this IngressClass. If you specify invalid prefix list IDs, the controller will fail to reconcile ingresses belonging to the particular ingress class.
262+
2. If `prefixListIDs` un-specified, Ingresses with this IngressClass can continue to use `alb.ingress.kubernetes.io/security-group-prefix-lists` annotation to specify the load balancer prefix lists.

‎pkg/ingress/model_build_listener.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ type listenPortConfig struct {
126126
func (t *defaultModelBuildTask) computeIngressListenPortConfigByPort(ctx context.Context, ing *ClassifiedIngress) (map[int32]listenPortConfig, error) {
127127
explicitTLSCertARNs := t.computeIngressExplicitTLSCertARNs(ctx, ing)
128128
explicitSSLPolicy := t.computeIngressExplicitSSLPolicy(ctx, ing)
129-
var prefixListIDs []string
130-
t.annotationParser.ParseStringSliceAnnotation(annotations.IngressSuffixSecurityGroupPrefixLists, &prefixListIDs, ing.Ing.Annotations)
129+
prefixListIDs := t.computeIngressExplicitPrefixListIDs(ctx, ing)
131130
inboundCIDRv4s, inboundCIDRV6s, err := t.computeIngressExplicitInboundCIDRs(ctx, ing)
132131
if err != nil {
133132
return nil, err
@@ -278,6 +277,16 @@ func (t *defaultModelBuildTask) computeIngressExplicitSSLPolicy(_ context.Contex
278277
return &rawSSLPolicy
279278
}
280279

280+
func (t *defaultModelBuildTask) computeIngressExplicitPrefixListIDs(_ context.Context, ing *ClassifiedIngress) []string {
281+
if ing.IngClassConfig.IngClassParams != nil && len(ing.IngClassConfig.IngClassParams.Spec.PrefixListsIDs) != 0 {
282+
return ing.IngClassConfig.IngClassParams.Spec.PrefixListsIDs
283+
}
284+
var prefixListIDs []string
285+
t.annotationParser.ParseStringSliceAnnotation(annotations.IngressSuffixSecurityGroupPrefixLists, &prefixListIDs, ing.Ing.Annotations)
286+
287+
return prefixListIDs
288+
}
289+
281290
type MutualAuthenticationConfig struct {
282291
Port int32 `json:"port"`
283292
Mode string `json:"mode"`

‎pkg/ingress/model_builder_test.go

+126
Original file line numberDiff line numberDiff line change
@@ -3396,6 +3396,132 @@ func Test_defaultModelBuilder_Build(t *testing.T) {
33963396
}
33973397
}
33983398
}
3399+
}`,
3400+
},
3401+
{
3402+
name: "Ingress - ingress with managed prefix list in IngressClassParam",
3403+
env: env{
3404+
svcs: []*corev1.Service{ns_1_svc_1, ns_1_svc_2, ns_1_svc_3},
3405+
},
3406+
fields: fields{
3407+
resolveViaDiscoveryCalls: []resolveViaDiscoveryCall{resolveViaDiscoveryCallForInternalLB},
3408+
listLoadBalancersCalls: []listLoadBalancersCall{listLoadBalancerCallForEmptyLB},
3409+
enableBackendSG: true,
3410+
},
3411+
args: args{
3412+
ingGroup: Group{
3413+
ID: GroupID{Namespace: "ns-1", Name: "ing-1"},
3414+
Members: []ClassifiedIngress{
3415+
{
3416+
IngClassConfig: ClassConfiguration{
3417+
IngClassParams: &v1beta1.IngressClassParams{
3418+
Spec: v1beta1.IngressClassParamsSpec{
3419+
PrefixListsIDs: []string{
3420+
"pl-11111111",
3421+
"pl-22222222",
3422+
},
3423+
},
3424+
},
3425+
},
3426+
Ing: &networking.Ingress{ObjectMeta: metav1.ObjectMeta{
3427+
Namespace: "ns-1",
3428+
Name: "ing-1",
3429+
Annotations: map[string]string{
3430+
"alb.ingress.kubernetes.io/security-group-prefix-lists": "pl-00000000",
3431+
},
3432+
},
3433+
Spec: networking.IngressSpec{
3434+
Rules: []networking.IngressRule{
3435+
{
3436+
Host: "app-1.example.com",
3437+
IngressRuleValue: networking.IngressRuleValue{
3438+
HTTP: &networking.HTTPIngressRuleValue{
3439+
Paths: []networking.HTTPIngressPath{
3440+
{
3441+
Path: "/svc-1",
3442+
Backend: networking.IngressBackend{
3443+
Service: &networking.IngressServiceBackend{
3444+
Name: ns_1_svc_1.Name,
3445+
Port: networking.ServiceBackendPort{
3446+
Name: "http",
3447+
},
3448+
},
3449+
},
3450+
},
3451+
{
3452+
Path: "/svc-2",
3453+
Backend: networking.IngressBackend{
3454+
Service: &networking.IngressServiceBackend{
3455+
Name: ns_1_svc_2.Name,
3456+
Port: networking.ServiceBackendPort{
3457+
Name: "http",
3458+
},
3459+
},
3460+
},
3461+
},
3462+
},
3463+
},
3464+
},
3465+
},
3466+
{
3467+
Host: "app-2.example.com",
3468+
IngressRuleValue: networking.IngressRuleValue{
3469+
HTTP: &networking.HTTPIngressRuleValue{
3470+
Paths: []networking.HTTPIngressPath{
3471+
{
3472+
Path: "/svc-3",
3473+
Backend: networking.IngressBackend{
3474+
Service: &networking.IngressServiceBackend{
3475+
Name: ns_1_svc_3.Name,
3476+
Port: networking.ServiceBackendPort{
3477+
Name: "https",
3478+
},
3479+
},
3480+
},
3481+
},
3482+
},
3483+
},
3484+
},
3485+
},
3486+
},
3487+
},
3488+
},
3489+
},
3490+
},
3491+
},
3492+
},
3493+
wantStackPatch: `
3494+
{
3495+
"resources": {
3496+
"AWS::EC2::SecurityGroup": {
3497+
"ManagedLBSecurityGroup": {
3498+
"spec": {
3499+
"ingress": [
3500+
{
3501+
"fromPort": 80,
3502+
"ipProtocol": "tcp",
3503+
"prefixLists": [
3504+
{
3505+
"listID": "pl-11111111"
3506+
}
3507+
],
3508+
"toPort": 80
3509+
},
3510+
{
3511+
"fromPort": 80,
3512+
"ipProtocol": "tcp",
3513+
"prefixLists": [
3514+
{
3515+
"listID": "pl-22222222"
3516+
}
3517+
],
3518+
"toPort": 80
3519+
}
3520+
]
3521+
}
3522+
}
3523+
}
3524+
}
33993525
}`,
34003526
},
34013527
{

0 commit comments

Comments
 (0)
Please sign in to comment.