Ver Fonte

fix paginated gpu merging

AjayTripathy há 7 anos atrás
pai
commit
dc0620119e
2 ficheiros alterados com 17 adições e 10 exclusões
  1. 11 8
      cloud/gcpprovider.go
  2. 6 2
      costmodel/costmodel.go

+ 11 - 8
cloud/gcpprovider.go

@@ -474,8 +474,10 @@ func (gcp *GCP) parsePage(r io.Reader, inputKeys map[string]Key, pvKeys map[stri
 									gcpPricingList[candidateKey] = product
 									gcpPricingList[candidateKey] = product
 								}
 								}
 								if _, ok := gcpPricingList[candidateKeyGPU]; ok {
 								if _, ok := gcpPricingList[candidateKeyGPU]; ok {
+									klog.V(1).Infof("Adding RAM %f for %s", hourlyPrice, candidateKeyGPU)
 									gcpPricingList[candidateKeyGPU].Node.RAMCost = strconv.FormatFloat(hourlyPrice, 'f', -1, 64)
 									gcpPricingList[candidateKeyGPU].Node.RAMCost = strconv.FormatFloat(hourlyPrice, 'f', -1, 64)
 								} else {
 								} else {
+									klog.V(1).Infof("Adding RAM %f for %s", hourlyPrice, candidateKeyGPU)
 									product.Node = &Node{
 									product.Node = &Node{
 										RAMCost: strconv.FormatFloat(hourlyPrice, 'f', -1, 64),
 										RAMCost: strconv.FormatFloat(hourlyPrice, 'f', -1, 64),
 									}
 									}
@@ -565,18 +567,19 @@ func (gcp *GCP) parsePages(inputKeys map[string]Key, pvKeys map[string]PVKey) (m
 		for k, v := range page {
 		for k, v := range page {
 			if val, ok := returnPages[k]; ok { //keys may need to be merged
 			if val, ok := returnPages[k]; ok { //keys may need to be merged
 				if val.Node != nil {
 				if val.Node != nil {
-					if val.Node.RAMCost != "" && val.Node.VCPUCost == "" {
+					if val.Node.VCPUCost == "" {
 						val.Node.VCPUCost = v.Node.VCPUCost
 						val.Node.VCPUCost = v.Node.VCPUCost
-					} else if val.Node.VCPUCost != "" && val.Node.RAMCost == "" {
+					}
+					if val.Node.RAMCost == "" {
 						val.Node.RAMCost = v.Node.RAMCost
 						val.Node.RAMCost = v.Node.RAMCost
-					} else {
-						returnPages[k] = v
 					}
 					}
-				} else if val.PV != nil {
-					if val.PV.Cost != "" {
+					if val.Node.GPUCost == "" {
+						val.Node.GPUCost = v.Node.GPUCost
+					}
+				}
+				if val.PV != nil {
+					if val.PV.Cost == "" {
 						val.PV.Cost = v.PV.Cost
 						val.PV.Cost = v.PV.Cost
-					} else {
-						returnPages[k] = v
 					}
 					}
 				}
 				}
 			} else {
 			} else {

+ 6 - 2
costmodel/costmodel.go

@@ -632,10 +632,10 @@ func getNodeCost(clientset kubernetes.Interface, cloud costAnalyzerCloud.Provide
 		ram = float64(n.Status.Capacity.Memory().Value())
 		ram = float64(n.Status.Capacity.Memory().Value())
 
 
 		if cnode.GPU != "" && cnode.GPUCost == "" { // We couldn't find a gpu cost, so fix cpu and ram, then accordingly
 		if cnode.GPU != "" && cnode.GPUCost == "" { // We couldn't find a gpu cost, so fix cpu and ram, then accordingly
-			klog.V(3).Infof("GPU without cost found, calculating...")
+			klog.V(3).Infof("GPU without cost found for %s, calculating...", cloud.GetKey(nodeLabels).Features())
 			basePrice, err := strconv.ParseFloat(cnode.BaseCPUPrice, 64)
 			basePrice, err := strconv.ParseFloat(cnode.BaseCPUPrice, 64)
 			if err != nil {
 			if err != nil {
-				return nil, err
+				klog.V(1).Infof("Error getting node. Error: " + err.Error())
 			}
 			}
 			nodePrice, err := strconv.ParseFloat(cnode.Cost, 64)
 			nodePrice, err := strconv.ParseFloat(cnode.Cost, 64)
 			if err != nil {
 			if err != nil {
@@ -652,8 +652,10 @@ func getNodeCost(clientset kubernetes.Interface, cloud costAnalyzerCloud.Provide
 			klog.V(2).Infof("Computed \"%s\" GPU Cost := %v", name, cnode.GPUCost)
 			klog.V(2).Infof("Computed \"%s\" GPU Cost := %v", name, cnode.GPUCost)
 		} else {
 		} else {
 			if cnode.RAMCost == "" { // We couldn't find a ramcost, so fix cpu and allocate ram accordingly
 			if cnode.RAMCost == "" { // We couldn't find a ramcost, so fix cpu and allocate ram accordingly
+				klog.V(3).Infof("No RAM cost found for %s, calculating...", cloud.GetKey(nodeLabels).Features())
 				basePrice, err := strconv.ParseFloat(cnode.BaseCPUPrice, 64)
 				basePrice, err := strconv.ParseFloat(cnode.BaseCPUPrice, 64)
 				if err != nil {
 				if err != nil {
+					klog.V(3).Infof("Could not find base total node price")
 					return nil, err
 					return nil, err
 				}
 				}
 				totalCPUPrice := basePrice * cpu
 				totalCPUPrice := basePrice * cpu
@@ -661,11 +663,13 @@ func getNodeCost(clientset kubernetes.Interface, cloud costAnalyzerCloud.Provide
 				if cnode.Cost != "" {
 				if cnode.Cost != "" {
 					nodePrice, err = strconv.ParseFloat(cnode.Cost, 64)
 					nodePrice, err = strconv.ParseFloat(cnode.Cost, 64)
 					if err != nil {
 					if err != nil {
+						klog.V(3).Infof("Could not parse total node price")
 						return nil, err
 						return nil, err
 					}
 					}
 				} else {
 				} else {
 					nodePrice, err = strconv.ParseFloat(cnode.VCPUCost, 64) // all the price was allocated the the CPU
 					nodePrice, err = strconv.ParseFloat(cnode.VCPUCost, 64) // all the price was allocated the the CPU
 					if err != nil {
 					if err != nil {
+						klog.V(3).Infof("Could not parse node vcpu price")
 						return nil, err
 						return nil, err
 					}
 					}
 				}
 				}