Skip to content

Commit

Permalink
Merge pull request #5199 from gutmensch/gutmensch-fix-addons-isequal
Browse files Browse the repository at this point in the history
🐛 fix(addons): add configuration to IsEqual cmp
  • Loading branch information
k8s-ci-robot authored Nov 4, 2024
2 parents 1416be7 + 30e364c commit 0cc6e45
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 1 deletion.
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)
}
}

0 comments on commit 0cc6e45

Please sign in to comment.