Skip to content

Commit 424350f

Browse files
authored
Merge pull request #804 from M00nF1sh/issue-655
fix issue-655
2 parents 370f7df + 2c86180 commit 424350f

File tree

2 files changed

+29
-37
lines changed

2 files changed

+29
-37
lines changed

internal/alb/lb/attributes.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,29 +156,32 @@ func (c *attributesController) Reconcile(ctx context.Context, lbArn string, attr
156156
}
157157

158158
// attributesChangeSet returns a list of elbv2.LoadBalancerAttribute required to change a into b
159-
func attributesChangeSet(a, b *Attributes) (changeSet []*elbv2.LoadBalancerAttribute) {
160-
if a.DeletionProtectionEnabled != b.DeletionProtectionEnabled {
161-
changeSet = append(changeSet, lbAttribute(DeletionProtectionEnabledKey, fmt.Sprintf("%v", b.DeletionProtectionEnabled)))
159+
func attributesChangeSet(current, desired *Attributes) (changeSet []*elbv2.LoadBalancerAttribute) {
160+
if current.DeletionProtectionEnabled != desired.DeletionProtectionEnabled {
161+
changeSet = append(changeSet, lbAttribute(DeletionProtectionEnabledKey, fmt.Sprintf("%v", desired.DeletionProtectionEnabled)))
162162
}
163163

164-
if a.AccessLogsS3Enabled != b.AccessLogsS3Enabled {
165-
changeSet = append(changeSet, lbAttribute(AccessLogsS3EnabledKey, fmt.Sprintf("%v", b.AccessLogsS3Enabled)))
164+
if current.AccessLogsS3Enabled != desired.AccessLogsS3Enabled {
165+
changeSet = append(changeSet, lbAttribute(AccessLogsS3EnabledKey, fmt.Sprintf("%v", desired.AccessLogsS3Enabled)))
166166
}
167167

168-
if a.AccessLogsS3Bucket != b.AccessLogsS3Bucket {
169-
changeSet = append(changeSet, lbAttribute(AccessLogsS3BucketKey, b.AccessLogsS3Bucket))
170-
}
168+
// ELBV2 API forbids us to set bucket to an empty bucket, so we keep it unchanged if AccessLogsS3Enabled==false.
169+
if desired.AccessLogsS3Enabled {
170+
if current.AccessLogsS3Bucket != desired.AccessLogsS3Bucket {
171+
changeSet = append(changeSet, lbAttribute(AccessLogsS3BucketKey, desired.AccessLogsS3Bucket))
172+
}
171173

172-
if a.AccessLogsS3Prefix != b.AccessLogsS3Prefix {
173-
changeSet = append(changeSet, lbAttribute(AccessLogsS3PrefixKey, b.AccessLogsS3Prefix))
174+
if current.AccessLogsS3Prefix != desired.AccessLogsS3Prefix {
175+
changeSet = append(changeSet, lbAttribute(AccessLogsS3PrefixKey, desired.AccessLogsS3Prefix))
176+
}
174177
}
175178

176-
if a.IdleTimeoutTimeoutSeconds != b.IdleTimeoutTimeoutSeconds {
177-
changeSet = append(changeSet, lbAttribute(IdleTimeoutTimeoutSecondsKey, fmt.Sprintf("%v", b.IdleTimeoutTimeoutSeconds)))
179+
if current.IdleTimeoutTimeoutSeconds != desired.IdleTimeoutTimeoutSeconds {
180+
changeSet = append(changeSet, lbAttribute(IdleTimeoutTimeoutSecondsKey, fmt.Sprintf("%v", desired.IdleTimeoutTimeoutSeconds)))
178181
}
179182

180-
if a.RoutingHTTP2Enabled != b.RoutingHTTP2Enabled {
181-
changeSet = append(changeSet, lbAttribute(RoutingHTTP2EnabledKey, fmt.Sprintf("%v", b.RoutingHTTP2Enabled)))
183+
if current.RoutingHTTP2Enabled != desired.RoutingHTTP2Enabled {
184+
changeSet = append(changeSet, lbAttribute(RoutingHTTP2EnabledKey, fmt.Sprintf("%v", desired.RoutingHTTP2Enabled)))
182185
}
183186

184187
return

internal/alb/lb/attributes_test.go

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,6 @@ func Test_attributesChangeSet(t *testing.T) {
114114
b *Attributes
115115
changeSet []*elbv2.LoadBalancerAttribute
116116
}{
117-
{
118-
name: "a and b contain a default AccessLogsS3Bucket value, expect no change",
119-
a: MustNewAttributes([]*elbv2.LoadBalancerAttribute{lbAttribute(AccessLogsS3BucketKey, "true")}),
120-
b: MustNewAttributes([]*elbv2.LoadBalancerAttribute{lbAttribute(AccessLogsS3BucketKey, "true")}),
121-
},
122-
{
123-
name: "a contains a non-default AccessLogsS3Bucket, b contains default, change to default",
124-
a: MustNewAttributes([]*elbv2.LoadBalancerAttribute{lbAttribute(AccessLogsS3BucketKey, "some bucket")}),
125-
b: MustNewAttributes(nil),
126-
changeSet: []*elbv2.LoadBalancerAttribute{lbAttribute(AccessLogsS3BucketKey, "")},
127-
},
128117
{
129118
name: "a and b contain empty defaults, no change",
130119
a: MustNewAttributes(nil),
@@ -137,22 +126,22 @@ func Test_attributesChangeSet(t *testing.T) {
137126
changeSet: []*elbv2.LoadBalancerAttribute{lbAttribute(DeletionProtectionEnabledKey, "true")},
138127
},
139128
{
140-
name: fmt.Sprintf("a contains default, b contains non-default AccessLogsS3EnabledKey, make a change"),
141-
a: MustNewAttributes(nil),
142-
b: MustNewAttributes([]*elbv2.LoadBalancerAttribute{lbAttribute(AccessLogsS3EnabledKey, "true")}),
143-
changeSet: []*elbv2.LoadBalancerAttribute{lbAttribute(AccessLogsS3EnabledKey, "true")},
129+
name: fmt.Sprintf("enable AccessLogS3"),
130+
a: MustNewAttributes([]*elbv2.LoadBalancerAttribute{lbAttribute(AccessLogsS3EnabledKey, "false"), lbAttribute(AccessLogsS3BucketKey, ""), lbAttribute(AccessLogsS3PrefixKey, "")}),
131+
b: MustNewAttributes([]*elbv2.LoadBalancerAttribute{lbAttribute(AccessLogsS3EnabledKey, "true"), lbAttribute(AccessLogsS3BucketKey, "bucket"), lbAttribute(AccessLogsS3PrefixKey, "prefix")}),
132+
changeSet: []*elbv2.LoadBalancerAttribute{lbAttribute(AccessLogsS3EnabledKey, "true"), lbAttribute(AccessLogsS3BucketKey, "bucket"), lbAttribute(AccessLogsS3PrefixKey, "prefix")},
144133
},
145134
{
146-
name: fmt.Sprintf("a contains default, b contains non-default AccessLogsS3BucketKey, make a change"),
147-
a: MustNewAttributes(nil),
148-
b: MustNewAttributes([]*elbv2.LoadBalancerAttribute{lbAttribute(AccessLogsS3BucketKey, "some bucket")}),
149-
changeSet: []*elbv2.LoadBalancerAttribute{lbAttribute(AccessLogsS3BucketKey, "some bucket")},
135+
name: fmt.Sprintf("disable AccessLogS3, don't change bucket/prefix when it's unchanged."),
136+
a: MustNewAttributes([]*elbv2.LoadBalancerAttribute{lbAttribute(AccessLogsS3EnabledKey, "true"), lbAttribute(AccessLogsS3BucketKey, "bucket"), lbAttribute(AccessLogsS3PrefixKey, "prefix")}),
137+
b: MustNewAttributes([]*elbv2.LoadBalancerAttribute{lbAttribute(AccessLogsS3EnabledKey, "false"), lbAttribute(AccessLogsS3BucketKey, "bucket"), lbAttribute(AccessLogsS3PrefixKey, "prefix")}),
138+
changeSet: []*elbv2.LoadBalancerAttribute{lbAttribute(AccessLogsS3EnabledKey, "false")},
150139
},
151140
{
152-
name: fmt.Sprintf("a contains default, b contains non-default AccessLogsS3PrefixKey, make a change"),
153-
a: MustNewAttributes(nil),
154-
b: MustNewAttributes([]*elbv2.LoadBalancerAttribute{lbAttribute(AccessLogsS3PrefixKey, "some prefix")}),
155-
changeSet: []*elbv2.LoadBalancerAttribute{lbAttribute(AccessLogsS3PrefixKey, "some prefix")},
141+
name: fmt.Sprintf("disable AccessLogS3, don't change bucket/prefix when it's changed"),
142+
a: MustNewAttributes([]*elbv2.LoadBalancerAttribute{lbAttribute(AccessLogsS3EnabledKey, "true"), lbAttribute(AccessLogsS3BucketKey, "bucket"), lbAttribute(AccessLogsS3PrefixKey, "prefix")}),
143+
b: MustNewAttributes([]*elbv2.LoadBalancerAttribute{lbAttribute(AccessLogsS3EnabledKey, "false"), lbAttribute(AccessLogsS3BucketKey, ""), lbAttribute(AccessLogsS3PrefixKey, "")}),
144+
changeSet: []*elbv2.LoadBalancerAttribute{lbAttribute(AccessLogsS3EnabledKey, "false")},
156145
},
157146
{
158147
name: fmt.Sprintf("a contains default, b contains non-default IdleTimeoutTimeoutSecondsKey, make a change"),

0 commit comments

Comments
 (0)