@@ -21,20 +21,26 @@ import (
2121
2222 "github.com/patrickmn/go-cache"
2323 "k8s.io/apimachinery/pkg/types"
24+ "sigs.k8s.io/controller-runtime/pkg/client"
2425
2526 v1 "github.com/aws/karpenter-provider-aws/pkg/apis/v1"
2627 sdk "github.com/aws/karpenter-provider-aws/pkg/aws"
2728 awserrors "github.com/aws/karpenter-provider-aws/pkg/errors"
2829)
2930
31+ type NodeClass interface {
32+ client.Object // Provides Name, UID, Generation
33+ PlacementGroupSelector () * v1.PlacementGroupSelector
34+ }
35+
3036type Provider interface {
3137 // Get resolves the placement group for a nodeclass. It uses an in-memory cache keyed by
3238 // NodeClass UID and generation to avoid unnecessary EC2 API calls. When the cache entry
3339 // expires (TTL) or the NodeClass spec changes (bumping generation), the next call
3440 // re-resolves from EC2. Returns nil when no placement group is configured.
3541 // On transient EC2 errors, returns the last known good result and surfaces the error.
3642 // On not-found errors, clears the resolved state and returns nil.
37- Get (context.Context , * v1. EC2NodeClass ) (* PlacementGroup , error )
43+ Get (context.Context , NodeClass ) (* PlacementGroup , error )
3844}
3945
4046type DefaultProvider struct {
@@ -58,14 +64,14 @@ func NewProvider(ec2api sdk.EC2API, placementGroupCache *cache.Cache) *DefaultPr
5864
5965// cacheKey returns a key that incorporates both the UID and generation,
6066// so spec changes naturally cause a cache miss without separate generation tracking.
61- func cacheKey (nodeClass * v1. EC2NodeClass ) string {
62- return fmt .Sprintf ("%s:%d" , nodeClass .UID , nodeClass .Generation )
67+ func cacheKey (nodeClass NodeClass ) string {
68+ return fmt .Sprintf ("%s:%d" , nodeClass .GetUID () , nodeClass .GetGeneration () )
6369}
6470
65- func (p * DefaultProvider ) Get (ctx context.Context , nodeClass * v1. EC2NodeClass ) (* PlacementGroup , error ) {
66- uid := nodeClass .UID
71+ func (p * DefaultProvider ) Get (ctx context.Context , nodeClass NodeClass ) (* PlacementGroup , error ) {
72+ uid := nodeClass .GetUID ()
6773
68- if nodeClass .Spec . PlacementGroupSelector == nil {
74+ if nodeClass .PlacementGroupSelector () == nil {
6975 p .Lock ()
7076 delete (p .resolved , uid )
7177 p .cache .Delete (cacheKey (nodeClass ))
@@ -81,7 +87,7 @@ func (p *DefaultProvider) Get(ctx context.Context, nodeClass *v1.EC2NodeClass) (
8187 }
8288 p .RUnlock ()
8389
84- term := * nodeClass .Spec . PlacementGroupSelector
90+ term := * nodeClass .PlacementGroupSelector ()
8591 q := & Query {ID : term .ID , Name : term .Name }
8692
8793 out , err := p .ec2api .DescribePlacementGroups (ctx , q .DescribePlacementGroupsInput ())
0 commit comments