@@ -28,6 +28,8 @@ import (
28
28
"github.com/aws/karpenter-core/pkg/apis/v1beta1"
29
29
"github.com/aws/karpenter-core/pkg/test"
30
30
. "github.com/aws/karpenter-core/pkg/test/expectations"
31
+
32
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31
33
)
32
34
33
35
var _ = Describe ("NodePool Static Drift Hash" , func () {
@@ -105,4 +107,107 @@ var _ = Describe("NodePool Static Drift Hash", func() {
105
107
106
108
Expect (nodePool .Annotations ).To (HaveKeyWithValue (v1beta1 .NodePoolHashAnnotationKey , expectedHash ))
107
109
})
110
+ It ("should update nodepool hash version when the nodepool hash version is out of sync with the controller hash version" , func () {
111
+ nodePool .Annotations = map [string ]string {
112
+ v1beta1 .NodePoolHashAnnotationKey : "abceduefed" ,
113
+ v1beta1 .NodePoolHashVersionAnnotationKey : "test" ,
114
+ }
115
+ ExpectApplied (ctx , env .Client , nodePool )
116
+
117
+ ExpectReconcileSucceeded (ctx , nodePoolController , client .ObjectKeyFromObject (nodePool ))
118
+ nodePool = ExpectExists (ctx , env .Client , nodePool )
119
+
120
+ expectedHash := nodePool .Hash ()
121
+ Expect (nodePool .Annotations ).To (HaveKeyWithValue (v1beta1 .NodePoolHashAnnotationKey , expectedHash ))
122
+ Expect (nodePool .Annotations ).To (HaveKeyWithValue (v1beta1 .NodePoolHashVersionAnnotationKey , v1beta1 .NodePoolHashVersion ))
123
+ })
124
+ It ("should update nodepool hash versions on all nodeclaims when the hash versions don't match the controller hash version" , func () {
125
+ nodePool .Annotations = map [string ]string {
126
+ v1beta1 .NodePoolHashAnnotationKey : "abceduefed" ,
127
+ v1beta1 .NodePoolHashVersionAnnotationKey : "test" ,
128
+ }
129
+ nodeClaimOne := test .NodeClaim (v1beta1.NodeClaim {
130
+ ObjectMeta : metav1.ObjectMeta {
131
+ Labels : map [string ]string {v1beta1 .NodePoolLabelKey : nodePool .Name },
132
+ Annotations : map [string ]string {
133
+ v1beta1 .NodePoolHashAnnotationKey : "123456" ,
134
+ v1beta1 .NodePoolHashVersionAnnotationKey : "test" ,
135
+ },
136
+ },
137
+ })
138
+ nodeClaimTwo := test .NodeClaim (v1beta1.NodeClaim {
139
+ ObjectMeta : metav1.ObjectMeta {
140
+ Labels : map [string ]string {v1beta1 .NodePoolLabelKey : nodePool .Name },
141
+ Annotations : map [string ]string {
142
+ v1beta1 .NodePoolHashAnnotationKey : "123456" ,
143
+ v1beta1 .NodePoolHashVersionAnnotationKey : "test" ,
144
+ },
145
+ },
146
+ })
147
+
148
+ ExpectApplied (ctx , env .Client , nodePool , nodeClaimOne , nodeClaimTwo )
149
+
150
+ ExpectReconcileSucceeded (ctx , nodePoolController , client .ObjectKeyFromObject (nodePool ))
151
+ nodePool = ExpectExists (ctx , env .Client , nodePool )
152
+ nodeClaimOne = ExpectExists (ctx , env .Client , nodeClaimOne )
153
+ nodeClaimTwo = ExpectExists (ctx , env .Client , nodeClaimTwo )
154
+
155
+ expectedHash := nodePool .Hash ()
156
+ Expect (nodeClaimOne .Annotations ).To (HaveKeyWithValue (v1beta1 .NodePoolHashAnnotationKey , expectedHash ))
157
+ Expect (nodeClaimOne .Annotations ).To (HaveKeyWithValue (v1beta1 .NodePoolHashVersionAnnotationKey , v1beta1 .NodePoolHashVersion ))
158
+ Expect (nodeClaimTwo .Annotations ).To (HaveKeyWithValue (v1beta1 .NodePoolHashAnnotationKey , expectedHash ))
159
+ Expect (nodeClaimTwo .Annotations ).To (HaveKeyWithValue (v1beta1 .NodePoolHashVersionAnnotationKey , v1beta1 .NodePoolHashVersion ))
160
+ })
161
+ It ("should not update nodepool hash on all nodeclaims when the hash versions match the controller hash version" , func () {
162
+ nodePool .Annotations = map [string ]string {
163
+ v1beta1 .NodePoolHashAnnotationKey : "abceduefed" ,
164
+ v1beta1 .NodePoolHashVersionAnnotationKey : "test-version" ,
165
+ }
166
+ nodeClaim := test .NodeClaim (v1beta1.NodeClaim {
167
+ ObjectMeta : metav1.ObjectMeta {
168
+ Labels : map [string ]string {v1beta1 .NodePoolLabelKey : nodePool .Name },
169
+ Annotations : map [string ]string {
170
+ v1beta1 .NodePoolHashAnnotationKey : "1234564654" ,
171
+ v1beta1 .NodePoolHashVersionAnnotationKey : v1beta1 .NodePoolHashVersion ,
172
+ },
173
+ },
174
+ })
175
+ ExpectApplied (ctx , env .Client , nodePool , nodeClaim )
176
+
177
+ ExpectReconcileSucceeded (ctx , nodePoolController , client .ObjectKeyFromObject (nodePool ))
178
+ nodePool = ExpectExists (ctx , env .Client , nodePool )
179
+ nodeClaim = ExpectExists (ctx , env .Client , nodeClaim )
180
+
181
+ expectedHash := nodePool .Hash ()
182
+
183
+ // Expect NodeClaims to have been updated to the original hash
184
+ Expect (nodePool .Annotations ).To (HaveKeyWithValue (v1beta1 .NodePoolHashAnnotationKey , expectedHash ))
185
+ Expect (nodePool .Annotations ).To (HaveKeyWithValue (v1beta1 .NodePoolHashVersionAnnotationKey , v1beta1 .NodePoolHashVersion ))
186
+ Expect (nodeClaim .Annotations ).To (HaveKeyWithValue (v1beta1 .NodePoolHashAnnotationKey , "1234564654" ))
187
+ Expect (nodeClaim .Annotations ).To (HaveKeyWithValue (v1beta1 .NodePoolHashVersionAnnotationKey , v1beta1 .NodePoolHashVersion ))
188
+ })
189
+ It ("should not update nodepool hash on the nodeclaim if it's drifted" , func () {
190
+ nodePool .Annotations = map [string ]string {
191
+ v1beta1 .NodePoolHashAnnotationKey : "abceduefed" ,
192
+ v1beta1 .NodePoolHashVersionAnnotationKey : "test" ,
193
+ }
194
+ nodeClaim := test .NodeClaim (v1beta1.NodeClaim {
195
+ ObjectMeta : metav1.ObjectMeta {
196
+ Labels : map [string ]string {v1beta1 .NodePoolLabelKey : nodePool .Name },
197
+ Annotations : map [string ]string {
198
+ v1beta1 .NodePoolHashAnnotationKey : "123456" ,
199
+ v1beta1 .NodePoolHashVersionAnnotationKey : "test" ,
200
+ },
201
+ },
202
+ })
203
+ nodeClaim .StatusConditions ().MarkTrue (v1beta1 .Drifted )
204
+ ExpectApplied (ctx , env .Client , nodePool , nodeClaim )
205
+
206
+ ExpectReconcileSucceeded (ctx , nodePoolController , client .ObjectKeyFromObject (nodePool ))
207
+ nodeClaim = ExpectExists (ctx , env .Client , nodeClaim )
208
+
209
+ // Expect NodeClaims hash to not have been updated
210
+ Expect (nodeClaim .Annotations ).To (HaveKeyWithValue (v1beta1 .NodePoolHashAnnotationKey , "123456" ))
211
+ Expect (nodeClaim .Annotations ).To (HaveKeyWithValue (v1beta1 .NodePoolHashVersionAnnotationKey , v1beta1 .NodePoolHashVersion ))
212
+ })
108
213
})
0 commit comments