diff --git a/test/pkg/environment/common/expectations.go b/test/pkg/environment/common/expectations.go index 03bb0c4d4b05..5d12ac303e40 100644 --- a/test/pkg/environment/common/expectations.go +++ b/test/pkg/environment/common/expectations.go @@ -696,8 +696,18 @@ func (env *Environment) EventuallyExpectDrifted(nodeClaims ...*corev1beta1.NodeC }).Should(Succeed()) } +func (env *Environment) ConsistentlyExpectNotDrifted(nodeClaim *corev1beta1.NodeClaim) { + GinkgoHelper() + By(fmt.Sprintf("waiting to verify nodeclaims to be %s does not drift", nodeClaim.Name)) + Consistently(func(g Gomega) { + g.Expect(env.Client.Get(env, client.ObjectKeyFromObject(nodeClaim), nodeClaim)).To(Succeed()) + g.Expect(nodeClaim.StatusConditions().GetCondition(corev1beta1.Drifted).IsFalse()).To(BeFalse()) + }, time.Minute*1).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()) diff --git a/test/suites/drift/suite_test.go b/test/suites/drift/suite_test.go index 0deda0d5f60f..29436dcb9aa7 100644 --- a/test/suites/drift/suite_test.go +++ b/test/suites/drift/suite_test.go @@ -719,6 +719,41 @@ var _ = Describe("Drift", func() { env.EventuallyExpectNotFound(pod, node) env.EventuallyExpectHealthyPodCount(selector, numPods) }) + It("should update nodepool-hash and nodepool-hash-version and re-propagates to the NodeClaim", func() { + env.ExpectCreated(dep, nodeClass, nodePool) + env.EventuallyExpectHealthyPodCount(selector, numPods) + nodeClaim := env.EventuallyExpectCreatedNodeClaimCount("==", 1)[0] + err := env.Client.Get(env.Context, client.ObjectKeyFromObject(nodePool), nodePool) + Expect(err).ToNot(HaveOccurred()) + expectedHash := nodeClass.Hash() + + By("expect nodepool and nodeclaim to contain karpenter.sh/nodepool-hash annotation") + 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)) + }).Should(Succeed()) + + nodePool.Annotations = map[string]string{corev1beta1.NodePoolHashAnnotationKey: "test-version-1"} + nodePool.Annotations = map[string]string{corev1beta1.NodePoolHashVersionAnnotationKey: "test-version-1"} + nodeClaim.Annotations = map[string]string{corev1beta1.NodePoolHashAnnotationKey: "test-version-2"} + nodeClaim.Annotations = map[string]string{corev1beta1.NodePoolHashVersionAnnotationKey: "test-version-2"} + + env.ExpectUpdated(nodePool, nodeClaim) + err = env.Client.Get(env.Context, client.ObjectKeyFromObject(nodePool), nodePool) + Expect(err).ToNot(HaveOccurred()) + nodeClaim = env.EventuallyExpectCreatedNodeClaimCount("==", 1)[0] + + // Should expect the NodeClaim not be drifted and contain the controller hash version + env.ConsistentlyExpectNotDrifted(nodeClaim) + 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)) + }).Should(Succeed()) + }) Context("Failure", func() { It("should not continue to drift if a node never registers", func() { // launch a new nodeClaim