Skip to content

Commit

Permalink
Fix reported pricing for spot node-groups with on-demand alternative (#…
Browse files Browse the repository at this point in the history
…2406)

(cherry picked from commit 87f54bd)
  • Loading branch information
RobertLucian authored and deliahu committed Dec 7, 2021
1 parent a6297c4 commit 6ae1cec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
10 changes: 8 additions & 2 deletions cli/cmd/lib_cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func confirmInstallClusterConfig(clusterConfig *clusterconfig.Config, awsClient
rows = append(rows, []interface{}{"1 eks cluster", s.DollarsMaxPrecision(eksPrice)})

ngNameToSpotInstancesUsed := map[string]int{}
fixedPrice := eksPrice + operatorInstancePrice + operatorEBSPrice + prometheusInstancePrice + prometheusEBSPrice + metricsEBSPrice + 2*nlbPrice + natTotalPrice
fixedPrice := eksPrice + 2*(operatorInstancePrice+operatorEBSPrice) + prometheusInstancePrice + prometheusEBSPrice + metricsEBSPrice + 2*nlbPrice + natTotalPrice
totalMinPrice := fixedPrice
totalMaxPrice := fixedPrice
for _, ng := range clusterConfig.NodeGroups {
Expand Down Expand Up @@ -215,7 +215,13 @@ func confirmInstallClusterConfig(clusterConfig *clusterconfig.Config, awsClient
workerPriceStr += " (spot pricing unavailable)"
if err == nil && spotPrice != 0 {
workerPriceStr = fmt.Sprintf("%s - %s each (varies based on spot price)", s.DollarsAndTenthsOfCents(spotPrice+apiEBSPrice), s.DollarsAndTenthsOfCents(apiInstancePrice+apiEBSPrice))
totalMinPrice += float64(ng.MinInstances) * (spotPrice + apiEBSPrice)
if ng.MinInstances > *ng.SpotConfig.OnDemandBaseCapacity {
totalMinPrice += float64(ng.MinInstances-*ng.SpotConfig.OnDemandBaseCapacity)*(spotPrice+apiEBSPrice)*float64(100-*ng.SpotConfig.OnDemandPercentageAboveBaseCapacity)/100 +
float64(ng.MinInstances-*ng.SpotConfig.OnDemandBaseCapacity)*(apiInstancePrice+apiEBSPrice)*float64(*ng.SpotConfig.OnDemandPercentageAboveBaseCapacity)/100 +
float64(*ng.SpotConfig.OnDemandBaseCapacity)*(apiInstancePrice+apiEBSPrice)
} else {
totalMinPrice += float64(ng.MinInstances) * (apiInstancePrice + apiEBSPrice)
}
} else {
totalMinPrice += float64(ng.MinInstances) * (apiInstancePrice + apiEBSPrice)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/operator/endpoints/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package endpoints
import (
"net/http"
"sort"
"strings"

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

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

price := aws.InstanceMetadatas[config.ClusterConfig.Region][instanceType].Price
if isSpot {
Expand Down
5 changes: 2 additions & 3 deletions pkg/operator/operator/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package operator

import (
"context"
"strings"

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

isSpot := false
if strings.Contains(strings.ToLower(node.Labels["lifecycle"]), "spot") {
if node.Labels["node-lifecycle"] == "spot" {
isSpot = true
}

Expand Down Expand Up @@ -304,7 +303,7 @@ func CostBreakdown() error {
}

isSpot := false
if strings.Contains(strings.ToLower(node.Labels["lifecycle"]), "spot") {
if node.Labels["node-lifecycle"] == "spot" {
isSpot = true
}

Expand Down

0 comments on commit 6ae1cec

Please sign in to comment.