Skip to content

Commit

Permalink
chore: Update NodeClassReference to have fieldname nodeClassRef (#4741
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jonathan-innis authored Oct 3, 2023
1 parent b5813cf commit c91f091
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 40 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/PuerkitoBio/goquery v1.8.1
github.com/avast/retry-go v3.0.0+incompatible
github.com/aws/aws-sdk-go v1.45.19
github.com/aws/karpenter-core v0.31.0
github.com/aws/karpenter-core v0.31.1-0.20231003150228-d494b7d6d54f
github.com/aws/karpenter/tools/kompat v0.0.0-20230915222222-abfbf5fa3644
github.com/imdario/mergo v0.3.16
github.com/mitchellh/hashstructure/v2 v2.0.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHS
github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
github.com/aws/aws-sdk-go v1.45.19 h1:+4yXWhldhCVXWFOQRF99ZTJ92t4DtoHROZIbN7Ujk/U=
github.com/aws/aws-sdk-go v1.45.19/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/karpenter-core v0.31.0 h1:3EVFl6luDqMmucaJFPI8dGgwpajxNeIOuB6BymKnTOo=
github.com/aws/karpenter-core v0.31.0/go.mod h1:gYAB79gHhfCDNa1MnN/6C7TJ9QRgpzcNf8evekHn6Bk=
github.com/aws/karpenter-core v0.31.1-0.20231003150228-d494b7d6d54f h1:yl73U8hrilKuHnGu1dqSv3H/r+3zXA0z8iJYDGbjGxE=
github.com/aws/karpenter-core v0.31.1-0.20231003150228-d494b7d6d54f/go.mod h1:4wXCSTj97gOWkWeB4D6LjWQMoqldrI8fo4tUOAhYTDs=
github.com/aws/karpenter/tools/kompat v0.0.0-20230915222222-abfbf5fa3644 h1:M1fxGlOfvSqFYI01HL2zzvomy8e7LiTHk77KDuChWZQ=
github.com/aws/karpenter/tools/kompat v0.0.0-20230915222222-abfbf5fa3644/go.mod h1:l/TIBsaCx/IrOr0Xvlj/cHLOf05QzuQKEZ1hx2XWmfU=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
Expand Down
14 changes: 9 additions & 5 deletions pkg/apis/crds/karpenter.sh_nodeclaims.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ spec:
name: NodePool
priority: 1
type: string
- jsonPath: .spec.nodeClass.name
- jsonPath: .spec.nodeClassRef.name
name: NodeClass
priority: 1
type: string
Expand Down Expand Up @@ -160,9 +160,9 @@ spec:
system daemons and kernel memory.
type: object
type: object
nodeClass:
description: NodeClass is a reference to an object that defines provider
specific configuration
nodeClassRef:
description: NodeClassRef is a reference to an object that defines
provider specific configuration
properties:
apiVersion:
description: API version of the referent
Expand Down Expand Up @@ -282,7 +282,7 @@ spec:
type: object
type: array
required:
- nodeClass
- nodeClassRef
- requirements
type: object
status:
Expand Down Expand Up @@ -341,6 +341,10 @@ spec:
- type
type: object
type: array
imageID:
description: ImageID is an identifier for the image that runs on the
node
type: string
nodeName:
description: NodeName is the name of the corresponding node object
type: string
Expand Down
10 changes: 5 additions & 5 deletions pkg/apis/crds/karpenter.sh_nodepools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
scope: Cluster
versions:
- additionalPrinterColumns:
- jsonPath: .spec.template.spec.nodeClass.name
- jsonPath: .spec.template.spec.nodeClassRef.name
name: NodeClass
type: string
- jsonPath: .spec.weight
Expand Down Expand Up @@ -219,9 +219,9 @@ spec:
for OS system daemons and kernel memory.
type: object
type: object
nodeClass:
description: NodeClass is a reference to an object that defines
provider specific configuration
nodeClassRef:
description: NodeClassRef is a reference to an object that
defines provider specific configuration
properties:
apiVersion:
description: API version of the referent
Expand Down Expand Up @@ -351,7 +351,7 @@ spec:
type: object
type: array
required:
- nodeClass
- nodeClassRef
- requirements
type: object
type: object
Expand Down
10 changes: 5 additions & 5 deletions pkg/cloudprovider/cloudprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (c *CloudProvider) IsDrifted(ctx context.Context, nodeClaim *corev1beta1.No
if err != nil {
return "", client.IgnoreNotFound(fmt.Errorf("resolving owner, %w", err))
}
if nodePool.Spec.Template.Spec.NodeClass == nil {
if nodePool.Spec.Template.Spec.NodeClassRef == nil {
return "", nil
}
nodeClass, err := c.resolveNodeClassFromNodePool(ctx, nodePool)
Expand All @@ -235,14 +235,14 @@ func (c *CloudProvider) resolveNodeClassFromNodeClaim(ctx context.Context, nodeC
if nodeClaim.IsMachine {
nodeTemplate, err := c.resolveNodeTemplate(ctx,
[]byte(nodeClaim.Annotations[v1alpha5.ProviderCompatabilityAnnotationKey]),
machineutil.NewMachineTemplateRef(nodeClaim.Spec.NodeClass))
machineutil.NewMachineTemplateRef(nodeClaim.Spec.NodeClassRef))
if err != nil {
return nil, fmt.Errorf("resolving node template, %w", err)
}
return nodeclassutil.New(nodeTemplate), nil
}
nodeClass := &v1beta1.EC2NodeClass{}
if err := c.kubeClient.Get(ctx, types.NamespacedName{Name: nodeClaim.Spec.NodeClass.Name}, nodeClass); err != nil {
if err := c.kubeClient.Get(ctx, types.NamespacedName{Name: nodeClaim.Spec.NodeClassRef.Name}, nodeClass); err != nil {
return nil, err
}
// For the purposes of NodeClass CloudProvider resolution, we treat deleting NodeClasses as NotFound
Expand All @@ -259,14 +259,14 @@ func (c *CloudProvider) resolveNodeClassFromNodePool(ctx context.Context, nodePo
if nodePool.Spec.Template.Spec.Provider != nil {
rawProvider = nodePool.Spec.Template.Spec.Provider.Raw
}
nodeTemplate, err := c.resolveNodeTemplate(ctx, rawProvider, machineutil.NewMachineTemplateRef(nodePool.Spec.Template.Spec.NodeClass))
nodeTemplate, err := c.resolveNodeTemplate(ctx, rawProvider, machineutil.NewMachineTemplateRef(nodePool.Spec.Template.Spec.NodeClassRef))
if err != nil {
return nil, fmt.Errorf("resolving node template, %w", err)
}
return nodeclassutil.New(nodeTemplate), nil
}
nodeClass := &v1beta1.EC2NodeClass{}
if err := c.kubeClient.Get(ctx, types.NamespacedName{Name: nodePool.Spec.Template.Spec.NodeClass.Name}, nodeClass); err != nil {
if err := c.kubeClient.Get(ctx, types.NamespacedName{Name: nodePool.Spec.Template.Spec.NodeClassRef.Name}, nodeClass); err != nil {
return nil, err
}
// For the purposes of NodeClass CloudProvider resolution, we treat deleting NodeClasses as NotFound
Expand Down
8 changes: 4 additions & 4 deletions pkg/cloudprovider/nodeclaim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var _ = Describe("NodeClaim/CloudProvider", func() {
Spec: corev1beta1.NodePoolSpec{
Template: corev1beta1.NodeClaimTemplate{
Spec: corev1beta1.NodeClaimSpec{
NodeClass: &corev1beta1.NodeClassReference{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
},
Requirements: []v1.NodeSelectorRequirement{
Expand All @@ -67,7 +67,7 @@ var _ = Describe("NodeClaim/CloudProvider", func() {
Labels: map[string]string{corev1beta1.NodePoolLabelKey: nodePool.Name},
},
Spec: corev1beta1.NodeClaimSpec{
NodeClass: &corev1beta1.NodeClassReference{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
},
},
Expand Down Expand Up @@ -463,7 +463,7 @@ var _ = Describe("NodeClaim/CloudProvider", func() {
Spec: corev1beta1.NodePoolSpec{
Template: corev1beta1.NodeClaimTemplate{
Spec: corev1beta1.NodeClaimSpec{
NodeClass: &corev1beta1.NodeClassReference{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass2.Name,
},
},
Expand Down Expand Up @@ -504,7 +504,7 @@ var _ = Describe("NodeClaim/CloudProvider", func() {
Spec: corev1beta1.NodePoolSpec{
Template: corev1beta1.NodeClaimTemplate{
Spec: corev1beta1.NodeClaimSpec{
NodeClass: &corev1beta1.NodeClassReference{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: misconfiguredNodeClass.Name,
},
},
Expand Down
8 changes: 4 additions & 4 deletions pkg/controllers/nodeclaim/garbagecollection/nodeclaim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var _ = Describe("NodeClaim/GarbageCollection", func() {
Spec: corev1beta1.NodePoolSpec{
Template: corev1beta1.NodeClaimTemplate{
Spec: corev1beta1.NodeClaimSpec{
NodeClass: &corev1beta1.NodeClassReference{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
},
},
Expand Down Expand Up @@ -208,7 +208,7 @@ var _ = Describe("NodeClaim/GarbageCollection", func() {
)
nodeClaim := coretest.NodeClaim(corev1beta1.NodeClaim{
Spec: corev1beta1.NodeClaimSpec{
NodeClass: &corev1beta1.NodeClassReference{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
},
},
Expand Down Expand Up @@ -269,7 +269,7 @@ var _ = Describe("NodeClaim/GarbageCollection", func() {

nodeClaim := coretest.NodeClaim(corev1beta1.NodeClaim{
Spec: corev1beta1.NodeClaimSpec{
NodeClass: &corev1beta1.NodeClassReference{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
},
},
Expand Down Expand Up @@ -325,7 +325,7 @@ var _ = Describe("NodeClaim/GarbageCollection", func() {
)
nodeClaim := coretest.NodeClaim(corev1beta1.NodeClaim{
Spec: corev1beta1.NodeClaimSpec{
NodeClass: &corev1beta1.NodeClassReference{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/nodeclaim/garbagecollection/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ var _ = Describe("Combined/GarbageCollection", func() {
)
nodeClaim := coretest.NodeClaim(corev1beta1.NodeClaim{
Spec: corev1beta1.NodeClaimSpec{
NodeClass: &corev1beta1.NodeClassReference{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/nodeclass/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ func (c *NodeClassController) Builder(_ context.Context, m manager.Manager) core
&source.Kind{Type: &corev1beta1.NodeClaim{}},
handler.EnqueueRequestsFromMapFunc(func(o client.Object) []reconcile.Request {
nc := o.(*corev1beta1.NodeClaim)
if nc.Spec.NodeClass == nil {
if nc.Spec.NodeClassRef == nil {
return nil
}
return []reconcile.Request{{NamespacedName: types.NamespacedName{Name: nc.Spec.NodeClass.Name}}}
return []reconcile.Request{{NamespacedName: types.NamespacedName{Name: nc.Spec.NodeClassRef.Name}}}
}),
// Watch for NodeClaim deletion events
builder.WithPredicates(predicate.Funcs{
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/nodeclass/nodeclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ var _ = Describe("NodeClassController", func() {
for i := 0; i < 2; i++ {
nc := coretest.NodeClaim(corev1beta1.NodeClaim{
Spec: corev1beta1.NodeClaimSpec{
NodeClass: &corev1beta1.NodeClassReference{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/providers/instance/nodeclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var _ = Describe("NodeClass/InstanceProvider", func() {
Spec: corev1beta1.NodePoolSpec{
Template: corev1beta1.NodeClaimTemplate{
Spec: corev1beta1.NodeClaimSpec{
NodeClass: &corev1beta1.NodeClassReference{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
},
},
Expand All @@ -54,7 +54,7 @@ var _ = Describe("NodeClass/InstanceProvider", func() {
},
},
Spec: corev1beta1.NodeClaimSpec{
NodeClass: &corev1beta1.NodeClassReference{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/providers/instancetype/nodeclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var _ = Describe("NodeClass/InstanceTypes", func() {
Values: []string{corev1beta1.CapacityTypeOnDemand},
},
},
NodeClass: &corev1beta1.NodeClassReference{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
},
},
Expand All @@ -84,7 +84,7 @@ var _ = Describe("NodeClass/InstanceTypes", func() {
Values: []string{corev1beta1.CapacityTypeOnDemand},
},
},
NodeClass: &corev1beta1.NodeClassReference{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: windowsNodeClass.Name,
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/providers/launchtemplate/nodeclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var _ = Describe("EC2NodeClass/LaunchTemplates", func() {
Values: []string{corev1beta1.CapacityTypeOnDemand},
},
},
NodeClass: &corev1beta1.NodeClassReference{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
},
},
Expand Down Expand Up @@ -1099,7 +1099,7 @@ var _ = Describe("EC2NodeClass/LaunchTemplates", func() {
EnableENILimitedPodDensity: lo.ToPtr(false),
}))

nodePool.Spec.Template.Spec.NodeClass = &corev1beta1.NodeClassReference{Name: "doesnotexist"}
nodePool.Spec.Template.Spec.NodeClassRef = &corev1beta1.NodeClassReference{Name: "doesnotexist"}
ExpectApplied(ctx, env.Client, nodePool)
pod := coretest.UnschedulablePod()
ExpectProvisioned(ctx, env.Client, cluster, cloudProvider, prov, pod)
Expand Down
4 changes: 2 additions & 2 deletions pkg/test/nodeclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ func EC2NodeClassFieldIndexer(ctx context.Context) func(cache.Cache) error {
return func(c cache.Cache) error {
return c.IndexField(ctx, &corev1beta1.NodeClaim{}, "spec.nodeClass.name", func(obj client.Object) []string {
nc := obj.(*corev1beta1.NodeClaim)
if nc.Spec.NodeClass == nil {
if nc.Spec.NodeClassRef == nil {
return []string{""}
}
return []string{nc.Spec.NodeClass.Name}
return []string{nc.Spec.NodeClassRef.Name}
})
}
}
4 changes: 2 additions & 2 deletions test/suites/integration/tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var _ = Describe("Tags", func() {
Spec: corev1beta1.NodePoolSpec{
Template: corev1beta1.NodeClaimTemplate{
Spec: corev1beta1.NodeClaimSpec{
NodeClass: &corev1beta1.NodeClassReference{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
},
},
Expand Down Expand Up @@ -144,7 +144,7 @@ var _ = Describe("Tags", func() {
Spec: corev1beta1.NodePoolSpec{
Template: corev1beta1.NodeClaimTemplate{
Spec: corev1beta1.NodeClaimSpec{
NodeClass: &corev1beta1.NodeClassReference{Name: nodeClass.Name},
NodeClassRef: &corev1beta1.NodeClassReference{Name: nodeClass.Name},
},
},
},
Expand Down

0 comments on commit c91f091

Please sign in to comment.