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

Merge branch 'develop' into logyball/make-ui-base-url-dynamic

logan 3 лет назад
Родитель
Сommit
50762a841a
3 измененных файлов с 36 добавлено и 13 удалено
  1. 1 1
      README.md
  2. 19 4
      pkg/cloud/customprovider.go
  3. 16 8
      pkg/cloud/provider.go

+ 1 - 1
README.md

@@ -37,7 +37,7 @@ and contributing changes.
 
 ## Community
 
-If you need any support or have any questions on contributing to the project, you can reach us on [CNCF Slack](https://slack.cncf.io/) in the [#opencost](https://cloud-native.slack.com/archives/C03D56FPD4G) channel or via email at [opencost@kubecost.com](opencost@kubecost.com).
+If you need any support or have any questions on contributing to the project, you can reach us on [CNCF Slack](https://slack.cncf.io/) in the [#opencost](https://cloud-native.slack.com/archives/C03D56FPD4G) channel, email at [opencost@kubecost.com](opencost@kubecost.com), or attend the [OpenCost Working Group meetings](https://bit.ly/opencost-meeting) from the [Community Calendar](https://bit.ly/opencost-calendar).
 
 ## FAQ
 

+ 19 - 4
pkg/cloud/customprovider.go

@@ -3,7 +3,6 @@ package cloud
 import (
 	"errors"
 	"fmt"
-	"github.com/opencost/opencost/pkg/kubecost"
 	"io"
 	"strconv"
 	"sync"
@@ -11,6 +10,8 @@ import (
 
 	"github.com/opencost/opencost/pkg/clustercache"
 	"github.com/opencost/opencost/pkg/env"
+	"github.com/opencost/opencost/pkg/kubecost"
+	"github.com/opencost/opencost/pkg/log"
 	"github.com/opencost/opencost/pkg/util/json"
 
 	v1 "k8s.io/api/core/v1"
@@ -139,6 +140,8 @@ func (cp *CustomProvider) NodePricing(key Key) (*Node, error) {
 	k := key.Features()
 	var gpuCount string
 	if _, ok := cp.Pricing[k]; !ok {
+		// Default is saying that there is no pricing info for the cluster and we should fall back to the defualt values.
+		// An interesting case is if the default values weren't loaded.
 		k = "default"
 	}
 	if key.GPUType() != "" {
@@ -146,10 +149,22 @@ func (cp *CustomProvider) NodePricing(key Key) (*Node, error) {
 		gpuCount = "1" // TODO: support more than one gpu.
 	}
 
+	var cpuCost, ramCost, gpuCost string
+	if pricing, ok := cp.Pricing[k]; !ok {
+		log.Warnf("No pricing found for key=%s, setting values to 0", k)
+		cpuCost = "0.0"
+		ramCost = "0.0"
+		gpuCost = "0.0"
+	} else {
+		cpuCost = pricing.CPU
+		ramCost = pricing.RAM
+		gpuCost = pricing.GPU
+	}
+
 	return &Node{
-		VCPUCost: cp.Pricing[k].CPU,
-		RAMCost:  cp.Pricing[k].RAM,
-		GPUCost:  cp.Pricing[k].GPU,
+		VCPUCost: cpuCost,
+		RAMCost:  ramCost,
+		GPUCost:  gpuCost,
 		GPU:      gpuCount,
 	}, nil
 }

+ 16 - 8
pkg/cloud/provider.go

@@ -158,14 +158,22 @@ type OutOfClusterAllocation struct {
 }
 
 type CustomPricing struct {
-	Provider                     string `json:"provider"`
-	Description                  string `json:"description"`
-	CPU                          string `json:"CPU"`
-	SpotCPU                      string `json:"spotCPU"`
-	RAM                          string `json:"RAM"`
-	SpotRAM                      string `json:"spotRAM"`
-	GPU                          string `json:"GPU"`
-	SpotGPU                      string `json:"spotGPU"`
+	Provider    string `json:"provider"`
+	Description string `json:"description"`
+	// CPU a string-encoded float describing cost per core-hour of CPU.
+	CPU string `json:"CPU"`
+	// CPU a string-encoded float describing cost per core-hour of CPU for spot
+	// nodes.
+	SpotCPU string `json:"spotCPU"`
+	// RAM a string-encoded float describing cost per GiB-hour of RAM/memory.
+	RAM string `json:"RAM"`
+	// SpotRAM a string-encoded float describing cost per GiB-hour of RAM/memory
+	// for spot nodes.
+	SpotRAM string `json:"spotRAM"`
+	GPU     string `json:"GPU"`
+	SpotGPU string `json:"spotGPU"`
+	// Storage is a string-encoded float describing cost per GB-hour of storage
+	// (e.g. PV, disk) resources.
 	Storage                      string `json:"storage"`
 	ZoneNetworkEgress            string `json:"zoneNetworkEgress"`
 	RegionNetworkEgress          string `json:"regionNetworkEgress"`