From 6ae1ceccac045a6f1ef76ef9fe021fe57c0aae13 Mon Sep 17 00:00:00 2001 From: Robert Lucian Chiriac Date: Tue, 7 Dec 2021 01:47:49 +0200 Subject: [PATCH] Fix reported pricing for spot node-groups with on-demand alternative (#2406) (cherry picked from commit 87f54bd1743476eb4303870aa63eeaabe9cae4c6) --- cli/cmd/lib_cluster_config.go | 10 ++++++++-- pkg/operator/endpoints/info.go | 3 +-- pkg/operator/operator/cron.go | 5 ++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cli/cmd/lib_cluster_config.go b/cli/cmd/lib_cluster_config.go index 48d7a444f3..ac45306865 100644 --- a/cli/cmd/lib_cluster_config.go +++ b/cli/cmd/lib_cluster_config.go @@ -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 { @@ -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) } diff --git a/pkg/operator/endpoints/info.go b/pkg/operator/endpoints/info.go index 53ee80a3d7..c3dbfbc680 100644 --- a/pkg/operator/endpoints/info.go +++ b/pkg/operator/endpoints/info.go @@ -19,7 +19,6 @@ package endpoints import ( "net/http" "sort" - "strings" "github.com/cortexlabs/cortex/pkg/config" "github.com/cortexlabs/cortex/pkg/lib/aws" @@ -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 { diff --git a/pkg/operator/operator/cron.go b/pkg/operator/operator/cron.go index 6153f685fb..89d78b6852 100644 --- a/pkg/operator/operator/cron.go +++ b/pkg/operator/operator/cron.go @@ -18,7 +18,6 @@ package operator import ( "context" - "strings" "github.com/cortexlabs/cortex/pkg/config" "github.com/cortexlabs/cortex/pkg/consts" @@ -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 } @@ -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 }