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

Merge branch 'develop' into bolt/cluster-manager

Matt Bolt 6 лет назад
Родитель
Сommit
cd276f9c0e
4 измененных файлов с 29 добавлено и 12 удалено
  1. 4 4
      README.md
  2. 1 0
      pkg/cloud/provider.go
  3. 3 0
      pkg/costmodel/costmodel.go
  4. 21 8
      pkg/costmodel/router.go

+ 4 - 4
README.md

@@ -1,12 +1,12 @@
-Kubecost models give teams visibility into current and historical Kubernetes spend and resource allocation. These models  provide cost transparency in Kubernetes environments that support multiple applications, teams, departments, etc.
+## Kubecost
 
 
-![Kubecost dashboard](https://github.com/kubecost/cost-model/blob/master/allocation-dashboard.png)
+Kubecost models give teams visibility into current and historical Kubernetes spend and resource allocation. These models  provide cost transparency in Kubernetes environments that support multiple applications, teams, departments, etc.
 
 
 To see more on the functionality of the full Kubecost product, please visit the [features page](https://kubecost.com/#features) on our website. 
 To see more on the functionality of the full Kubecost product, please visit the [features page](https://kubecost.com/#features) on our website. 
 Here is a summary of features enabled by this cost model:
 Here is a summary of features enabled by this cost model:
 
 
-- Real-time cost allocation for native Kubernetes concepts: service, deployment, namespace, label, daemonset, pod, container, and more
-- Dynamic asset pricing enabled by integrations with AWS, Azure and GCP billing APIs 
+- Real-time cost allocation by Kubernetes service, deployment, namespace, label, statefulset, daemonset, pod, and container
+- Dynamic asset pricing enabled by integrations with AWS, Azure, and GCP billing APIs 
 - Supports on-prem k8s clusters with custom pricing sheets
 - Supports on-prem k8s clusters with custom pricing sheets
 - Allocation for in-cluster resources like CPU, GPU, memory, and persistent volumes.
 - Allocation for in-cluster resources like CPU, GPU, memory, and persistent volumes.
 - Allocation for AWS & GCP out-of-cluster resources like RDS instances and S3 buckets with key (optional)
 - Allocation for AWS & GCP out-of-cluster resources like RDS instances and S3 buckets with key (optional)

+ 1 - 0
pkg/cloud/provider.go

@@ -58,6 +58,7 @@ type Node struct {
 	GPU              string                `json:"gpu"` // GPU represents the number of GPU on the instance
 	GPU              string                `json:"gpu"` // GPU represents the number of GPU on the instance
 	GPUName          string                `json:"gpuName"`
 	GPUName          string                `json:"gpuName"`
 	GPUCost          string                `json:"gpuCost"`
 	GPUCost          string                `json:"gpuCost"`
+	InstanceType     string                `json:"instanceType,omitempty"`
 	Reserved         *ReservedInstanceData `json:"reserved,omitempty"`
 	Reserved         *ReservedInstanceData `json:"reserved,omitempty"`
 }
 }
 
 

+ 3 - 0
pkg/costmodel/costmodel.go

@@ -1059,6 +1059,9 @@ func (cm *CostModel) GetNodeCost(cp costAnalyzerCloud.Provider) (map[string]*cos
 			}
 			}
 		}
 		}
 		newCnode := *cnode
 		newCnode := *cnode
+		if newCnode.InstanceType == "" {
+			newCnode.InstanceType = n.Labels[v1.LabelInstanceType]
+		}
 
 
 		var cpu float64
 		var cpu float64
 		if newCnode.VCPU == "" {
 		if newCnode.VCPU == "" {

+ 21 - 8
pkg/costmodel/router.go

@@ -583,6 +583,18 @@ func (p *Accesses) ClusterInfo(w http.ResponseWriter, r *http.Request, ps httpro
 	w.Header().Set("Access-Control-Allow-Origin", "*")
 	w.Header().Set("Access-Control-Allow-Origin", "*")
 
 
 	data, err := p.Cloud.ClusterInfo()
 	data, err := p.Cloud.ClusterInfo()
+
+	kc, ok := p.KubeClientSet.(*kubernetes.Clientset)
+	if ok && data != nil {
+		v, err := kc.ServerVersion()
+		if err != nil {
+			klog.Infof("Could not get k8s version info: %s", err.Error())
+		} else if v != nil {
+			data["version"] = v.Major + "." + v.Minor
+		}
+	} else {
+		klog.Infof("Could not get k8s version info: %s", err.Error())
+	}
 	w.Write(WrapData(data, err))
 	w.Write(WrapData(data, err))
 
 
 }
 }
@@ -677,13 +689,14 @@ func (a *Accesses) recordPrices() {
 						gpuCost = 0
 						gpuCost = 0
 					}
 					}
 				}
 				}
+				nodeType := node.InstanceType
 
 
 				totalCost := cpu*cpuCost + ramCost*(ram/1024/1024/1024) + gpu*gpuCost
 				totalCost := cpu*cpuCost + ramCost*(ram/1024/1024/1024) + gpu*gpuCost
 
 
-				a.CPUPriceRecorder.WithLabelValues(nodeName, nodeName).Set(cpuCost)
-				a.RAMPriceRecorder.WithLabelValues(nodeName, nodeName).Set(ramCost)
-				a.GPUPriceRecorder.WithLabelValues(nodeName, nodeName).Set(gpuCost)
-				a.NodeTotalPriceRecorder.WithLabelValues(nodeName, nodeName).Set(totalCost)
+				a.CPUPriceRecorder.WithLabelValues(nodeName, nodeName, nodeType).Set(cpuCost)
+				a.RAMPriceRecorder.WithLabelValues(nodeName, nodeName, nodeType).Set(ramCost)
+				a.GPUPriceRecorder.WithLabelValues(nodeName, nodeName, nodeType).Set(gpuCost)
+				a.NodeTotalPriceRecorder.WithLabelValues(nodeName, nodeName, nodeType).Set(totalCost)
 				labelKey := getKeyFromLabelStrings(nodeName, nodeName)
 				labelKey := getKeyFromLabelStrings(nodeName, nodeName)
 				nodeSeen[labelKey] = true
 				nodeSeen[labelKey] = true
 			}
 			}
@@ -908,22 +921,22 @@ func Initialize() {
 	cpuGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 	cpuGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "node_cpu_hourly_cost",
 		Name: "node_cpu_hourly_cost",
 		Help: "node_cpu_hourly_cost hourly cost for each cpu on this node",
 		Help: "node_cpu_hourly_cost hourly cost for each cpu on this node",
-	}, []string{"instance", "node"})
+	}, []string{"instance", "node", "instance_type"})
 
 
 	ramGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 	ramGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "node_ram_hourly_cost",
 		Name: "node_ram_hourly_cost",
 		Help: "node_ram_hourly_cost hourly cost for each gb of ram on this node",
 		Help: "node_ram_hourly_cost hourly cost for each gb of ram on this node",
-	}, []string{"instance", "node"})
+	}, []string{"instance", "node", "instance_type"})
 
 
 	gpuGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 	gpuGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "node_gpu_hourly_cost",
 		Name: "node_gpu_hourly_cost",
 		Help: "node_gpu_hourly_cost hourly cost for each gpu on this node",
 		Help: "node_gpu_hourly_cost hourly cost for each gpu on this node",
-	}, []string{"instance", "node"})
+	}, []string{"instance", "node", "instance_type"})
 
 
 	totalGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 	totalGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "node_total_hourly_cost",
 		Name: "node_total_hourly_cost",
 		Help: "node_total_hourly_cost Total node cost per hour",
 		Help: "node_total_hourly_cost Total node cost per hour",
-	}, []string{"instance", "node"})
+	}, []string{"instance", "node", "instance_type"})
 
 
 	pvGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 	pvGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "pv_hourly_cost",
 		Name: "pv_hourly_cost",