diff --git a/pkg/apis/v1/labels.go b/pkg/apis/v1/labels.go index 46d28573b..e404f5682 100644 --- a/pkg/apis/v1/labels.go +++ b/pkg/apis/v1/labels.go @@ -49,6 +49,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 8deec9276..bc0989171 100644 --- a/pkg/apis/v1/nodeclaim_conversion.go +++ b/pkg/apis/v1/nodeclaim_conversion.go @@ -47,6 +47,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 46aa11894..ab4fdde9c 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 ffb59a584..d817fdfd3 100644 --- a/pkg/apis/v1/nodepool_conversion.go +++ b/pkg/apis/v1/nodepool_conversion.go @@ -44,6 +44,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 305b58f7c..90bf46d79 100644 --- a/pkg/apis/v1/nodepool_conversion_test.go +++ b/pkg/apis/v1/nodepool_conversion_test.go @@ -78,6 +78,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))