From 2fd69ba3a33f6a82f50f4436a8052119f05ec633 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Tue, 3 Aug 2021 17:45:20 +0900
Subject: [PATCH] Remove access log attributes when the spec is removed from
cluster spec
---
pkg/model/awsmodel/api_loadbalancer.go | 7 +++++++
.../fi/cloudup/awstasks/networkloadbalancer_attributes.go | 4 ++--
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/pkg/model/awsmodel/api_loadbalancer.go b/pkg/model/awsmodel/api_loadbalancer.go
index 5ef9c05332..808ee3bcfd 100644
--- a/pkg/model/awsmodel/api_loadbalancer.go
+++ b/pkg/model/awsmodel/api_loadbalancer.go
@@ -249,6 +249,13 @@ func (b *APILoadBalancerBuilder) Build(c *fi.ModelBuilderContext) error {
S3BucketName: fi.String(lbSpec.AccessLog.Bucket),
S3BucketPrefix: fi.String(lbSpec.AccessLog.BucketPrefix),
}
+ } else {
+ clb.AccessLog = &awstasks.ClassicLoadBalancerAccessLog{
+ Enabled: fi.Bool(false),
+ }
+ nlb.AccessLog = &awstasks.NetworkLoadBalancerAccessLog{
+ Enabled: fi.Bool(false),
+ }
}
if b.APILoadBalancerClass() == kops.LoadBalancerClassClassic {
diff --git a/upup/pkg/fi/cloudup/awstasks/networkloadbalancer_attributes.go b/upup/pkg/fi/cloudup/awstasks/networkloadbalancer_attributes.go
index be628211f7..3c307967f2 100644
--- a/upup/pkg/fi/cloudup/awstasks/networkloadbalancer_attributes.go
+++ b/upup/pkg/fi/cloudup/awstasks/networkloadbalancer_attributes.go
@@ -62,7 +62,7 @@ func findNetworkLoadBalancerAttributes(cloud awsup.AWSCloud, LoadBalancerArn str
}
func (_ *NetworkLoadBalancer) modifyLoadBalancerAttributes(t *awsup.AWSAPITarget, a, e, changes *NetworkLoadBalancer, loadBalancerArn string) error {
- if changes.CrossZoneLoadBalancing == nil {
+ if changes.CrossZoneLoadBalancing == nil && changes.AccessLog == nil {
klog.V(4).Infof("No LoadBalancerAttribute changes; skipping update")
return nil
}
@@ -84,7 +84,7 @@ func (_ *NetworkLoadBalancer) modifyLoadBalancerAttributes(t *awsup.AWSAPITarget
}
attributes = append(attributes, attribute)
- if e.AccessLog != nil && e.AccessLog.Enabled != nil {
+ if e.AccessLog != nil {
attr := &elbv2.LoadBalancerAttribute{
Key: aws.String("access_logs.s3.enabled"),
Value: aws.String(strconv.FormatBool(aws.BoolValue(e.AccessLog.Enabled))),