Skip to content

Commit

Permalink
Merge pull request #163 from castai/feat/spot-worker
Browse files Browse the repository at this point in the history
feat: support for  for spot nodes
  • Loading branch information
aldor007 authored Apr 2, 2024
2 parents 5550d10 + 0959150 commit 40fddc0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/services/providers/eks/eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ func determineLifecycle(n *v1.Node) nodeLifecycle {
return NodeLifecycleSpot
}

if val, ok := n.Labels[labels.WorkerSpot]; ok && val == "true" {
return NodeLifecycleSpot
}

if val, ok := n.Labels[labels.KarpenterCapacityType]; ok {
if val == labels.ValueKarpenterCapacityTypeSpot {
return NodeLifecycleSpot
Expand Down
21 changes: 21 additions & 0 deletions internal/services/providers/eks/eks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,27 @@ func TestProvider_IsSpot(t *testing.T) {
r.Equal([]*v1.Node{node}, got)
})

t.Run("spot instance worker label", func(t *testing.T) {
r := require.New(t)
awsClient := mock_client.NewMockClient(gomock.NewController(t))

p := &Provider{
log: logrus.New(),
awsClient: awsClient,
apiNodeLifecycleDiscoveryEnabled: true,
spotCache: map[string]bool{},
}

node := &v1.Node{ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{
labels.WorkerSpot: "true",
}}}

got, err := p.FilterSpot(context.Background(), []*v1.Node{node})

r.NoError(err)
r.Equal([]*v1.Node{node}, got)
})

t.Run("spot instance CAST AI label", func(t *testing.T) {
r := require.New(t)
awsClient := mock_client.NewMockClient(gomock.NewController(t))
Expand Down
1 change: 1 addition & 0 deletions pkg/labels/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const (
CastaiFakeSpot = "scheduling.cast.ai/fake-spot"
KopsSpot = "spot"
KarpenterCapacityType = "karpenter.sh/capacity-type"
WorkerSpot = "node-role.kubernetes.io/spot-worker"

ValueKarpenterCapacityTypeSpot = "spot"
ValueKarpenterCapacityTypeOnDemand = "on-demand"
Expand Down

0 comments on commit 40fddc0

Please sign in to comment.