Skip to content

Commit

Permalink
chore: Backport conversion webhooks changes for v0.37.x (#1553)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathan Innis <jonathan.innis.ji@gmail.com>
  • Loading branch information
engedaam and jonathan-innis authored Aug 12, 2024
1 parent eec97e4 commit 579dd36
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 65 deletions.
1 change: 1 addition & 0 deletions pkg/apis/v1/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (
NodePoolHashAnnotationKey = Group + "/nodepool-hash"
NodePoolHashVersionAnnotationKey = Group + "/nodepool-hash-version"
KubeletCompatibilityAnnotationKey = CompatibilityGroup + "/v1beta1-kubelet-conversion"
NodeClassReferenceAnnotationKey = CompatibilityGroup + "/v1beta1-nodeclass-reference"
NodeClaimTerminationTimestampAnnotationKey = Group + "/nodeclaim-termination-timestamp"
)

Expand Down
44 changes: 27 additions & 17 deletions pkg/apis/v1/nodeclaim_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/samber/lo"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"knative.dev/pkg/apis"

Expand All @@ -38,11 +37,17 @@ func (in *NodeClaim) ConvertTo(ctx context.Context, to apis.Convertible) error {
v1beta1NC := to.(*v1beta1.NodeClaim)
v1beta1NC.ObjectMeta = in.ObjectMeta

in.Status.convertTo((&v1beta1NC.Status))
return in.Spec.convertTo(ctx, &v1beta1NC.Spec, in.Annotations[KubeletCompatibilityAnnotationKey])
in.Status.convertTo(&v1beta1NC.Status)
if err := in.Spec.convertTo(&v1beta1NC.Spec, in.Annotations[KubeletCompatibilityAnnotationKey], in.Annotations[NodeClassReferenceAnnotationKey]); err != nil {
return err
}
// Remove the annotations from the v1beta1 NodeClaim on the convert back
delete(v1beta1NC.Annotations, KubeletCompatibilityAnnotationKey)
delete(v1beta1NC.Annotations, NodeClassReferenceAnnotationKey)
return nil
}

func (in *NodeClaimSpec) convertTo(ctx context.Context, v1beta1nc *v1beta1.NodeClaimSpec, kubeletAnnotation string) error {
func (in *NodeClaimSpec) convertTo(v1beta1nc *v1beta1.NodeClaimSpec, kubeletAnnotation, nodeClassReferenceAnnotation string) error {
v1beta1nc.Taints = in.Taints
v1beta1nc.StartupTaints = in.StartupTaints
v1beta1nc.Resources = v1beta1.ResourceRequirements(in.Resources)
Expand All @@ -56,18 +61,16 @@ func (in *NodeClaimSpec) convertTo(ctx context.Context, v1beta1nc *v1beta1.NodeC
MinValues: v1Requirements.MinValues,
}
})

if in.NodeClassRef != nil {
nodeclass, found := lo.Find(injection.GetNodeClasses(ctx), func(nc schema.GroupVersionKind) bool {
return nc.Kind == in.NodeClassRef.Kind && nc.Group == in.NodeClassRef.Group
})
v1beta1nc.NodeClassRef = &v1beta1.NodeClassReference{
Kind: in.NodeClassRef.Kind,
Name: in.NodeClassRef.Name,
APIVersion: lo.Ternary(found, nodeclass.GroupVersion().String(), ""),
// Convert the NodeClassReference depending on whether the annotation exists
v1beta1nc.NodeClassRef = &v1beta1.NodeClassReference{}
if nodeClassReferenceAnnotation != "" {
if err := json.Unmarshal([]byte(nodeClassReferenceAnnotation), v1beta1nc.NodeClassRef); err != nil {
return fmt.Errorf("unmarshaling nodeClassRef annotation, %w", err)
}
} else {
v1beta1nc.NodeClassRef.Name = in.NodeClassRef.Name
v1beta1nc.NodeClassRef.Kind = in.NodeClassRef.Kind
}

if kubeletAnnotation != "" {
v1beta1kubelet := &v1beta1.KubeletConfiguration{}
err := json.Unmarshal([]byte(kubeletAnnotation), v1beta1kubelet)
Expand Down Expand Up @@ -103,6 +106,13 @@ func (in *NodeClaim) ConvertFrom(ctx context.Context, from apis.Convertible) err
} else {
in.Annotations = lo.Assign(in.Annotations, map[string]string{KubeletCompatibilityAnnotationKey: kubeletAnnotation})
}
nodeClassRefAnnotation, err := json.Marshal(v1beta1NC.Spec.NodeClassRef)
if err != nil {
return fmt.Errorf("marshaling nodeClassRef annotation, %w", err)
}
in.Annotations = lo.Assign(in.Annotations, map[string]string{
NodeClassReferenceAnnotationKey: string(nodeClassRefAnnotation),
})
return in.setExpireAfter(ctx, v1beta1NC)
}

Expand Down Expand Up @@ -141,11 +151,11 @@ func (in *NodeClaimSpec) convertFrom(ctx context.Context, v1beta1nc *v1beta1.Nod
}
})

nodeclasses := injection.GetNodeClasses(ctx)
defaultNodeClassGVK := injection.GetNodeClasses(ctx)[0]
in.NodeClassRef = &NodeClassReference{
Name: v1beta1nc.NodeClassRef.Name,
Kind: lo.Ternary(v1beta1nc.NodeClassRef.Kind == "", nodeclasses[0].Kind, v1beta1nc.NodeClassRef.Kind),
Group: lo.Ternary(v1beta1nc.NodeClassRef.APIVersion == "", nodeclasses[0].Group, strings.Split(v1beta1nc.NodeClassRef.APIVersion, "/")[0]),
Kind: lo.Ternary(v1beta1nc.NodeClassRef.Kind == "", defaultNodeClassGVK.Kind, v1beta1nc.NodeClassRef.Kind),
Group: lo.Ternary(v1beta1nc.NodeClassRef.APIVersion == "", defaultNodeClassGVK.Group, strings.Split(v1beta1nc.NodeClassRef.APIVersion, "/")[0]),
}

if v1beta1nc.Kubelet != nil {
Expand Down
41 changes: 32 additions & 9 deletions pkg/apis/v1/nodeclaim_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,30 @@ var _ = Describe("Convert v1 to v1beta1 NodeClaim API", func() {
Group: object.GVK(&v1alpha1.TestNodeClass{}).Group,
}
Expect(v1nodeclaim.ConvertTo(ctx, v1beta1nodeclaim)).To(Succeed())
Expect(v1beta1nodeclaim.Spec.NodeClassRef.Kind).To(Equal(v1nodeclaim.Spec.NodeClassRef.Kind))
Expect(v1beta1nodeclaim.Spec.NodeClassRef.Name).To(Equal(v1nodeclaim.Spec.NodeClassRef.Name))
Expect(v1beta1nodeclaim.Spec.NodeClassRef.APIVersion).To(Equal(cloudProvider.NodeClassGroupVersionKind[0].GroupVersion().String()))
Expect(v1beta1nodeclaim.Spec.NodeClassRef.Kind).To(Equal(v1nodeclaim.Spec.NodeClassRef.Kind))
Expect(v1beta1nodeclaim.Spec.NodeClassRef.APIVersion).To(BeEmpty())
})
It("should not include APIVersion for v1beta1 if Group and Kind is not in the supported nodeclass", func() {
It("should retain NodeClassReference details when the karpenter.sh/v1beta1-nodeclass-reference annotation exists", func() {
nodeClassReference := &v1beta1.NodeClassReference{
APIVersion: object.GVK(&v1alpha1.TestNodeClass{}).GroupVersion().String(),
Name: "nodeclass-test",
Kind: object.GVK(&v1alpha1.TestNodeClass{}).Kind,
}
nodeClassAnnotation, err := json.Marshal(nodeClassReference)
Expect(err).ToNot(HaveOccurred())
v1nodeclaim.Annotations = lo.Assign(map[string]string{
NodeClassReferenceAnnotationKey: string(nodeClassAnnotation),
})
v1nodeclaim.Spec.NodeClassRef = &NodeClassReference{
Kind: "test-kind",
Kind: object.GVK(&v1alpha1.TestNodeClass{}).Kind,
Name: "nodeclass-test",
Group: "testgroup.sh",
Group: object.GVK(&v1alpha1.TestNodeClass{}).Group,
}
Expect(v1nodeclaim.ConvertTo(ctx, v1beta1nodeclaim)).To(Succeed())
Expect(v1beta1nodeclaim.Spec.NodeClassRef.Kind).To(Equal(v1nodeclaim.Spec.NodeClassRef.Kind))
Expect(v1beta1nodeclaim.Spec.NodeClassRef.Name).To(Equal(v1nodeclaim.Spec.NodeClassRef.Name))
Expect(v1beta1nodeclaim.Spec.NodeClassRef.APIVersion).To(Equal(""))
Expect(v1beta1nodeclaim.Spec.NodeClassRef.Name).To(Equal(nodeClassReference.Name))
Expect(v1beta1nodeclaim.Spec.NodeClassRef.Kind).To(Equal(nodeClassReference.Kind))
Expect(v1beta1nodeclaim.Spec.NodeClassRef.APIVersion).To(Equal(nodeClassReference.APIVersion))
})
})
})
Expand Down Expand Up @@ -325,7 +335,12 @@ var _ = Describe("Convert V1beta1 to V1 NodeClaim API", func() {
It("should convert v1beta1 nodeclaim metadata", func() {
v1beta1nodeclaim.ObjectMeta = test.ObjectMeta()
Expect(v1nodeclaim.ConvertFrom(ctx, v1beta1nodeclaim)).To(Succeed())
v1beta1nodeclaim.Annotations = map[string]string{}

nodeClassReferenceAnnotation, err := json.Marshal(v1beta1nodeclaim.Spec.NodeClassRef)
Expect(err).ToNot(HaveOccurred())
v1beta1nodeclaim.Annotations = map[string]string{
NodeClassReferenceAnnotationKey: string(nodeClassReferenceAnnotation),
}
Expect(v1nodeclaim.ObjectMeta).To(BeEquivalentTo(v1beta1nodeclaim.ObjectMeta))
})
Context("NodeClaim Spec", func() {
Expand Down Expand Up @@ -450,19 +465,27 @@ var _ = Describe("Convert V1beta1 to V1 NodeClaim API", func() {
Name: "nodeclass-test",
APIVersion: "testgroup.sh/testversion",
}
nodeClassReferenceAnnotation, err := json.Marshal(v1beta1nodeclaim.Spec.NodeClassRef)
Expect(err).ToNot(HaveOccurred())

Expect(v1nodeclaim.ConvertFrom(ctx, v1beta1nodeclaim)).To(Succeed())
Expect(v1nodeclaim.Spec.NodeClassRef.Kind).To(Equal(v1beta1nodeclaim.Spec.NodeClassRef.Kind))
Expect(v1nodeclaim.Spec.NodeClassRef.Name).To(Equal(v1beta1nodeclaim.Spec.NodeClassRef.Name))
Expect(v1nodeclaim.Spec.NodeClassRef.Group).To(Equal("testgroup.sh"))
Expect(v1nodeclaim.Annotations).To(HaveKeyWithValue(NodeClassReferenceAnnotationKey, string(nodeClassReferenceAnnotation)))
})
It("should set default nodeclass group and kind on v1beta1 nodeclassRef", func() {
v1beta1nodeclaim.Spec.NodeClassRef = &v1beta1.NodeClassReference{
Name: "nodeclass-test",
}
nodeClassReferenceAnnotation, err := json.Marshal(v1beta1nodeclaim.Spec.NodeClassRef)
Expect(err).ToNot(HaveOccurred())

Expect(v1nodeclaim.ConvertFrom(ctx, v1beta1nodeclaim)).To(Succeed())
Expect(v1nodeclaim.Spec.NodeClassRef.Kind).To(Equal(cloudProvider.NodeClassGroupVersionKind[0].Kind))
Expect(v1nodeclaim.Spec.NodeClassRef.Name).To(Equal(v1beta1nodeclaim.Spec.NodeClassRef.Name))
Expect(v1nodeclaim.Spec.NodeClassRef.Group).To(Equal(cloudProvider.NodeClassGroupVersionKind[0].Group))
Expect(v1nodeclaim.Annotations).To(HaveKeyWithValue(NodeClassReferenceAnnotationKey, string(nodeClassReferenceAnnotation)))
})
})
})
Expand Down
59 changes: 28 additions & 31 deletions pkg/apis/v1/nodepool_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ import (
"context"
"encoding/json"
"fmt"
"sort"
"strings"
"time"

"github.com/samber/lo"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/pkg/apis"

"sigs.k8s.io/karpenter/pkg/apis/v1beta1"
Expand All @@ -40,17 +38,23 @@ func (in *NodePool) ConvertTo(ctx context.Context, to apis.Convertible) error {

// Convert v1 status
v1beta1NP.Status.Resources = in.Status.Resources
return in.Spec.convertTo(ctx, &v1beta1NP.Spec, in.Annotations[KubeletCompatibilityAnnotationKey])
if err := in.Spec.convertTo(&v1beta1NP.Spec, in.Annotations[KubeletCompatibilityAnnotationKey], in.Annotations[NodeClassReferenceAnnotationKey]); err != nil {
return err
}
// Remove the annotations from the v1beta1 NodeClaim on the convert back
delete(v1beta1NP.Annotations, KubeletCompatibilityAnnotationKey)
delete(v1beta1NP.Annotations, NodeClassReferenceAnnotationKey)
return nil
}

func (in *NodePoolSpec) convertTo(ctx context.Context, v1beta1np *v1beta1.NodePoolSpec, kubeletAnnotation string) error {
func (in *NodePoolSpec) convertTo(v1beta1np *v1beta1.NodePoolSpec, kubeletAnnotation, nodeClassReferenceAnnotation string) error {
v1beta1np.Weight = in.Weight
v1beta1np.Limits = v1beta1.Limits(in.Limits)
in.Disruption.convertTo(&v1beta1np.Disruption)
// Set the expireAfter to the nodeclaim template's expireAfter.
// Don't convert terminationGracePeriod, as this is only included in v1.
v1beta1np.Disruption.ExpireAfter = v1beta1.NillableDuration(in.Template.Spec.ExpireAfter)
return in.Template.convertTo(ctx, &v1beta1np.Template, kubeletAnnotation)
return in.Template.convertTo(&v1beta1np.Template, kubeletAnnotation, nodeClassReferenceAnnotation)
}

func (in *Disruption) convertTo(v1beta1np *v1beta1.Disruption) {
Expand All @@ -68,7 +72,7 @@ func (in *Disruption) convertTo(v1beta1np *v1beta1.Disruption) {
})
}

func (in *NodeClaimTemplate) convertTo(ctx context.Context, v1beta1np *v1beta1.NodeClaimTemplate, kubeletAnnotation string) error {
func (in *NodeClaimTemplate) convertTo(v1beta1np *v1beta1.NodeClaimTemplate, kubeletAnnotation, nodeClassReferenceAnnotation string) error {
v1beta1np.ObjectMeta = v1beta1.ObjectMeta(in.ObjectMeta)
v1beta1np.Spec.Taints = in.Spec.Taints
v1beta1np.Spec.StartupTaints = in.Spec.StartupTaints
Expand All @@ -82,28 +86,16 @@ func (in *NodeClaimTemplate) convertTo(ctx context.Context, v1beta1np *v1beta1.N
MinValues: v1Requirements.MinValues,
}
})

nodeClasses := injection.GetNodeClasses(ctx)
// We are sorting the supported nodeclass, so that we are able to consistently find the same GVK,
// if multiple version of a nodeclass are supported
sort.Slice(nodeClasses, func(i int, j int) bool {
if nodeClasses[i].Group != nodeClasses[j].Group {
return nodeClasses[i].Group < nodeClasses[j].Group
// Convert the NodeClassReference depending on whether the annotation exists
v1beta1np.Spec.NodeClassRef = &v1beta1.NodeClassReference{}
if nodeClassReferenceAnnotation != "" {
if err := json.Unmarshal([]byte(nodeClassReferenceAnnotation), v1beta1np.Spec.NodeClassRef); err != nil {
return fmt.Errorf("unmarshaling nodeClassRef annotation, %w", err)
}
if nodeClasses[i].Version != nodeClasses[j].Version {
return nodeClasses[i].Version < nodeClasses[j].Version
}
return nodeClasses[i].Kind < nodeClasses[j].Kind
})
matchingNodeClass, found := lo.Find(nodeClasses, func(nc schema.GroupVersionKind) bool {
return nc.Kind == in.Spec.NodeClassRef.Kind && nc.Group == in.Spec.NodeClassRef.Group
})
v1beta1np.Spec.NodeClassRef = &v1beta1.NodeClassReference{
Kind: in.Spec.NodeClassRef.Kind,
Name: in.Spec.NodeClassRef.Name,
APIVersion: lo.Ternary(found, matchingNodeClass.GroupVersion().String(), ""),
} else {
v1beta1np.Spec.NodeClassRef.Name = in.Spec.NodeClassRef.Name
v1beta1np.Spec.NodeClassRef.Kind = in.Spec.NodeClassRef.Kind
}

if kubeletAnnotation != "" {
v1beta1kubelet := &v1beta1.KubeletConfiguration{}
err := json.Unmarshal([]byte(kubeletAnnotation), v1beta1kubelet)
Expand Down Expand Up @@ -133,6 +125,13 @@ func (in *NodePool) ConvertFrom(ctx context.Context, v1beta1np apis.Convertible)
} else {
in.Annotations = lo.Assign(in.Annotations, map[string]string{KubeletCompatibilityAnnotationKey: kubeletAnnotation})
}
nodeClassRefAnnotation, err := json.Marshal(v1beta1NP.Spec.Template.Spec.NodeClassRef)
if err != nil {
return fmt.Errorf("marshaling nodeClassRef annotation, %w", err)
}
in.Annotations = lo.Assign(in.Annotations, map[string]string{
NodeClassReferenceAnnotationKey: string(nodeClassRefAnnotation),
})
return nil
}

Expand Down Expand Up @@ -174,20 +173,18 @@ func (in *NodeClaimTemplate) convertFrom(ctx context.Context, v1beta1np *v1beta1
}
})

nodeclasses := injection.GetNodeClasses(ctx)
defaultNodeClassGVK := injection.GetNodeClasses(ctx)[0]
in.Spec.NodeClassRef = &NodeClassReference{
Name: v1beta1np.Spec.NodeClassRef.Name,
Kind: lo.Ternary(v1beta1np.Spec.NodeClassRef.Kind == "", nodeclasses[0].Kind, v1beta1np.Spec.NodeClassRef.Kind),
Group: lo.Ternary(v1beta1np.Spec.NodeClassRef.APIVersion == "", nodeclasses[0].Group, strings.Split(v1beta1np.Spec.NodeClassRef.APIVersion, "/")[0]),
Kind: lo.Ternary(v1beta1np.Spec.NodeClassRef.Kind == "", defaultNodeClassGVK.Kind, v1beta1np.Spec.NodeClassRef.Kind),
Group: lo.Ternary(v1beta1np.Spec.NodeClassRef.APIVersion == "", defaultNodeClassGVK.Group, strings.Split(v1beta1np.Spec.NodeClassRef.APIVersion, "/")[0]),
}

if v1beta1np.Spec.Kubelet != nil {
kubelet, err := json.Marshal(v1beta1np.Spec.Kubelet)
if err != nil {
return "", fmt.Errorf("marshaling kubelet config annotation, %w", err)
}
return string(kubelet), nil
}

return "", nil
}
34 changes: 26 additions & 8 deletions pkg/apis/v1/nodepool_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,30 @@ var _ = Describe("Convert V1 to V1beta1 NodePool API", func() {
Group: object.GVK(&v1alpha1.TestNodeClass{}).Group,
}
Expect(v1nodepool.ConvertTo(ctx, v1beta1nodepool)).To(Succeed())
Expect(v1beta1nodepool.Spec.Template.Spec.NodeClassRef.Kind).To(Equal(v1nodepool.Spec.Template.Spec.NodeClassRef.Kind))
Expect(v1beta1nodepool.Spec.Template.Spec.NodeClassRef.Name).To(Equal(v1nodepool.Spec.Template.Spec.NodeClassRef.Name))
Expect(v1beta1nodepool.Spec.Template.Spec.NodeClassRef.APIVersion).To(Equal(cloudProvider.NodeClassGroupVersionKind[0].GroupVersion().String()))
Expect(v1beta1nodepool.Spec.Template.Spec.NodeClassRef.Kind).To(Equal(v1nodepool.Spec.Template.Spec.NodeClassRef.Kind))
Expect(v1beta1nodepool.Spec.Template.Spec.NodeClassRef.APIVersion).To(BeEmpty())
})
It("should not include APIVersion for v1beta1 if Group and Kind is not in the supported nodeclass", func() {
It("should retain NodeClassReference details when the karpenter.sh/v1beta1-nodeclass-reference annotation exists", func() {
nodeClassReference := &v1beta1.NodeClassReference{
APIVersion: object.GVK(&v1alpha1.TestNodeClass{}).GroupVersion().String(),
Name: "nodeclass-test",
Kind: object.GVK(&v1alpha1.TestNodeClass{}).Kind,
}
nodeClassAnnotation, err := json.Marshal(nodeClassReference)
Expect(err).ToNot(HaveOccurred())
v1nodepool.Annotations = lo.Assign(map[string]string{
NodeClassReferenceAnnotationKey: string(nodeClassAnnotation),
})
v1nodepool.Spec.Template.Spec.NodeClassRef = &NodeClassReference{
Kind: "test-kind",
Kind: object.GVK(&v1alpha1.TestNodeClass{}).Kind,
Name: "nodeclass-test",
Group: "testgroup.sh",
Group: object.GVK(&v1alpha1.TestNodeClass{}).Group,
}
Expect(v1nodepool.ConvertTo(ctx, v1beta1nodepool)).To(Succeed())
Expect(v1beta1nodepool.Spec.Template.Spec.NodeClassRef.Kind).To(Equal(v1nodepool.Spec.Template.Spec.NodeClassRef.Kind))
Expect(v1beta1nodepool.Spec.Template.Spec.NodeClassRef.Name).To(Equal(v1nodepool.Spec.Template.Spec.NodeClassRef.Name))
Expect(v1beta1nodepool.Spec.Template.Spec.NodeClassRef.APIVersion).To(Equal(""))
Expect(v1beta1nodepool.Spec.Template.Spec.NodeClassRef.Name).To(Equal(nodeClassReference.Name))
Expect(v1beta1nodepool.Spec.Template.Spec.NodeClassRef.Kind).To(Equal(nodeClassReference.Kind))
Expect(v1beta1nodepool.Spec.Template.Spec.NodeClassRef.APIVersion).To(Equal(nodeClassReference.APIVersion))
})
})
})
Expand Down Expand Up @@ -449,19 +459,27 @@ var _ = Describe("Convert V1beta1 to V1 NodePool API", func() {
Name: "nodeclass-test",
APIVersion: "testgroup.sh/testversion",
}
nodeClassReferenceAnnotation, err := json.Marshal(v1beta1nodepool.Spec.Template.Spec.NodeClassRef)
Expect(err).ToNot(HaveOccurred())

Expect(v1nodepool.ConvertFrom(ctx, v1beta1nodepool)).To(Succeed())
Expect(v1nodepool.Spec.Template.Spec.NodeClassRef.Kind).To(Equal(v1beta1nodepool.Spec.Template.Spec.NodeClassRef.Kind))
Expect(v1nodepool.Spec.Template.Spec.NodeClassRef.Name).To(Equal(v1beta1nodepool.Spec.Template.Spec.NodeClassRef.Name))
Expect(v1nodepool.Spec.Template.Spec.NodeClassRef.Group).To(Equal("testgroup.sh"))
Expect(v1nodepool.Annotations).To(HaveKeyWithValue(NodeClassReferenceAnnotationKey, string(nodeClassReferenceAnnotation)))
})
It("should set default nodeclass group and kind on v1beta1 nodeclassRef", func() {
v1beta1nodepool.Spec.Template.Spec.NodeClassRef = &v1beta1.NodeClassReference{
Name: "nodeclass-test",
}
nodeClassReferenceAnnotation, err := json.Marshal(v1beta1nodepool.Spec.Template.Spec.NodeClassRef)
Expect(err).ToNot(HaveOccurred())

Expect(v1nodepool.ConvertFrom(ctx, v1beta1nodepool)).To(Succeed())
Expect(v1nodepool.Spec.Template.Spec.NodeClassRef.Kind).To(Equal(cloudProvider.NodeClassGroupVersionKind[0].Kind))
Expect(v1nodepool.Spec.Template.Spec.NodeClassRef.Name).To(Equal(v1beta1nodepool.Spec.Template.Spec.NodeClassRef.Name))
Expect(v1nodepool.Spec.Template.Spec.NodeClassRef.Group).To(Equal(cloudProvider.NodeClassGroupVersionKind[0].Group))
Expect(v1nodepool.Annotations).To(HaveKeyWithValue(NodeClassReferenceAnnotationKey, string(nodeClassReferenceAnnotation)))
})
})
})
Expand Down

0 comments on commit 579dd36

Please sign in to comment.