Skip to content

Commit ec3211b

Browse files
committed
update interface
1 parent f65d2ae commit ec3211b

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

pkg/apis/v1/ec2nodeclass.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,10 @@ func (in *EC2NodeClass) NetworkInterfaces() []*NetworkInterface {
582582
return in.Spec.NetworkInterfaces
583583
}
584584

585+
func (in *EC2NodeClass) PlacementGroupSelector() *PlacementGroupSelector {
586+
return in.Spec.PlacementGroupSelector
587+
}
588+
585589
func (in *EC2NodeClass) KubeletConfiguration() *KubeletConfiguration {
586590
return in.Spec.Kubelet
587591
}

pkg/providers/instancetype/instancetype.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type NodeClass interface {
6161
InstanceStorePolicy() *v1.InstanceStorePolicy
6262
NetworkInterfaces() []*v1.NetworkInterface
6363
KubeletConfiguration() *v1.KubeletConfiguration
64+
PlacementGroupSelector() *v1.PlacementGroupSelector
6465
ZoneInfo() []v1.ZoneInfo
6566
}
6667

@@ -364,8 +365,8 @@ func (p *DefaultProvider) FilterForNodeClass(ctx context.Context, its []*cloudpr
364365
defer p.muInstanceTypesInfo.RUnlock()
365366
// Resolve the placement group for compatibility checking
366367
var pg *placementgroup.PlacementGroup
367-
if nc, ok := nodeClass.(*v1.EC2NodeClass); ok {
368-
pg, _ = p.placementGroupProvider.Get(ctx, nc)
368+
if nodeClass.PlacementGroupSelector() != nil {
369+
pg, _ = p.placementGroupProvider.Get(ctx, nodeClass)
369370
}
370371
compatible := []*cloudprovider.InstanceType{}
371372
for _, it := range its {

pkg/providers/instancetype/offering/offering.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/samber/lo"
2626
corev1 "k8s.io/api/core/v1"
2727
"k8s.io/apimachinery/pkg/util/sets"
28+
"sigs.k8s.io/controller-runtime/pkg/client"
2829
karpv1 "sigs.k8s.io/karpenter/pkg/apis/v1"
2930
"sigs.k8s.io/karpenter/pkg/cloudprovider"
3031
"sigs.k8s.io/karpenter/pkg/operator/options"
@@ -43,10 +44,12 @@ type Provider interface {
4344
}
4445

4546
type NodeClass interface {
47+
client.Object
4648
CapacityReservations() []v1.CapacityReservation
4749
ZoneInfo() []v1.ZoneInfo
4850
NetworkInterfaces() []*v1.NetworkInterface
4951
AMIFamily() string
52+
PlacementGroupSelector() *v1.PlacementGroupSelector
5053
}
5154

5255
type DefaultProvider struct {
@@ -88,8 +91,8 @@ func (p *DefaultProvider) InjectOfferings(
8891
})
8992
// Resolve the placement group once and pass it through to avoid repeated type assertions and lookups
9093
var pg *placementgroup.PlacementGroup
91-
if nc, ok := nodeClass.(*v1.EC2NodeClass); ok {
92-
pg, _ = p.placementGroupProvider.Get(ctx, nc)
94+
if nodeClass.PlacementGroupSelector() != nil {
95+
pg, _ = p.placementGroupProvider.Get(ctx, nodeClass)
9396
}
9497
var its []*cloudprovider.InstanceType
9598
for _, it := range instanceTypes {

pkg/providers/placementgroup/provider.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
3036
type 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

4046
type 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())

website/content/en/preview/concepts/nodeclasses.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,6 @@ status:
227227
reservationType: default
228228
state: active
229229

230-
# Placement Group
231-
placementGroup:
232-
- id: pg-01234567890123456
233-
name: my-pg
234-
partitionCount: 7
235-
spreadLevel: rack
236-
state: available
237-
strategy: cluster
238-
239230
# Generated instance profile name from "role"
240231
instanceProfile: "${CLUSTER_NAME}-0123456778901234567789"
241232
conditions:

0 commit comments

Comments
 (0)