Skip to content
Open
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
6 changes: 4 additions & 2 deletions pkg/model/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
34 changes: 18 additions & 16 deletions pkg/model/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,40 @@ 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)
}
}

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")
}
}

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{
label: value,
}
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")
}
}
}
Expand All @@ -80,20 +81,21 @@ 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{
label: value,
}
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")
}
}
}
Expand All @@ -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")
}
}
}
Expand All @@ -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")
}
}
}
Expand Down