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

Fix a variable-package name collision warning

`labels` from the apimachinery, and `labels` as a var, and same with `json`
Matthew L Daniel 7 лет назад
Родитель
Сommit
5bd153e48d
2 измененных файлов с 9 добавлено и 10 удалено
  1. 2 2
      cloud/awsprovider.go
  2. 7 8
      costmodel/costmodel.go

+ 2 - 2
cloud/awsprovider.go

@@ -333,11 +333,11 @@ func (*AWS) AddServiceKey(formValues url.Values) error {
 	m := make(map[string]string)
 	m["access_key_ID"] = keyID
 	m["secret_access_key"] = key
-	json, err := json.Marshal(m)
+	result, err := json.Marshal(m)
 	if err != nil {
 		return err
 	}
-	return ioutil.WriteFile("/var/configs/key.json", json, 0644)
+	return ioutil.WriteFile("/var/configs/key.json", result, 0644)
 }
 
 // GetDisks returns the AWS disks backing PVs. Useful because sometimes k8s will not clean up PVs correctly. Requires a json config in /var/configs with key region.

+ 7 - 8
costmodel/costmodel.go

@@ -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"
@@ -111,7 +111,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 {
@@ -180,7 +180,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)
@@ -244,8 +244,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())
 		}
@@ -290,7 +290,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
@@ -421,7 +420,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 {
@@ -500,7 +499,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)