From ef0a8690684171b6be53effe5c0df13ae58eefc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Havl=C3=AD=C4=8Dek?= Date: Fri, 16 May 2025 08:21:49 +0200 Subject: [PATCH] add support for nodes managed by Spot Ocean --- pkg/model/node.go | 6 ++++-- pkg/model/node_test.go | 34 ++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/pkg/model/node.go b/pkg/model/node.go index cc89734..e8562b0 100644 --- a/pkg/model/node.go +++ b/pkg/model/node.go @@ -78,12 +78,14 @@ func NewNodeFromNodeClaim(nc *karpv1.NodeClaim) *Node { func (n *Node) IsOnDemand() bool { return n.node.Labels["karpenter.sh/capacity-type"] == "on-demand" || - n.node.Labels["eks.amazonaws.com/capacityType"] == "ON_DEMAND" + n.node.Labels["eks.amazonaws.com/capacityType"] == "ON_DEMAND" || + n.node.Labels["spotinst.io/node-lifecycle"] == "od" } func (n *Node) IsSpot() bool { return n.node.Labels["karpenter.sh/capacity-type"] == "spot" || - n.node.Labels["eks.amazonaws.com/capacityType"] == "SPOT" + n.node.Labels["eks.amazonaws.com/capacityType"] == "SPOT" || + n.node.Labels["spotinst.io/node-lifecycle"] == "spot" } func (n *Node) IsFargate() bool { diff --git a/pkg/model/node_test.go b/pkg/model/node_test.go index f4a05f7..4d343a4 100644 --- a/pkg/model/node_test.go +++ b/pkg/model/node_test.go @@ -39,7 +39,7 @@ func TestNewNode(t *testing.T) { n := testNode("mynode") node := model.NewNode(n) if exp, got := "mynode", node.Name(); exp != got { - t.Errorf("expeted Name == %s, got %s", exp, got) + t.Errorf("expected Name == %s, got %s", exp, got) } } @@ -47,10 +47,10 @@ func TestNodeTypeUnknown(t *testing.T) { n := testNode("mynode") node := model.NewNode(n) if node.IsOnDemand() { - t.Errorf("exepcted to not be on-demand") + t.Errorf("expected to not be on-demand") } if node.IsSpot() { - t.Errorf("exepcted to not be spot") + t.Errorf("expected to not be spot") } } @@ -58,6 +58,7 @@ func TestNodeTypeOnDemand(t *testing.T) { for label, value := range map[string]string{ "karpenter.sh/capacity-type": "on-demand", "eks.amazonaws.com/capacityType": "ON_DEMAND", + "spotinst.io/node-lifecycle": "od", } { n := testNode("mynode") n.Labels = map[string]string{ @@ -65,13 +66,13 @@ func TestNodeTypeOnDemand(t *testing.T) { } node := model.NewNode(n) if !node.IsOnDemand() { - t.Errorf("exepcted on-demand") + t.Errorf("expected on-demand") } if node.IsSpot() { - t.Errorf("exepcted to not be spot") + t.Errorf("expected to not be spot") } if node.IsFargate() { - t.Errorf("exepcted to not be fargate") + t.Errorf("expected to not be fargate") } } } @@ -80,6 +81,7 @@ func TestNodeTypeSpot(t *testing.T) { for label, value := range map[string]string{ "karpenter.sh/capacity-type": "spot", "eks.amazonaws.com/capacityType": "SPOT", + "spotinst.io/node-lifecycle": "spot", } { n := testNode("mynode") n.Labels = map[string]string{ @@ -87,13 +89,13 @@ func TestNodeTypeSpot(t *testing.T) { } node := model.NewNode(n) if node.IsOnDemand() { - t.Errorf("exepcted to not be on-demand") + t.Errorf("expected to not be on-demand") } if !node.IsSpot() { - t.Errorf("exepcted to be spot") + t.Errorf("expected to be spot") } if node.IsFargate() { - t.Errorf("exepcted to not be fargate") + t.Errorf("expected to not be fargate") } } } @@ -108,13 +110,13 @@ func TestNodeTypeFargate(t *testing.T) { } node := model.NewNode(n) if node.IsOnDemand() { - t.Errorf("exepcted to not be on-demand") + t.Errorf("expected to not be on-demand") } if node.IsSpot() { - t.Errorf("exepcted to not be spot") + t.Errorf("expected to not be spot") } if !node.IsFargate() { - t.Errorf("exepcted to be fargate") + t.Errorf("expected to be fargate") } } } @@ -129,16 +131,16 @@ func TestNodeTypeAuto(t *testing.T) { } node := model.NewNode(n) if node.IsOnDemand() { - t.Errorf("exepcted to not be on-demand") + t.Errorf("expected to not be on-demand") } if node.IsSpot() { - t.Errorf("exepcted to not be spot") + t.Errorf("expected to not be spot") } if node.IsFargate() { - t.Errorf("exepcted to not be fargate") + t.Errorf("expected to not be fargate") } if !node.IsAuto() { - t.Errorf("exepcted to be auto") + t.Errorf("expected to be auto") } } }