Skip to content

Commit 6ae1cec

Browse files
RobertLuciandeliahu
authored andcommitted
Fix reported pricing for spot node-groups with on-demand alternative (#2406)
(cherry picked from commit 87f54bd)
1 parent a6297c4 commit 6ae1cec

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

cli/cmd/lib_cluster_config.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func confirmInstallClusterConfig(clusterConfig *clusterconfig.Config, awsClient
187187
rows = append(rows, []interface{}{"1 eks cluster", s.DollarsMaxPrecision(eksPrice)})
188188

189189
ngNameToSpotInstancesUsed := map[string]int{}
190-
fixedPrice := eksPrice + operatorInstancePrice + operatorEBSPrice + prometheusInstancePrice + prometheusEBSPrice + metricsEBSPrice + 2*nlbPrice + natTotalPrice
190+
fixedPrice := eksPrice + 2*(operatorInstancePrice+operatorEBSPrice) + prometheusInstancePrice + prometheusEBSPrice + metricsEBSPrice + 2*nlbPrice + natTotalPrice
191191
totalMinPrice := fixedPrice
192192
totalMaxPrice := fixedPrice
193193
for _, ng := range clusterConfig.NodeGroups {
@@ -215,7 +215,13 @@ func confirmInstallClusterConfig(clusterConfig *clusterconfig.Config, awsClient
215215
workerPriceStr += " (spot pricing unavailable)"
216216
if err == nil && spotPrice != 0 {
217217
workerPriceStr = fmt.Sprintf("%s - %s each (varies based on spot price)", s.DollarsAndTenthsOfCents(spotPrice+apiEBSPrice), s.DollarsAndTenthsOfCents(apiInstancePrice+apiEBSPrice))
218-
totalMinPrice += float64(ng.MinInstances) * (spotPrice + apiEBSPrice)
218+
if ng.MinInstances > *ng.SpotConfig.OnDemandBaseCapacity {
219+
totalMinPrice += float64(ng.MinInstances-*ng.SpotConfig.OnDemandBaseCapacity)*(spotPrice+apiEBSPrice)*float64(100-*ng.SpotConfig.OnDemandPercentageAboveBaseCapacity)/100 +
220+
float64(ng.MinInstances-*ng.SpotConfig.OnDemandBaseCapacity)*(apiInstancePrice+apiEBSPrice)*float64(*ng.SpotConfig.OnDemandPercentageAboveBaseCapacity)/100 +
221+
float64(*ng.SpotConfig.OnDemandBaseCapacity)*(apiInstancePrice+apiEBSPrice)
222+
} else {
223+
totalMinPrice += float64(ng.MinInstances) * (apiInstancePrice + apiEBSPrice)
224+
}
219225
} else {
220226
totalMinPrice += float64(ng.MinInstances) * (apiInstancePrice + apiEBSPrice)
221227
}

pkg/operator/endpoints/info.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package endpoints
1919
import (
2020
"net/http"
2121
"sort"
22-
"strings"
2322

2423
"github.com/cortexlabs/cortex/pkg/config"
2524
"github.com/cortexlabs/cortex/pkg/lib/aws"
@@ -76,7 +75,7 @@ func getWorkerNodeInfos() ([]schema.WorkerNodeInfo, int, error) {
7675

7776
instanceType := node.Labels["beta.kubernetes.io/instance-type"]
7877
nodeGroupName := node.Labels["alpha.eksctl.io/nodegroup-name"]
79-
isSpot := strings.Contains(strings.ToLower(node.Labels["lifecycle"]), "spot")
78+
isSpot := node.Labels["node-lifecycle"] == "spot"
8079

8180
price := aws.InstanceMetadatas[config.ClusterConfig.Region][instanceType].Price
8281
if isSpot {

pkg/operator/operator/cron.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package operator
1818

1919
import (
2020
"context"
21-
"strings"
2221

2322
"github.com/cortexlabs/cortex/pkg/config"
2423
"github.com/cortexlabs/cortex/pkg/consts"
@@ -128,7 +127,7 @@ func clusterTelemetryProperties() (map[string]interface{}, error) {
128127
}
129128

130129
isSpot := false
131-
if strings.Contains(strings.ToLower(node.Labels["lifecycle"]), "spot") {
130+
if node.Labels["node-lifecycle"] == "spot" {
132131
isSpot = true
133132
}
134133

@@ -304,7 +303,7 @@ func CostBreakdown() error {
304303
}
305304

306305
isSpot := false
307-
if strings.Contains(strings.ToLower(node.Labels["lifecycle"]), "spot") {
306+
if node.Labels["node-lifecycle"] == "spot" {
308307
isSpot = true
309308
}
310309

0 commit comments

Comments
 (0)