Skip to content

Commit

Permalink
chore: Drop stored version annotation 35 (#1710)
Browse files Browse the repository at this point in the history
  • Loading branch information
rschalo authored Sep 25, 2024
1 parent b0bb434 commit 9e0bd63
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/apis/v1/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/v1/nodeclaim_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/apis/v1/nodeclaim_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/v1/nodepool_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/apis/v1/nodepool_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 9e0bd63

Please sign in to comment.