Skip to content

Commit

Permalink
Add E2E for NodePools hash version
Browse files Browse the repository at this point in the history
  • Loading branch information
engedaam committed Mar 9, 2024
1 parent 16992b6 commit 1e1e1f5
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/pkg/environment/common/expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,19 @@ func (env *Environment) EventuallyExpectDrifted(nodeClaims ...*corev1beta1.NodeC
}).Should(Succeed())
}

func (env *Environment) ConsistentlyExpectNodeClaimsNotDrifted(duration time.Duration, nodeClaims ...*corev1beta1.NodeClaim) {
GinkgoHelper()
Consistently(func(g Gomega) {
for _, nc := range nodeClaims {
g.Expect(env.Client.Get(env, client.ObjectKeyFromObject(nc), nc)).To(Succeed())
g.Expect(nc.StatusConditions().GetCondition(corev1beta1.Drifted)).To(BeNil())
}
}, duration).Should(Succeed())
}

func (env *Environment) EventuallyExpectEmpty(nodeClaims ...*corev1beta1.NodeClaim) {
GinkgoHelper()

Eventually(func(g Gomega) {
for _, nc := range nodeClaims {
g.Expect(env.Client.Get(env, client.ObjectKeyFromObject(nc), nc)).To(Succeed())
Expand Down
49 changes: 49 additions & 0 deletions test/suites/drift/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,55 @@ var _ = Describe("Drift", func() {
env.EventuallyExpectNotFound(pod, node)
env.EventuallyExpectHealthyPodCount(selector, numPods)
})
It("should update the nodepool-hash annotation on the nodepool and nodeclaim when the nodepool's nodepool-hash-version annotation does not match the controller hash version", func() {
env.ExpectCreated(dep, nodeClass, nodePool)
env.EventuallyExpectHealthyPodCount(selector, numPods)
nodeClaim := env.EventuallyExpectCreatedNodeClaimCount("==", 1)[0]
nodePool = env.ExpectExists(nodePool).(*corev1beta1.NodePool)
expectedHash := nodePool.Hash()

By(fmt.Sprintf("expect nodepool %s and nodeclaim %s to contain karpenter.sh/nodepool-hash and karpenter.sh/nodepool-hash-version annotations", nodePool.Name, nodeClaim.Name))
Eventually(func(g Gomega) {
g.Expect(nodePool.Annotations).To(HaveKeyWithValue(corev1beta1.NodePoolHashAnnotationKey, expectedHash))
g.Expect(nodePool.Annotations).To(HaveKeyWithValue(corev1beta1.NodePoolHashVersionAnnotationKey, corev1beta1.NodePoolHashVersion))
g.Expect(nodeClaim.Annotations).To(HaveKeyWithValue(corev1beta1.NodePoolHashAnnotationKey, expectedHash))
g.Expect(nodeClaim.Annotations).To(HaveKeyWithValue(corev1beta1.NodePoolHashVersionAnnotationKey, corev1beta1.NodePoolHashVersion))
}).WithTimeout(30 * time.Second).Should(Succeed())

nodePool.Annotations = lo.Assign(nodePool.Annotations, map[string]string{
corev1beta1.NodePoolHashAnnotationKey: "test-hash-1",
corev1beta1.NodePoolHashVersionAnnotationKey: "test-hash-version-1",
})
// Updating `nodePool.Spec.Template.Annotations` would normally trigger drift on all nodeclaims owned by the
// nodepool. However, the nodepool-hash-version does not match the controller hash version, so we will see that
// none of the nodeclaims will be drifted and all nodeclaims will have an updated `nodepool-hash` and `nodepool-hash-version` annotations
nodePool.Spec.Template.Annotations = lo.Assign(nodePool.Spec.Template.Annotations, map[string]string{
"test-key": "test-value",
})
nodeClaim.Annotations = lo.Assign(nodePool.Annotations, map[string]string{
corev1beta1.NodePoolHashAnnotationKey: "test-hash-2",
corev1beta1.NodePoolHashVersionAnnotationKey: "test-hash-version-2",
})

// The nodeclaim will need to be updated first, as the hash controller will only be triggered on changes to the nodepool
env.ExpectUpdated(nodeClaim, nodePool)
expectedHash = nodePool.Hash()

// Should expect the all nodeclaims will not be drifted and contain an updated `nodepool-hash` and `nodepool-hash-version` annotations
Eventually(func(g Gomega) {
nodePool = env.ExpectExists(nodePool).(*corev1beta1.NodePool)
nodeClaim = env.ExpectExists(nodeClaim).(*corev1beta1.NodeClaim)

g.Expect(nodePool.Annotations).To(HaveKeyWithValue(corev1beta1.NodePoolHashAnnotationKey, expectedHash))
g.Expect(nodePool.Annotations).To(HaveKeyWithValue(corev1beta1.NodePoolHashVersionAnnotationKey, corev1beta1.NodePoolHashVersion))
g.Expect(nodeClaim.Annotations).To(HaveKeyWithValue(corev1beta1.NodePoolHashAnnotationKey, expectedHash))
g.Expect(nodeClaim.Annotations).To(HaveKeyWithValue(corev1beta1.NodePoolHashVersionAnnotationKey, corev1beta1.NodePoolHashVersion))
}).WithTimeout(30 * time.Second).Should(Succeed())

notDriftedDuration := time.Minute
By(fmt.Sprintf("consistently expect nodeclaim %s not to be drifted for %s", nodeClaim.Name, notDriftedDuration))
env.ConsistentlyExpectNodeClaimsNotDrifted(notDriftedDuration, nodeClaim)
})
Context("Failure", func() {
It("should not continue to drift if a node never registers", func() {
// launch a new nodeClaim
Expand Down

0 comments on commit 1e1e1f5

Please sign in to comment.