Skip to content

Commit b81ab69

Browse files
Merge branch 'kubernetes-sigs:main' into main
2 parents abd690d + e1d32f4 commit b81ab69

24 files changed

+2671
-374
lines changed

.go-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.22.3
1+
1.22.5

Pipfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ name = "pypi"
66
[packages]
77

88
[dev-packages]
9-
mkdocs = "==1.1.2"
10-
mkdocs-material = "==7.1.5"
11-
mike = "==1.0.0"
9+
mkdocs = "==1.6.0"
10+
mkdocs-material = "==9.5.31"
11+
mike = "==2.1.2"
1212

1313
[requires]
14-
python_version = "3.9"
14+
python_version = "3.12"

Pipfile.lock

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

docs/guide/ingress/annotations.md

+33-15
Original file line numberDiff line numberDiff line change
@@ -907,35 +907,53 @@ In addition, you can use annotations to specify additional tags
907907

908908
## Addons
909909

910-
!!!note
911-
If waf-acl-arn is specified via the ingress annotations, the controller will make sure the waf-acl is associated to the provisioned ALB with the ingress.
912-
If there is not such annotation, the controller will make sure no waf-acl is associated, so it may remove the existing waf-acl on the ALB provisioned.
913-
If users do not want the controller to manage the waf-acl on the ALBs, they can disable the feature by setting controller command line flags `--enable-waf=false` or `--enable-wafv2=false`
914-
915-
- <a name="waf-acl-id">`alb.ingress.kubernetes.io/waf-acl-id`</a> specifies the identifier for the Amazon WAF web ACL.
910+
- <a name="waf-acl-id">`alb.ingress.kubernetes.io/waf-acl-id`</a> specifies the identifier for the Amazon WAF Classic web ACL.
916911

917912
!!!warning ""
918-
Only Regional WAF is supported.
913+
Only Regional WAF Classic is supported.
914+
915+
!!!note ""
916+
When this annotation is absent or empty, the controller will keep LoadBalancer WAF Classic settings unchanged.
917+
To disable WAF Classic, explicitly set the annotation value to 'none'.
919918

920919
!!!example
921-
```alb.ingress.kubernetes.io/waf-acl-id: 499e8b99-6671-4614-a86d-adb1810b7fbe
922-
```
920+
- enable WAF Classic
921+
```alb.ingress.kubernetes.io/waf-acl-id: 499e8b99-6671-4614-a86d-adb1810b7fbe
922+
```
923+
- disable WAF Classic
924+
```alb.ingress.kubernetes.io/waf-acl-id: none
925+
```
923926

924927
- <a name="wafv2-acl-arn">`alb.ingress.kubernetes.io/wafv2-acl-arn`</a> specifies ARN for the Amazon WAFv2 web ACL.
925928

926929
!!!warning ""
927930
Only Regional WAFv2 is supported.
928931

932+
!!!note ""
933+
When this annotation is absent or empty, the controller will keep LoadBalancer WAFv2 settings unchanged.
934+
To disable WAFv2, explicitly set the annotation value to 'none'.
935+
929936
!!!tip ""
930937
To get the WAFv2 Web ACL ARN from the Console, click the gear icon in the upper right and enable the ARN column.
931938

932939
!!!example
933-
```alb.ingress.kubernetes.io/wafv2-acl-arn: arn:aws:wafv2:us-west-2:xxxxx:regional/webacl/xxxxxxx/3ab78708-85b0-49d3-b4e1-7a9615a6613b
934-
```
935-
940+
- enable WAFv2
941+
```alb.ingress.kubernetes.io/wafv2-acl-arn: arn:aws:wafv2:us-west-2:xxxxx:regional/webacl/xxxxxxx/3ab78708-85b0-49d3-b4e1-7a9615a6613b
942+
```
943+
- disable WAFV2
944+
```alb.ingress.kubernetes.io/wafv2-acl-arn: none
945+
```
946+
936947
- <a name="shield-advanced-protection">`alb.ingress.kubernetes.io/shield-advanced-protection`</a> turns on / off the AWS Shield Advanced protection for the load balancer.
937948

938-
!!!example
939-
```alb.ingress.kubernetes.io/shield-advanced-protection: 'true'
940-
```
949+
!!!note ""
950+
When this annotation is absent, the controller will keep LoadBalancer shield protection settings unchanged.
951+
To disable shield protection, explicitly set the annotation value to 'false'.
941952

953+
!!!example
954+
- enable shield protection
955+
```alb.ingress.kubernetes.io/shield-advanced-protection: 'true'
956+
```
957+
- disable shield protection
958+
```alb.ingress.kubernetes.io/shield-advanced-protection: 'false'
959+
```

helm/aws-load-balancer-controller/templates/deployment.yaml

+5-4
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,14 @@ spec:
170170
{{- if .Values.loadBalancerClass }}
171171
- --load-balancer-class={{ .Values.loadBalancerClass }}
172172
{{- end }}
173-
{{- if or .Values.env .Values.envSecretName .Values.envFrom }}
173+
{{- if or .Values.env .Values.envSecretName }}
174174
env:
175175
{{- if .Values.env}}
176176
{{- range $key, $value := .Values.env }}
177177
- name: {{ $key }}
178178
value: "{{ $value }}"
179179
{{- end }}
180180
{{- end }}
181-
{{- if .Values.envFrom }}
182-
{{ .Values.envFrom | toYaml | nindent 8 }}
183-
{{- end }}
184181
{{- if .Values.envSecretName }}
185182
- name: AWS_ACCESS_KEY_ID
186183
valueFrom:
@@ -196,6 +193,10 @@ spec:
196193
optional: true
197194
{{- end }}
198195
{{- end }}
196+
{{- if .Values.envFrom }}
197+
envFrom:
198+
{{- toYaml .Values.envFrom | nindent 10 }}
199+
{{- end }}
199200
securityContext:
200201
{{- toYaml .Values.securityContext | nindent 10 }}
201202
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,9 @@ env:
282282
# envSecretName: aws-secret
283283

284284
# Use envFrom to set environment variables from a Secret or ConfigMap
285-
envFrom:
286-
# valueFrom:
287-
# - secretKeyRef:
288-
# name: aws-load-balancer-controller
285+
# envFrom:
286+
# - secretRef:
287+
# name: my-secret
289288

290289
# Specifies if aws-load-balancer-controller should be started in hostNetwork mode.
291290
# This is required if using a custom CNI where the managed control plane nodes are unable to initiate

mkdocs.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ markdown_extensions:
7070
- pymdownx.superfences
7171
- pymdownx.tabbed
7272
- pymdownx.emoji:
73-
emoji_index: !!python/name:materialx.emoji.twemoji
74-
emoji_generator: !!python/name:materialx.emoji.to_svg
73+
emoji_index: !!python/name:material.extensions.emoji.twemoji
74+
emoji_generator: !!python/name:material.extensions.emoji.to_svg
7575
- toc:
7676
permalink: true
7777
extra_css:

pkg/algorithm/slices.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package algorithm
2+
3+
import "cmp"
4+
5+
// RemoveSliceDuplicates returns a copy of the slice without duplicate entries.
6+
func RemoveSliceDuplicates[S ~[]E, E cmp.Ordered](s S) []E {
7+
result := make([]E, 0, len(s))
8+
found := make(map[E]struct{}, len(s))
9+
10+
for _, x := range s {
11+
if _, ok := found[x]; !ok {
12+
found[x] = struct{}{}
13+
result = append(result, x)
14+
}
15+
}
16+
17+
return result
18+
}

pkg/algorithm/slices_test.go

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package algorithm
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func Test_RemoveSliceDuplicates(t *testing.T) {
10+
type args struct {
11+
data []string
12+
}
13+
tests := []struct {
14+
name string
15+
args args
16+
want []string
17+
}{
18+
{
19+
name: "empty",
20+
args: args{
21+
data: []string{},
22+
},
23+
want: []string{},
24+
},
25+
{
26+
name: "no duplicate entries",
27+
args: args{
28+
data: []string{"a", "b", "c", "d"},
29+
},
30+
want: []string{"a", "b", "c", "d"},
31+
},
32+
{
33+
name: "with duplicates",
34+
args: args{
35+
data: []string{"a", "b", "a", "c", "b"},
36+
},
37+
want: []string{"a", "b", "c"},
38+
},
39+
}
40+
for _, tt := range tests {
41+
t.Run(tt.name, func(t *testing.T) {
42+
got := RemoveSliceDuplicates(tt.args.data)
43+
assert.Equal(t, tt.want, got)
44+
})
45+
}
46+
}

pkg/deploy/shield/protection_manager_mocks.go

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

pkg/deploy/shield/protection_synthesizer.go

+13-25
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package shield
22

33
import (
44
"context"
5+
"fmt"
56
"github.com/go-logr/logr"
67
"github.com/pkg/errors"
78
"k8s.io/apimachinery/pkg/util/sets"
89
"sigs.k8s.io/aws-load-balancer-controller/pkg/model/core"
9-
elbv2model "sigs.k8s.io/aws-load-balancer-controller/pkg/model/elbv2"
1010
shieldmodel "sigs.k8s.io/aws-load-balancer-controller/pkg/model/shield"
1111
)
1212

@@ -32,25 +32,18 @@ type protectionSynthesizer struct {
3232

3333
func (s *protectionSynthesizer) Synthesize(ctx context.Context) error {
3434
var resProtections []*shieldmodel.Protection
35-
s.stack.ListResources(&resProtections)
35+
if err := s.stack.ListResources(&resProtections); err != nil {
36+
return fmt.Errorf("[should never happen] failed to list resources: %w", err)
37+
}
38+
if len(resProtections) == 0 {
39+
return nil
40+
}
3641
resProtectionsByResARN, err := mapResProtectionByResourceARN(resProtections)
3742
if err != nil {
3843
return err
3944
}
40-
41-
var resLBs []*elbv2model.LoadBalancer
42-
s.stack.ListResources(&resLBs)
43-
for _, resLB := range resLBs {
44-
// shield protection can only be associated with ALB for now.
45-
if resLB.Spec.Type != elbv2model.LoadBalancerTypeApplication {
46-
continue
47-
}
48-
lbARN, err := resLB.LoadBalancerARN().Resolve(ctx)
49-
if err != nil {
50-
return err
51-
}
52-
resProtections := resProtectionsByResARN[lbARN]
53-
if err := s.synthesizeProtectionsOnLB(ctx, lbARN, resProtections); err != nil {
45+
for resARN, protections := range resProtectionsByResARN {
46+
if err := s.synthesizeProtectionsOnLB(ctx, resARN, protections); err != nil {
5447
return err
5548
}
5649
}
@@ -63,18 +56,13 @@ func (s *protectionSynthesizer) PostSynthesize(ctx context.Context) error {
6356
}
6457

6558
func (s *protectionSynthesizer) synthesizeProtectionsOnLB(ctx context.Context, lbARN string, resProtections []*shieldmodel.Protection) error {
66-
if len(resProtections) > 1 {
67-
return errors.Errorf("[should never happen] multiple shield protection desired on LoadBalancer: %v", lbARN)
68-
}
69-
70-
enableProtection := false
71-
if len(resProtections) == 1 {
72-
enableProtection = true
59+
if len(resProtections) != 1 {
60+
return errors.Errorf("[should never happen] should be exactly one shield protection desired on LoadBalancer: %v", lbARN)
7361
}
74-
62+
enableProtection := resProtections[0].Spec.Enabled
7563
protectionInfo, err := s.protectionManager.GetProtection(ctx, lbARN)
7664
if err != nil {
77-
return err
65+
return errors.Wrap(err, "failed to get shield protection on LoadBalancer")
7866
}
7967
switch {
8068
case !enableProtection && protectionInfo != nil:

0 commit comments

Comments
 (0)