Skip to content

Commit

Permalink
Passing nodeclaim and nodeclass to UpdateInstanceTypeCapacityFromNode (
Browse files Browse the repository at this point in the history
  • Loading branch information
edibble21 authored Nov 13, 2024
1 parent e1c369c commit 5910b7d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
13 changes: 12 additions & 1 deletion pkg/controllers/providers/instancetype/capacity/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
karpv1 "sigs.k8s.io/karpenter/pkg/apis/v1"
"sigs.k8s.io/karpenter/pkg/operator/injection"
nodeutils "sigs.k8s.io/karpenter/pkg/utils/node"

v1 "github.com/aws/karpenter-provider-aws/pkg/apis/v1"
"github.com/aws/karpenter-provider-aws/pkg/providers/instancetype"
)

Expand All @@ -48,7 +50,16 @@ func NewController(kubeClient client.Client, instancetypeProvider *instancetype.

func (c *Controller) Reconcile(ctx context.Context, node *corev1.Node) (reconcile.Result, error) {
ctx = injection.WithControllerName(ctx, "providers.instancetype.capacity")
if err := c.instancetypeProvider.UpdateInstanceTypeCapacityFromNode(ctx, c.kubeClient, node); err != nil {
nodeClaim, err := nodeutils.NodeClaimForNode(ctx, c.kubeClient, node)
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to get nodeclaim for node, %w", err)
}

nodeClass := &v1.EC2NodeClass{}
if err = c.kubeClient.Get(ctx, client.ObjectKey{Name: nodeClaim.Spec.NodeClassRef.Name}, nodeClass); err != nil {
return reconcile.Result{}, fmt.Errorf("failed to get ec2nodeclass, %w", err)
}
if err := c.instancetypeProvider.UpdateInstanceTypeCapacityFromNode(ctx, node, nodeClaim, nodeClass); err != nil {
return reconcile.Result{}, fmt.Errorf("updating discovered capacity cache, %w", err)
}
return reconcile.Result{}, nil
Expand Down
13 changes: 1 addition & 12 deletions pkg/providers/instancetype/instancetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import (
"sync/atomic"

"k8s.io/apimachinery/pkg/api/resource"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/karpenter/pkg/scheduling"
nodeutils "sigs.k8s.io/karpenter/pkg/utils/node"

"github.com/aws/karpenter-provider-aws/pkg/providers/amifamily"

Expand Down Expand Up @@ -272,16 +270,7 @@ func (p *DefaultProvider) UpdateInstanceTypeOfferings(ctx context.Context) error
return nil
}

func (p *DefaultProvider) UpdateInstanceTypeCapacityFromNode(ctx context.Context, kubeClient client.Client, node *corev1.Node) error {
nodeClaim, err := nodeutils.NodeClaimForNode(ctx, kubeClient, node)
if err != nil {
return fmt.Errorf("failed to get nodeclaim for node, %w", err)
}

nodeClass := &v1.EC2NodeClass{}
if err = kubeClient.Get(ctx, client.ObjectKey{Name: nodeClaim.Spec.NodeClassRef.Name}, nodeClass); err != nil {
return fmt.Errorf("failed to get ec2nodeclass, %w", err)
}
func (p *DefaultProvider) UpdateInstanceTypeCapacityFromNode(ctx context.Context, node *corev1.Node, nodeClaim *karpv1.NodeClaim, nodeClass *v1.EC2NodeClass) error {

// Get mappings for most recent AMIs
instanceTypeName := node.Labels[corev1.LabelInstanceTypeStable]
Expand Down

0 comments on commit 5910b7d

Please sign in to comment.