From 4fc4749486b6a94c5f7cf941b1d03546f9ba7eb9 Mon Sep 17 00:00:00 2001 From: Reed Schalo Date: Tue, 24 Sep 2024 17:44:00 -0700 Subject: [PATCH] chore: Drop stored version annotation 33 (#1712) --- pkg/apis/v1/labels.go | 1 + pkg/apis/v1/nodeclaim_conversion.go | 2 ++ pkg/apis/v1/nodeclaim_conversion_test.go | 13 +++++++++++++ pkg/apis/v1/nodepool_conversion.go | 2 ++ pkg/apis/v1/nodepool_conversion_test.go | 13 +++++++++++++ 5 files changed, 31 insertions(+) diff --git a/pkg/apis/v1/labels.go b/pkg/apis/v1/labels.go index f537e3fb48..82c475900e 100644 --- a/pkg/apis/v1/labels.go +++ b/pkg/apis/v1/labels.go @@ -47,6 +47,7 @@ const ( KubeletCompatibilityAnnotationKey = CompatibilityGroup + "/v1beta1-kubelet-conversion" NodeClassReferenceAnnotationKey = CompatibilityGroup + "/v1beta1-nodeclass-reference" NodeClaimTerminationTimestampAnnotationKey = Group + "/nodeclaim-termination-timestamp" + StoredVersionMigratedKey = Group + "/stored-version-migrated" ) // Karpenter specific finalizers diff --git a/pkg/apis/v1/nodeclaim_conversion.go b/pkg/apis/v1/nodeclaim_conversion.go index 1873d5c54b..880ba058a5 100644 --- a/pkg/apis/v1/nodeclaim_conversion.go +++ b/pkg/apis/v1/nodeclaim_conversion.go @@ -45,6 +45,8 @@ func (in *NodeClaim) ConvertTo(ctx context.Context, to apis.Convertible) error { // Remove the annotations from the v1beta1 NodeClaim on the convert back delete(v1beta1NC.Annotations, KubeletCompatibilityAnnotationKey) delete(v1beta1NC.Annotations, NodeClassReferenceAnnotationKey) + // Drop the annotation so when roundtripping from v1, to v1beta1, and back to v1 the migration resource controller can re-annotate it + delete(v1beta1NC.Annotations, StoredVersionMigratedKey) return nil } diff --git a/pkg/apis/v1/nodeclaim_conversion_test.go b/pkg/apis/v1/nodeclaim_conversion_test.go index 8fbf5605ed..be4ee67bab 100644 --- a/pkg/apis/v1/nodeclaim_conversion_test.go +++ b/pkg/apis/v1/nodeclaim_conversion_test.go @@ -98,6 +98,19 @@ var _ = Describe("Convert v1 to v1beta1 NodeClaim API", func() { v1beta1nodeclaim.Annotations = nil Expect(v1beta1nodeclaim.ObjectMeta).To(BeEquivalentTo(v1nodeclaim.ObjectMeta)) }) + It("should drop v1 specific annotations on conversion", func() { + v1nodeclaim.ObjectMeta = test.ObjectMeta( + metav1.ObjectMeta{ + Annotations: map[string]string{ + StoredVersionMigratedKey: "true", + }, + }, + ) + v1nc := v1nodeclaim.DeepCopy() + Expect(v1nodeclaim.ConvertTo(ctx, v1beta1nodeclaim)).To(Succeed()) + Expect(v1nc.Annotations).To(HaveKey(StoredVersionMigratedKey)) + Expect(v1beta1nodeclaim.Annotations).NotTo(HaveKey(StoredVersionMigratedKey)) + }) Context("NodeClaim Spec", func() { It("should convert v1 nodeclaim taints", func() { v1nodeclaim.Spec.Taints = []v1.Taint{ diff --git a/pkg/apis/v1/nodepool_conversion.go b/pkg/apis/v1/nodepool_conversion.go index 5af45f03d0..3f4f429af4 100644 --- a/pkg/apis/v1/nodepool_conversion.go +++ b/pkg/apis/v1/nodepool_conversion.go @@ -42,6 +42,8 @@ func (in *NodePool) ConvertTo(ctx context.Context, to apis.Convertible) error { // Remove the annotations from the v1beta1 NodeClaim on the convert back delete(v1beta1NP.Annotations, KubeletCompatibilityAnnotationKey) delete(v1beta1NP.Annotations, NodeClassReferenceAnnotationKey) + // Drop the annotation so when roundtripping from v1, to v1beta1, and back to v1 the migration resource controller can re-annotate it + delete(v1beta1NP.Annotations, StoredVersionMigratedKey) return nil } diff --git a/pkg/apis/v1/nodepool_conversion_test.go b/pkg/apis/v1/nodepool_conversion_test.go index 390491843f..04114eb018 100644 --- a/pkg/apis/v1/nodepool_conversion_test.go +++ b/pkg/apis/v1/nodepool_conversion_test.go @@ -76,6 +76,19 @@ var _ = Describe("Convert V1 to V1beta1 NodePool API", func() { Expect(v1nodepool.ConvertTo(ctx, v1beta1nodepool)).To(Succeed()) Expect(v1beta1nodepool.ObjectMeta).To(BeEquivalentTo(v1nodepool.ObjectMeta)) }) + It("should drop v1 specific annotations on conversion", func() { + v1nodepool.ObjectMeta = test.ObjectMeta( + metav1.ObjectMeta{ + Annotations: map[string]string{ + StoredVersionMigratedKey: "true", + }, + }, + ) + v1np := v1nodepool.DeepCopy() + Expect(v1nodepool.ConvertTo(ctx, v1beta1nodepool)).To(Succeed()) + Expect(v1np.Annotations).To(HaveKey(StoredVersionMigratedKey)) + Expect(v1beta1nodepool.Annotations).NotTo(HaveKey(StoredVersionMigratedKey)) + }) Context("NodePool Spec", func() { It("should convert v1 nodepool weights", func() { v1nodepool.Spec.Weight = lo.ToPtr(int32(62))