Skip to content

Commit e528ab2

Browse files
committed
add nlb annotation support
Signed-off-by: Saurabh Choudhary <[email protected]>
1 parent 8def727 commit e528ab2

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

pkg/annotations/constants.go

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const (
6161
// NLB annotation suffixes
6262
// prefixes service.beta.kubernetes.io, service.kubernetes.io
6363
SvcLBSuffixSourceRanges = "load-balancer-source-ranges"
64+
SvcLBSuffixShieldAdvancedProtection = "aws-load-balancer-nlb-shield-advanced-protection"
6465
SvcLBSuffixLoadBalancerType = "aws-load-balancer-type"
6566
SvcLBSuffixTargetType = "aws-load-balancer-nlb-target-type"
6667
SvcLBSuffixLoadBalancerName = "aws-load-balancer-name"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package service
2+
3+
import (
4+
"context"
5+
6+
"github.com/pkg/errors"
7+
"sigs.k8s.io/aws-load-balancer-controller/pkg/annotations"
8+
shieldmodel "sigs.k8s.io/aws-load-balancer-controller/pkg/model/shield"
9+
)
10+
11+
func (t *defaultModelBuildTask) buildLoadBalancerAddOns(ctx context.Context) error {
12+
if _, err := t.buildShieldProtection(ctx); err != nil {
13+
return err
14+
}
15+
return nil
16+
}
17+
18+
func (t *defaultModelBuildTask) buildShieldProtection(_ context.Context) (*shieldmodel.Protection, error) {
19+
explicitEnableProtections := make(map[bool]struct{})
20+
rawEnableProtection := false
21+
exists, err := t.annotationParser.ParseBoolAnnotation(annotations.SvcLBSuffixShieldAdvancedProtection, &rawEnableProtection, t.service.Annotations)
22+
if err != nil {
23+
return nil, err
24+
}
25+
if exists {
26+
explicitEnableProtections[rawEnableProtection] = struct{}{}
27+
}
28+
if len(explicitEnableProtections) == 0 {
29+
return nil, nil
30+
}
31+
if len(explicitEnableProtections) > 1 {
32+
return nil, errors.New("conflicting enable shield advanced protection")
33+
}
34+
if _, enableProtection := explicitEnableProtections[true]; enableProtection {
35+
protection := shieldmodel.NewProtection(t.stack, resourceIDLoadBalancer, shieldmodel.ProtectionSpec{
36+
ResourceARN: t.loadBalancer.LoadBalancerARN(),
37+
})
38+
return protection, nil
39+
}
40+
return nil, nil
41+
}

pkg/service/model_builder.go

+3
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ func (t *defaultModelBuildTask) buildModel(ctx context.Context) error {
249249
if err != nil {
250250
return err
251251
}
252+
if err := t.buildLoadBalancerAddOns(ctx); err != nil {
253+
return err
254+
}
252255
return nil
253256
}
254257

0 commit comments

Comments
 (0)