Skip to content

Commit

Permalink
chore: Drop NodePool and NodeClaim utils functions (#5401)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis authored Dec 29, 2023
1 parent 7d47718 commit 8e5115c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
knative.dev/pkg v0.0.0-20231010144348-ca8c009405dd
sigs.k8s.io/controller-runtime v0.16.3
sigs.k8s.io/karpenter v0.33.1-0.20231224205745-0b25de76d2ad
sigs.k8s.io/karpenter v0.33.1-0.20231227175620-ea2e47b9fe73
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,8 @@ sigs.k8s.io/controller-runtime v0.16.3 h1:2TuvuokmfXvDUamSx1SuAOO3eTyye+47mJCigw
sigs.k8s.io/controller-runtime v0.16.3/go.mod h1:j7bialYoSn142nv9sCOJmQgDXQXxnroFU4VnX/brVJ0=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/karpenter v0.33.1-0.20231224205745-0b25de76d2ad h1:C3zHs4PswQC3tCtQBFI2hXSj9SEfJNQ5Jcs8giTec8c=
sigs.k8s.io/karpenter v0.33.1-0.20231224205745-0b25de76d2ad/go.mod h1:k1819wVloDPI/TUTEYWII7LgbC6paTSIgYgbywM0r/k=
sigs.k8s.io/karpenter v0.33.1-0.20231227175620-ea2e47b9fe73 h1:L8McmDRGqisYDX5wIG42hVTIgCz7aUdCbN0enVCovRs=
sigs.k8s.io/karpenter v0.33.1-0.20231227175620-ea2e47b9fe73/go.mod h1:OAiiFe16SakE7GJNTuC2YTWZq0rwRUgqkunY1Y9TqYY=
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=
sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
Expand Down
14 changes: 9 additions & 5 deletions pkg/controllers/interruption/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

sqsapi "github.com/aws/aws-sdk-go/service/sqs"
"github.com/prometheus/client_golang/prometheus"
"github.com/samber/lo"
"go.uber.org/multierr"
v1 "k8s.io/api/core/v1"
Expand All @@ -29,6 +30,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/karpenter/pkg/metrics"

"sigs.k8s.io/karpenter/pkg/apis/v1beta1"
"sigs.k8s.io/karpenter/pkg/utils/pretty"
Expand All @@ -42,7 +44,6 @@ import (

"sigs.k8s.io/karpenter/pkg/events"
corecontroller "sigs.k8s.io/karpenter/pkg/operator/controller"
nodeclaimutil "sigs.k8s.io/karpenter/pkg/utils/nodeclaim"
)

type Action string
Expand Down Expand Up @@ -208,12 +209,15 @@ func (c *Controller) deleteNodeClaim(ctx context.Context, nodeClaim *v1beta1.Nod
if !nodeClaim.DeletionTimestamp.IsZero() {
return nil
}
if err := nodeclaimutil.Delete(ctx, c.kubeClient, nodeClaim); err != nil {
if err := c.kubeClient.Delete(ctx, nodeClaim); err != nil {
return client.IgnoreNotFound(fmt.Errorf("deleting the node on interruption message, %w", err))
}
logging.FromContext(ctx).Infof("initiating delete from interruption message")
c.recorder.Publish(interruptionevents.TerminatingOnInterruption(node, nodeClaim)...)
nodeclaimutil.TerminatedCounter(nodeClaim, terminationReasonLabel).Inc()
metrics.NodeClaimsTerminatedCounter.With(prometheus.Labels{
metrics.ReasonLabel: terminationReasonLabel,
metrics.NodePoolLabel: nodeClaim.Labels[v1beta1.NodePoolLabelKey],
}).Inc()
return nil
}

Expand Down Expand Up @@ -245,8 +249,8 @@ func (c *Controller) notifyForMessage(msg messages.Message, nodeClaim *v1beta1.N
// NodeClaim .status.providerID and the NodeClaim
func (c *Controller) makeNodeClaimInstanceIDMap(ctx context.Context) (map[string]*v1beta1.NodeClaim, error) {
m := map[string]*v1beta1.NodeClaim{}
nodeClaimList, err := nodeclaimutil.List(ctx, c.kubeClient)
if err != nil {
nodeClaimList := &v1beta1.NodeClaimList{}
if err := c.kubeClient.List(ctx, nodeClaimList); err != nil {
return nil, err
}
for i := range nodeClaimList.Items {
Expand Down
7 changes: 3 additions & 4 deletions pkg/controllers/nodeclaim/garbagecollection/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"sigs.k8s.io/karpenter/pkg/apis/v1beta1"
corecloudprovider "sigs.k8s.io/karpenter/pkg/cloudprovider"
"sigs.k8s.io/karpenter/pkg/operator/controller"
nodeclaimutil "sigs.k8s.io/karpenter/pkg/utils/nodeclaim"

"github.com/aws/karpenter-provider-aws/pkg/cloudprovider"
)
Expand Down Expand Up @@ -66,12 +65,12 @@ func (c *Controller) Reconcile(ctx context.Context, _ reconcile.Request) (reconc
managedRetrieved := lo.Filter(retrieved, func(nc *v1beta1.NodeClaim, _ int) bool {
return nc.Annotations[v1beta1.ManagedByAnnotationKey] != "" && nc.DeletionTimestamp.IsZero()
})
nodeClaimList, err := nodeclaimutil.List(ctx, c.kubeClient)
if err != nil {
nodeClaimList := &v1beta1.NodeClaimList{}
if err = c.kubeClient.List(ctx, nodeClaimList); err != nil {
return reconcile.Result{}, err
}
nodeList := &v1.NodeList{}
if err := c.kubeClient.List(ctx, nodeList); err != nil {
if err = c.kubeClient.List(ctx, nodeList); err != nil {
return reconcile.Result{}, err
}
resolvedProviderIDs := sets.New[string](lo.FilterMap(nodeClaimList.Items, func(n v1beta1.NodeClaim, _ int) (string, bool) {
Expand Down

0 comments on commit 8e5115c

Please sign in to comment.