|
|
@@ -13,7 +13,7 @@ import (
|
|
|
|
|
|
costAnalyzerCloud "github.com/kubecost/cost-model/cloud"
|
|
|
prometheusClient "github.com/prometheus/client_golang/api"
|
|
|
- v1 "k8s.io/api/core/v1"
|
|
|
+ "k8s.io/api/core/v1"
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
"k8s.io/apimachinery/pkg/labels"
|
|
|
"k8s.io/client-go/kubernetes"
|
|
|
@@ -112,7 +112,7 @@ func ComputeCostData(cli prometheusClient.Client, clientset *kubernetes.Clientse
|
|
|
for _, pod := range podlist.Items {
|
|
|
podName := pod.GetObjectMeta().GetName()
|
|
|
ns := pod.GetObjectMeta().GetNamespace()
|
|
|
- labels := pod.GetObjectMeta().GetLabels()
|
|
|
+ podLabels := pod.GetObjectMeta().GetLabels()
|
|
|
nodeName := pod.Spec.NodeName
|
|
|
var nodeData *costAnalyzerCloud.Node
|
|
|
if _, ok := nodes[nodeName]; ok {
|
|
|
@@ -181,7 +181,7 @@ func ComputeCostData(cli prometheusClient.Client, clientset *kubernetes.Clientse
|
|
|
CPUUsed: []*Vector{findContainerMetric(resultCPUUsage, containerName, podName, ns)},
|
|
|
GPUReq: []*Vector{GPUReqV},
|
|
|
PVData: pvReq,
|
|
|
- Labels: labels,
|
|
|
+ Labels: podLabels,
|
|
|
}
|
|
|
costs.CPUAllocation = getContainerAllocation(costs.CPUReq, costs.CPUUsed)
|
|
|
costs.RAMAllocation = getContainerAllocation(costs.RAMReq, costs.RAMUsed)
|
|
|
@@ -245,8 +245,8 @@ func getNodeCost(clientset *kubernetes.Clientset, cloud costAnalyzerCloud.Provid
|
|
|
nodes := make(map[string]*costAnalyzerCloud.Node)
|
|
|
for _, n := range nodeList.Items {
|
|
|
name := n.GetObjectMeta().GetName()
|
|
|
- labels := n.GetObjectMeta().GetLabels()
|
|
|
- cnode, err := cloud.NodePricing(cloud.GetKey(labels))
|
|
|
+ nodeLabels := n.GetObjectMeta().GetLabels()
|
|
|
+ cnode, err := cloud.NodePricing(cloud.GetKey(nodeLabels))
|
|
|
if err != nil {
|
|
|
log.Printf("Error getting node. Error: " + err.Error())
|
|
|
continue
|
|
|
@@ -269,10 +269,10 @@ func getNodeCost(clientset *kubernetes.Clientset, cloud costAnalyzerCloud.Provid
|
|
|
totalCPUPrice := basePrice * cpu
|
|
|
var nodePrice float64
|
|
|
if cnode.Cost != "" {
|
|
|
- log.Printf("Use given nodeprice as whole node price")
|
|
|
+ log.Print("Use given nodeprice as whole node price")
|
|
|
nodePrice, _ = strconv.ParseFloat(cnode.Cost, 64)
|
|
|
} else {
|
|
|
- log.Printf("Use cpuprice as whole node price")
|
|
|
+ log.Print("Use cpuprice as whole node price")
|
|
|
nodePrice, _ = strconv.ParseFloat(cnode.VCPUCost, 64) // all the price was allocated the the CPU
|
|
|
}
|
|
|
if totalCPUPrice >= nodePrice {
|
|
|
@@ -284,7 +284,7 @@ func getNodeCost(clientset *kubernetes.Clientset, cloud costAnalyzerCloud.Provid
|
|
|
cnode.VCPUCost = fmt.Sprintf("%f", cpuPrice)
|
|
|
cnode.RAMCost = fmt.Sprintf("%f", ramPrice)
|
|
|
cnode.RAMBytes = fmt.Sprintf("%f", ram)
|
|
|
- log.Printf(cnode.RAMCost)
|
|
|
+ log.Printf("Node \"%s\" RAM Cost := %v", name, cnode.RAMCost)
|
|
|
}
|
|
|
nodes[name] = cnode
|
|
|
}
|
|
|
@@ -292,7 +292,6 @@ func getNodeCost(clientset *kubernetes.Clientset, cloud costAnalyzerCloud.Provid
|
|
|
}
|
|
|
|
|
|
func getPodServices(clientset *kubernetes.Clientset, podList *v1.PodList) (map[string]map[string][]string, error) {
|
|
|
- //servicesList, err := clientset.Core().Services("").List(metav1.ListOptions{})
|
|
|
servicesList, err := clientset.CoreV1().Services("").List(metav1.ListOptions{})
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
@@ -423,7 +422,7 @@ func ComputeCostDataRange(cli prometheusClient.Client, clientset *kubernetes.Cli
|
|
|
for _, pod := range podlist.Items {
|
|
|
podName := pod.GetObjectMeta().GetName()
|
|
|
ns := pod.GetObjectMeta().GetNamespace()
|
|
|
- labels := pod.GetObjectMeta().GetLabels()
|
|
|
+ podLabels := pod.GetObjectMeta().GetLabels()
|
|
|
nodeName := pod.Spec.NodeName
|
|
|
var nodeData *costAnalyzerCloud.Node
|
|
|
if _, ok := nodes[nodeName]; ok {
|
|
|
@@ -502,7 +501,7 @@ func ComputeCostDataRange(cli prometheusClient.Client, clientset *kubernetes.Cli
|
|
|
CPUUsed: findContainerMetricVectors(resultCPUUsage, containerName, podName, ns),
|
|
|
GPUReq: GPUReqV,
|
|
|
PVData: pvReq,
|
|
|
- Labels: labels,
|
|
|
+ Labels: podLabels,
|
|
|
}
|
|
|
costs.RAMAllocation = getContainerAllocation(costs.RAMReq, costs.RAMUsed)
|
|
|
costs.CPUAllocation = getContainerAllocation(costs.CPUReq, costs.CPUUsed)
|