Skip to content

Commit 0cc6e45

Browse files
authored
Merge pull request #5199 from gutmensch/gutmensch-fix-addons-isequal
🐛 fix(addons): add configuration to IsEqual cmp
2 parents 1416be7 + 30e364c commit 0cc6e45

File tree

2 files changed

+150
-1
lines changed

2 files changed

+150
-1
lines changed

pkg/eks/addons/types.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type EKSAddon struct {
3636

3737
// IsEqual determines if 2 EKSAddon are equal.
3838
func (e *EKSAddon) IsEqual(other *EKSAddon, includeTags bool) bool {
39-
//NOTE: we don't compare the ARN as thats only for existing addons
39+
//NOTE: we do not compare the ARN as that is only for existing addons
4040
if e == other {
4141
return true
4242
}
@@ -46,6 +46,12 @@ func (e *EKSAddon) IsEqual(other *EKSAddon, includeTags bool) bool {
4646
if !cmp.Equal(e.ServiceAccountRoleARN, other.ServiceAccountRoleARN) {
4747
return false
4848
}
49+
if !cmp.Equal(e.Configuration, other.Configuration) {
50+
return false
51+
}
52+
if !cmp.Equal(e.ResolveConflict, other.ResolveConflict) {
53+
return false
54+
}
4955

5056
if includeTags {
5157
diffTags := e.Tags.Difference(other.Tags)

pkg/eks/addons/types_test.go

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
Copyright 2021 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package addons
18+
19+
import (
20+
"testing"
21+
22+
"github.com/onsi/gomega"
23+
)
24+
25+
func TestAddOnEqual(t *testing.T) {
26+
ptr := func(s string) *string { return &s }
27+
tags := func(s, t string) map[string]string {
28+
return map[string]string{
29+
s: t,
30+
}
31+
}
32+
g := gomega.NewGomegaWithT(t)
33+
tests := []struct {
34+
orig *EKSAddon
35+
other *EKSAddon
36+
result gomega.OmegaMatcher
37+
includeTags bool
38+
}{
39+
{
40+
orig: &EKSAddon{
41+
Version: ptr("a"),
42+
ServiceAccountRoleARN: ptr("b"),
43+
Configuration: ptr("c"),
44+
ResolveConflict: ptr("d"),
45+
Tags: tags("a", "1"),
46+
},
47+
other: &EKSAddon{
48+
Version: ptr("a"),
49+
ServiceAccountRoleARN: ptr("b"),
50+
Configuration: ptr("c"),
51+
ResolveConflict: ptr("d"),
52+
Tags: tags("a", "1"),
53+
Status: ptr("e"),
54+
},
55+
result: gomega.BeTrueBecause("addon values are equal (except status)"),
56+
},
57+
{
58+
orig: &EKSAddon{
59+
Version: ptr("a"),
60+
ServiceAccountRoleARN: ptr("b"),
61+
Configuration: ptr("c"),
62+
},
63+
other: &EKSAddon{
64+
Version: ptr("b"),
65+
ServiceAccountRoleARN: ptr("b"),
66+
Configuration: ptr("c"),
67+
},
68+
result: gomega.BeFalseBecause("addon version differs"),
69+
},
70+
{
71+
orig: &EKSAddon{
72+
Version: ptr("a"),
73+
ServiceAccountRoleARN: ptr("b"),
74+
Configuration: ptr("c"),
75+
},
76+
other: &EKSAddon{
77+
Version: ptr("a"),
78+
ServiceAccountRoleARN: ptr("c"),
79+
Configuration: ptr("c"),
80+
},
81+
result: gomega.BeFalseBecause("addon serviceAccountRoleARN differs"),
82+
},
83+
{
84+
orig: &EKSAddon{
85+
Version: ptr("a"),
86+
ServiceAccountRoleARN: ptr("b"),
87+
Configuration: ptr("c"),
88+
},
89+
other: &EKSAddon{
90+
Version: ptr("a"),
91+
ServiceAccountRoleARN: ptr("b"),
92+
Configuration: ptr("d"),
93+
},
94+
result: gomega.BeFalseBecause("addon configuration differs"),
95+
},
96+
{
97+
orig: &EKSAddon{
98+
Version: ptr("a"),
99+
ServiceAccountRoleARN: ptr("b"),
100+
Configuration: ptr("c"),
101+
ResolveConflict: ptr("d"),
102+
},
103+
other: &EKSAddon{
104+
Version: ptr("a"),
105+
ServiceAccountRoleARN: ptr("b"),
106+
Configuration: ptr("d"),
107+
ResolveConflict: ptr("e"),
108+
},
109+
result: gomega.BeFalseBecause("addon conflict resolution differs"),
110+
},
111+
{
112+
orig: &EKSAddon{
113+
Version: ptr("a"),
114+
ServiceAccountRoleARN: ptr("b"),
115+
Tags: tags("a", "1"),
116+
},
117+
other: &EKSAddon{
118+
Version: ptr("a"),
119+
ServiceAccountRoleARN: ptr("b"),
120+
Tags: tags("a", "2"),
121+
},
122+
result: gomega.BeTrueBecause("addon tags differ but not used for comparison"),
123+
},
124+
{
125+
orig: &EKSAddon{
126+
Version: ptr("a"),
127+
ServiceAccountRoleARN: ptr("b"),
128+
Tags: tags("a", "1"),
129+
},
130+
other: &EKSAddon{
131+
Version: ptr("a"),
132+
ServiceAccountRoleARN: ptr("b"),
133+
Tags: tags("a", "2"),
134+
},
135+
result: gomega.BeFalseBecause("addon tags differ and used for comparison"),
136+
includeTags: true,
137+
},
138+
}
139+
140+
for _, test := range tests {
141+
g.Expect(test.orig.IsEqual(test.other, test.includeTags)).To(test.result)
142+
}
143+
}

0 commit comments

Comments
 (0)