Skip to content

Commit

Permalink
make coip drift check a warning instead of error (kubernetes-sigs#2329)
Browse files Browse the repository at this point in the history
  • Loading branch information
M00nF1sh authored Oct 29, 2021
1 parent d124b32 commit ede438c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions pkg/deploy/elbv2/load_balancer_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
awssdk "github.com/aws/aws-sdk-go/aws"
elbv2sdk "github.com/aws/aws-sdk-go/service/elbv2"
"github.com/go-logr/logr"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/sets"
"sigs.k8s.io/aws-load-balancer-controller/pkg/aws/services"
"sigs.k8s.io/aws-load-balancer-controller/pkg/deploy/tracking"
Expand Down Expand Up @@ -214,7 +213,9 @@ func (m *defaultLoadBalancerManager) updateSDKLoadBalancerWithSecurityGroups(ctx

func (m *defaultLoadBalancerManager) checkSDKLoadBalancerWithCOIPv4Pool(_ context.Context, resLB *elbv2model.LoadBalancer, sdkLB LoadBalancerWithTags) error {
if awssdk.StringValue(resLB.Spec.CustomerOwnedIPv4Pool) != awssdk.StringValue(sdkLB.LoadBalancer.CustomerOwnedIpv4Pool) {
return errors.New("loadBalancer has drifted CustomerOwnedIPv4Pool setting")
m.logger.Info("loadBalancer has drifted CustomerOwnedIPv4Pool setting",
"desired", awssdk.StringValue(resLB.Spec.CustomerOwnedIPv4Pool),
"current", awssdk.StringValue(sdkLB.LoadBalancer.CustomerOwnedIpv4Pool))
}
return nil
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/deploy/elbv2/load_balancer_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package elbv2

import (
"context"
"errors"
awssdk "github.com/aws/aws-sdk-go/aws"
elbv2sdk "github.com/aws/aws-sdk-go/service/elbv2"
"github.com/stretchr/testify/assert"
coremodel "sigs.k8s.io/aws-load-balancer-controller/pkg/model/core"
elbv2model "sigs.k8s.io/aws-load-balancer-controller/pkg/model/elbv2"
"sigs.k8s.io/controller-runtime/pkg/log"
"testing"
)

Expand Down Expand Up @@ -363,7 +363,7 @@ func Test_defaultLoadBalancerManager_checkSDKLoadBalancerWithCOIPv4Pool(t *testi
},
},
},
wantErr: errors.New("loadBalancer has drifted CustomerOwnedIPv4Pool setting"),
wantErr: nil,
},
{
name: "only resLB have CustomerOwnedIPv4Pool setting",
Expand All @@ -379,7 +379,7 @@ func Test_defaultLoadBalancerManager_checkSDKLoadBalancerWithCOIPv4Pool(t *testi
},
},
},
wantErr: errors.New("loadBalancer has drifted CustomerOwnedIPv4Pool setting"),
wantErr: nil,
},
{
name: "only sdkLB have CustomerOwnedIPv4Pool setting",
Expand All @@ -395,12 +395,14 @@ func Test_defaultLoadBalancerManager_checkSDKLoadBalancerWithCOIPv4Pool(t *testi
},
},
},
wantErr: errors.New("loadBalancer has drifted CustomerOwnedIPv4Pool setting"),
wantErr: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := &defaultLoadBalancerManager{}
m := &defaultLoadBalancerManager{
logger: &log.NullLogger{},
}
err := m.checkSDKLoadBalancerWithCOIPv4Pool(context.Background(), tt.args.resLB, tt.args.sdkLB)
if tt.wantErr != nil {
assert.EqualError(t, err, tt.wantErr.Error())
Expand Down

0 comments on commit ede438c

Please sign in to comment.