Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]feat: Add UserAnnotedExpiration as a new disruption method #845

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions pkg/controllers/disruption/custom_expiration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm anticipating that we probably don't want to do something as verbose as karpenter.sh/voluntarily-disrupted=drifted. Realistically, it should probably something simple like karpenter.sh/disrupt=true since we've already got an annotation that's karpenter.sh/do-not-disrupt=false

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package disruption

import (
"context"

"k8s.io/utils/clock"

"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/aws/karpenter-core/pkg/controllers/provisioning"
"github.com/aws/karpenter-core/pkg/controllers/state"
"github.com/aws/karpenter-core/pkg/events"
"github.com/aws/karpenter-core/pkg/metrics"
)

// UserAnnotedExpiration is a subreconciler that deletes custom marked candidates, based on node annotations.
// Expiration will respect TTLSecondsAfterEmpty
type UserAnnotedExpiration struct {
clock clock.Clock
kubeClient client.Client
cluster *state.Cluster
provisioner *provisioning.Provisioner
recorder events.Recorder
}

func NewCustomExpiration(clk clock.Clock, kubeClient client.Client, cluster *state.Cluster, provisioner *provisioning.Provisioner, recorder events.Recorder) *Expiration {
return &Expiration{
clock: clk,
kubeClient: kubeClient,
cluster: cluster,
provisioner: provisioner,
recorder: recorder,
}
}

// ShouldDisrupt is a predicate used to filter candidates
func (e *UserAnnotedExpiration) ShouldDisrupt(_ context.Context, c *Candidate) bool {
// TODO: tasdikrahman to implement this.
return true
}

// SortCandidates orders expired candidates by when they've expired
func (e *UserAnnotedExpiration) filterAndSortCandidates(ctx context.Context, candidates []*Candidate) ([]*Candidate, error) {
// TODO: tasdikrahman to implement this.
return candidates, nil
}

// ComputeCommand generates a disrpution command given candidates
func (e *UserAnnotedExpiration) ComputeCommand(ctx context.Context, candidates ...*Candidate) (Command, error) {
// TODO: tasdikrahman to implement this.
return Command{}, nil
}

func (e *UserAnnotedExpiration) Type() string {
return metrics.UserAnnotedExpiration
}

func (e *UserAnnotedExpiration) ConsolidationType() string {
return ""
}
11 changes: 6 additions & 5 deletions pkg/metrics/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ const (
TypeLabel = "type"

// Reasons for CREATE/DELETE shared metrics
ConsolidationReason = "consolidation"
ProvisioningReason = "provisioning"
ExpirationReason = "expiration"
EmptinessReason = "emptiness"
DriftReason = "drift"
ConsolidationReason = "consolidation"
ProvisioningReason = "provisioning"
ExpirationReason = "expiration"
UserAnnotedExpiration = "user-annotated-expiration"
EmptinessReason = "emptiness"
DriftReason = "drift"
)

// DurationBuckets returns a []float64 of default threshold values for duration histograms.
Expand Down