From d9bc8514bbf2b2b22e81178289d7fe793c3db29a Mon Sep 17 00:00:00 2001 From: Alex Leites <18728999+tallaxes@users.noreply.github.com> Date: Tue, 14 Jan 2025 18:06:02 +0000 Subject: [PATCH] chore: fix aksnodeclass-hash case (no functional changes) --- pkg/controllers/nodeclass/hash/controller.go | 6 +++--- pkg/controllers/nodeclass/hash/suite_test.go | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/controllers/nodeclass/hash/controller.go b/pkg/controllers/nodeclass/hash/controller.go index c9bb64d0b..a82ed7a3b 100644 --- a/pkg/controllers/nodeclass/hash/controller.go +++ b/pkg/controllers/nodeclass/hash/controller.go @@ -80,9 +80,9 @@ func (c *Controller) Register(_ context.Context, m manager.Manager) error { Complete(reconcile.AsReconciler(m.GetClient(), c)) } -// Updating `AKSNodeClass-hash-version` annotation inside the karpenter controller means a breaking change has been made to the hash calculation. -// `AKSNodeClass-hash` annotation on the AKSNodeClass will be updated, due to the breaking change, making the `AKSNodeClass-hash` on the NodeClaim different from -// AKSNodeClass. Since, we cannot rely on the `AKSNodeClass-hash` on the NodeClaims, due to the breaking change, we will need to re-calculate the hash and update the annotation. +// Updating `aksnodeclass-hash-version` annotation inside the karpenter controller means a breaking change has been made to the hash calculation. +// `aksnodeclass-hash` annotation on the AKSNodeClass will be updated, due to the breaking change, making the `aksnodeclass-hash` on the NodeClaim different from +// AKSNodeClass. Since, we cannot rely on the `aksnodeclass-hash` on the NodeClaims, due to the breaking change, we will need to re-calculate the hash and update the annotation. // For more information on the Drift Hash Versioning: https://github.com/kubernetes-sigs/karpenter/blob/main/designs/drift-hash-versioning.md func (c *Controller) updateNodeClaimHash(ctx context.Context, nodeClass *v1alpha2.AKSNodeClass) error { ncList := &karpv1.NodeClaimList{} diff --git a/pkg/controllers/nodeclass/hash/suite_test.go b/pkg/controllers/nodeclass/hash/suite_test.go index 0fac30d3e..d95f6c916 100644 --- a/pkg/controllers/nodeclass/hash/suite_test.go +++ b/pkg/controllers/nodeclass/hash/suite_test.go @@ -117,7 +117,7 @@ var _ = Describe("NodeClass Hash Controller", func() { Entry("OSDiskSizeGB Drift", &v1alpha2.AKSNodeClass{Spec: v1alpha2.AKSNodeClassSpec{OSDiskSizeGB: lo.ToPtr(int32(100))}}), Entry("Tags Drift", &v1alpha2.AKSNodeClass{Spec: v1alpha2.AKSNodeClassSpec{Tags: map[string]string{"keyTag-test-3": "valueTag-test-3"}}}), ) - It("should update AKSNodeClass-hash-version annotation when the AKSNodeClass-hash-version on the NodeClass does not match with the controller hash version", func() { + It("should update aksnodeclass-hash-version annotation when the aksnodeclass-hash-version on the NodeClass does not match with the controller hash version", func() { nodeClass.Annotations = map[string]string{ v1alpha2.AnnotationAKSNodeClassHash: "abceduefed", v1alpha2.AnnotationAKSNodeClassHashVersion: "test", @@ -128,11 +128,11 @@ var _ = Describe("NodeClass Hash Controller", func() { nodeClass = ExpectExists(ctx, env.Client, nodeClass) expectedHash := nodeClass.Hash() - // Expect AKSNodeClass-hash on the NodeClass to be updated + // Expect aksnodeclass-hash on the NodeClass to be updated Expect(nodeClass.Annotations).To(HaveKeyWithValue(v1alpha2.AnnotationAKSNodeClassHash, expectedHash)) Expect(nodeClass.Annotations).To(HaveKeyWithValue(v1alpha2.AnnotationAKSNodeClassHashVersion, v1alpha2.AKSNodeClassHashVersion)) }) - It("should update AKSNodeClass-hash-versions on all NodeClaims when the AKSNodeClass-hash-version does not match with the controller hash version", func() { + It("should update aksnodeclass-hash-versions on all NodeClaims when the aksnodeclass-hash-version does not match with the controller hash version", func() { nodeClass.Annotations = map[string]string{ v1alpha2.AnnotationAKSNodeClassHash: "abceduefed", v1alpha2.AnnotationAKSNodeClassHashVersion: "test", @@ -178,13 +178,13 @@ var _ = Describe("NodeClass Hash Controller", func() { nodeClaimTwo = ExpectExists(ctx, env.Client, nodeClaimTwo) expectedHash := nodeClass.Hash() - // Expect AKSNodeClass-hash on the NodeClaims to be updated + // Expect aksnodeclass-hash on the NodeClaims to be updated Expect(nodeClaimOne.Annotations).To(HaveKeyWithValue(v1alpha2.AnnotationAKSNodeClassHash, expectedHash)) Expect(nodeClaimOne.Annotations).To(HaveKeyWithValue(v1alpha2.AnnotationAKSNodeClassHashVersion, v1alpha2.AKSNodeClassHashVersion)) Expect(nodeClaimTwo.Annotations).To(HaveKeyWithValue(v1alpha2.AnnotationAKSNodeClassHash, expectedHash)) Expect(nodeClaimTwo.Annotations).To(HaveKeyWithValue(v1alpha2.AnnotationAKSNodeClassHashVersion, v1alpha2.AKSNodeClassHashVersion)) }) - It("should not update AKSNodeClass-hash on all NodeClaims when the AKSNodeClass-hash-version matches the controller hash version", func() { + It("should not update aksnodeclass-hash on all NodeClaims when the aksnodeclass-hash-version matches the controller hash version", func() { nodeClass.Annotations = map[string]string{ v1alpha2.AnnotationAKSNodeClassHash: "abceduefed", v1alpha2.AnnotationAKSNodeClassHashVersion: "test-version", @@ -213,14 +213,14 @@ var _ = Describe("NodeClass Hash Controller", func() { expectedHash := nodeClass.Hash() - // Expect AKSNodeClass-hash on the NodeClass to be updated + // Expect aksnodeclass-hash on the NodeClass to be updated Expect(nodeClass.Annotations).To(HaveKeyWithValue(v1alpha2.AnnotationAKSNodeClassHash, expectedHash)) Expect(nodeClass.Annotations).To(HaveKeyWithValue(v1alpha2.AnnotationAKSNodeClassHashVersion, v1alpha2.AKSNodeClassHashVersion)) - // Expect AKSNodeClass-hash on the NodeClaims to stay the same + // Expect aksnodeclass-hash on the NodeClaims to stay the same Expect(nodeClaim.Annotations).To(HaveKeyWithValue(v1alpha2.AnnotationAKSNodeClassHash, "1234564654")) Expect(nodeClaim.Annotations).To(HaveKeyWithValue(v1alpha2.AnnotationAKSNodeClassHashVersion, v1alpha2.AKSNodeClassHashVersion)) }) - It("should not update AKSNodeClass-hash on the NodeClaim if it's drifted and the AKSNodeClass-hash-version does not match the controller hash version", func() { + It("should not update aksnodeclass-hash on the NodeClaim if it's drifted and the aksnodeclass-hash-version does not match the controller hash version", func() { nodeClass.Annotations = map[string]string{ v1alpha2.AnnotationAKSNodeClassHash: "abceduefed", v1alpha2.AnnotationAKSNodeClassHashVersion: "test", @@ -247,7 +247,7 @@ var _ = Describe("NodeClass Hash Controller", func() { ExpectObjectReconciled(ctx, env.Client, hashController, nodeClass) nodeClaim = ExpectExists(ctx, env.Client, nodeClaim) - // Expect AKSNodeClass-hash on the NodeClaims to stay the same + // Expect aksnodeclass-hash on the NodeClaims to stay the same Expect(nodeClaim.Annotations).To(HaveKeyWithValue(v1alpha2.AnnotationAKSNodeClassHash, "123456")) Expect(nodeClaim.Annotations).To(HaveKeyWithValue(v1alpha2.AnnotationAKSNodeClassHashVersion, v1alpha2.AKSNodeClassHashVersion)) })