Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-2.7] 🐛 fix(addons): add configuration to IsEqual cmp #5202

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pkg/eks/addons/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type EKSAddon struct {

// IsEqual determines if 2 EKSAddon are equal.
func (e *EKSAddon) IsEqual(other *EKSAddon, includeTags bool) bool {
//NOTE: we don't compare the ARN as thats only for existing addons
//NOTE: we do not compare the ARN as that is only for existing addons
if e == other {
return true
}
Expand All @@ -46,6 +46,12 @@ func (e *EKSAddon) IsEqual(other *EKSAddon, includeTags bool) bool {
if !cmp.Equal(e.ServiceAccountRoleARN, other.ServiceAccountRoleARN) {
return false
}
if !cmp.Equal(e.Configuration, other.Configuration) {
return false
}
if !cmp.Equal(e.ResolveConflict, other.ResolveConflict) {
return false
}

if includeTags {
diffTags := e.Tags.Difference(other.Tags)
Expand Down
143 changes: 143 additions & 0 deletions pkg/eks/addons/types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
Copyright 2021 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package addons

import (
"testing"

"github.com/onsi/gomega"
)

func TestAddOnEqual(t *testing.T) {
ptr := func(s string) *string { return &s }
tags := func(s, t string) map[string]string {
return map[string]string{
s: t,
}
}
g := gomega.NewGomegaWithT(t)
tests := []struct {
orig *EKSAddon
other *EKSAddon
result gomega.OmegaMatcher
includeTags bool
}{
{
orig: &EKSAddon{
Version: ptr("a"),
ServiceAccountRoleARN: ptr("b"),
Configuration: ptr("c"),
ResolveConflict: ptr("d"),
Tags: tags("a", "1"),
},
other: &EKSAddon{
Version: ptr("a"),
ServiceAccountRoleARN: ptr("b"),
Configuration: ptr("c"),
ResolveConflict: ptr("d"),
Tags: tags("a", "1"),
Status: ptr("e"),
},
result: gomega.BeTrueBecause("addon values are equal (except status)"),
},
{
orig: &EKSAddon{
Version: ptr("a"),
ServiceAccountRoleARN: ptr("b"),
Configuration: ptr("c"),
},
other: &EKSAddon{
Version: ptr("b"),
ServiceAccountRoleARN: ptr("b"),
Configuration: ptr("c"),
},
result: gomega.BeFalseBecause("addon version differs"),
},
{
orig: &EKSAddon{
Version: ptr("a"),
ServiceAccountRoleARN: ptr("b"),
Configuration: ptr("c"),
},
other: &EKSAddon{
Version: ptr("a"),
ServiceAccountRoleARN: ptr("c"),
Configuration: ptr("c"),
},
result: gomega.BeFalseBecause("addon serviceAccountRoleARN differs"),
},
{
orig: &EKSAddon{
Version: ptr("a"),
ServiceAccountRoleARN: ptr("b"),
Configuration: ptr("c"),
},
other: &EKSAddon{
Version: ptr("a"),
ServiceAccountRoleARN: ptr("b"),
Configuration: ptr("d"),
},
result: gomega.BeFalseBecause("addon configuration differs"),
},
{
orig: &EKSAddon{
Version: ptr("a"),
ServiceAccountRoleARN: ptr("b"),
Configuration: ptr("c"),
ResolveConflict: ptr("d"),
},
other: &EKSAddon{
Version: ptr("a"),
ServiceAccountRoleARN: ptr("b"),
Configuration: ptr("d"),
ResolveConflict: ptr("e"),
},
result: gomega.BeFalseBecause("addon conflict resolution differs"),
},
{
orig: &EKSAddon{
Version: ptr("a"),
ServiceAccountRoleARN: ptr("b"),
Tags: tags("a", "1"),
},
other: &EKSAddon{
Version: ptr("a"),
ServiceAccountRoleARN: ptr("b"),
Tags: tags("a", "2"),
},
result: gomega.BeTrueBecause("addon tags differ but not used for comparison"),
},
{
orig: &EKSAddon{
Version: ptr("a"),
ServiceAccountRoleARN: ptr("b"),
Tags: tags("a", "1"),
},
other: &EKSAddon{
Version: ptr("a"),
ServiceAccountRoleARN: ptr("b"),
Tags: tags("a", "2"),
},
result: gomega.BeFalseBecause("addon tags differ and used for comparison"),
includeTags: true,
},
}

for _, test := range tests {
g.Expect(test.orig.IsEqual(test.other, test.includeTags)).To(test.result)
}
}