Просмотр исходного кода

Merge branch 'master' of https://github.com/kubecost/cost-model into develop

Ajay Tripathy 5 лет назад
Родитель
Сommit
32cdb01521
3 измененных файлов с 12 добавлено и 3 удалено
  1. 1 0
      go.sum
  2. 5 2
      pkg/cloud/gcpprovider.go
  3. 6 1
      pkg/costmodel/cluster.go

+ 1 - 0
go.sum

@@ -72,6 +72,7 @@ github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFP
 github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM=
 github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
 github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
+github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw=
 github.com/evanphx/json-patch v0.0.0-20190203023257-5858425f7550 h1:mV9jbLoSW/8m4VK16ZkHTozJa8sesK5u5kTMFysTYac=
 github.com/evanphx/json-patch v0.0.0-20190203023257-5858425f7550/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
 github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=

+ 5 - 2
pkg/cloud/gcpprovider.go

@@ -1401,10 +1401,13 @@ func (gcp *GCP) ServiceAccountStatus() *ServiceAccountStatus {
 
 func (gcp *GCP) CombinedDiscountForNode(instanceType string, isPreemptible bool, defaultDiscount, negotiatedDiscount float64) float64 {
 	class := strings.Split(instanceType, "-")[0]
-	return 1.0 - ((1.0 - sustainedUseDiscount(class, defaultDiscount)) * (1.0 - negotiatedDiscount))
+	return 1.0 - ((1.0 - sustainedUseDiscount(class, defaultDiscount, isPreemptible)) * (1.0 - negotiatedDiscount))
 }
 
-func sustainedUseDiscount(class string, defaultDiscount float64) float64 {
+func sustainedUseDiscount(class string, defaultDiscount float64, isPreemptible bool) float64 {
+	if isPreemptible {
+		return 0.0
+	}
 	discount := defaultDiscount
 	switch class {
 	case "e2", "f1", "g1":

+ 6 - 1
pkg/costmodel/cluster.go

@@ -463,7 +463,12 @@ func ClusterNodes(cp cloud.Provider, client prometheus.Client, duration, offset
 
 		// GCP preemptible label
 		pre, _ := result.GetString("label_cloud_google_com_gke_preemptible")
-		if node, ok := nodeMap[nodeName]; pre == "true" && ok {
+		cluster, err := result.GetString("cluster_id")
+		if err != nil {
+			cluster = env.GetClusterID()
+		}
+		key := fmt.Sprintf("%s/%s", cluster, nodeName)
+		if node, ok := nodeMap[key]; pre == "true" && ok {
 			node.Preemptible = true
 		}