Skip to content

Commit

Permalink
Add the NodeClaim indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis committed Oct 17, 2023
1 parent c3b341b commit 8677963
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
sigs.k8s.io/controller-runtime v0.16.2
)

replace github.com/aws/karpenter-core => github.com/jonathan-innis/karpenter-core v0.0.0-20231012191332-1e368cfd9c25
replace github.com/aws/karpenter-core => github.com/jonathan-innis/karpenter-core v0.0.0-20231012204809-85c20f5ab91f

require (
contrib.go.opencensus.io/exporter/ocagent v0.7.1-0.20200907061046-05415f1de66d // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9Y
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/jonathan-innis/karpenter-core v0.0.0-20231012191332-1e368cfd9c25 h1:ouaAwe6U5+LIgvgnAfwa7gMnFKtpvgrRMc6ATJlCiP4=
github.com/jonathan-innis/karpenter-core v0.0.0-20231012191332-1e368cfd9c25/go.mod h1:rb3kp/3cj38tACF6udfpmIvKoQMwirSVoHNlrd66LyE=
github.com/jonathan-innis/karpenter-core v0.0.0-20231012204809-85c20f5ab91f h1:KHHkgIt6RPCEDezhXrr/Y+F9MI2TGi6A5+46zkdQU1I=
github.com/jonathan-innis/karpenter-core v0.0.0-20231012204809-85c20f5ab91f/go.mod h1:rb3kp/3cj38tACF6udfpmIvKoQMwirSVoHNlrd66LyE=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/nodeclass/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (c *Controller) Finalize(ctx context.Context, nodeClass *v1beta1.EC2NodeCla
return reconcile.Result{}, nil
}
nodeClaimList := &corev1beta1.NodeClaimList{}
if err := c.kubeClient.List(ctx, nodeClaimList, client.MatchingFields{"spec.nodeClass.name": nodeClass.Name}); err != nil {
if err := c.kubeClient.List(ctx, nodeClaimList, client.MatchingFields{"spec.nodeClassRef.name": nodeClass.Name}); err != nil {
return reconcile.Result{}, fmt.Errorf("listing nodeclaims that are using nodeclass, %w", err)
}
if len(nodeClaimList.Items) > 0 {
Expand Down
10 changes: 10 additions & 0 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/aws/aws-sdk-go/service/iam"
"github.com/aws/aws-sdk-go/service/ssm"
"github.com/patrickmn/go-cache"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/samber/lo"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -46,6 +47,7 @@ import (
"knative.dev/pkg/logging"
"knative.dev/pkg/ptr"

corev1beta1 "github.com/aws/karpenter-core/pkg/apis/v1beta1"
"github.com/aws/karpenter-core/pkg/operator"
"github.com/aws/karpenter/pkg/apis/settings"
awscache "github.com/aws/karpenter/pkg/cache"
Expand Down Expand Up @@ -167,6 +169,14 @@ func NewOperator(ctx context.Context, operator *operator.Operator) (context.Cont
launchTemplateProvider,
)

lo.Must0(operator.Manager.GetFieldIndexer().IndexField(ctx, &corev1beta1.NodeClaim{}, "spec.nodeClassRef.name", func(o client.Object) []string {
nc := o.(*corev1beta1.NodeClaim)
if nc.Spec.NodeClassRef == nil {
return []string{}
}
return []string{nc.Spec.NodeClassRef.Name}
}), "failed to setup nodeclaim indexer")

return ctx, &Operator{
Operator: operator,
Session: sess,
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/nodeclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func EC2NodeClass(overrides ...v1beta1.EC2NodeClass) *v1beta1.EC2NodeClass {

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 {
return c.IndexField(ctx, &corev1beta1.NodeClaim{}, "spec.nodeClassRef.name", func(obj client.Object) []string {
nc := obj.(*corev1beta1.NodeClaim)
if nc.Spec.NodeClassRef == nil {
return []string{""}
Expand Down

0 comments on commit 8677963

Please sign in to comment.