|
@@ -231,29 +231,32 @@ func ComputeCostData(cli prometheusClient.Client, clientset kubernetes.Interface
|
|
|
for i, container := range pod.Spec.Containers {
|
|
for i, container := range pod.Spec.Containers {
|
|
|
containerName := container.Name
|
|
containerName := container.Name
|
|
|
|
|
|
|
|
- RAMReqV, ok := RAMReqMap[key]
|
|
|
|
|
|
|
+ // recreate the key and look up data for this container
|
|
|
|
|
+ newKey := ns + "," + podName + "," + containerName
|
|
|
|
|
+
|
|
|
|
|
+ RAMReqV, ok := RAMReqMap[newKey]
|
|
|
if !ok {
|
|
if !ok {
|
|
|
- klog.V(2).Info("no RAM requests for " + key)
|
|
|
|
|
|
|
+ klog.V(2).Info("no RAM requests for " + newKey)
|
|
|
RAMReqV = []*Vector{&Vector{}}
|
|
RAMReqV = []*Vector{&Vector{}}
|
|
|
}
|
|
}
|
|
|
- RAMUsedV, ok := RAMUsedMap[key]
|
|
|
|
|
|
|
+ RAMUsedV, ok := RAMUsedMap[newKey]
|
|
|
if !ok {
|
|
if !ok {
|
|
|
- klog.V(2).Info("no RAM usage for " + key)
|
|
|
|
|
|
|
+ klog.V(2).Info("no RAM usage for " + newKey)
|
|
|
RAMUsedV = []*Vector{&Vector{}}
|
|
RAMUsedV = []*Vector{&Vector{}}
|
|
|
}
|
|
}
|
|
|
- CPUReqV, ok := CPUReqMap[key]
|
|
|
|
|
|
|
+ CPUReqV, ok := CPUReqMap[newKey]
|
|
|
if !ok {
|
|
if !ok {
|
|
|
- klog.V(2).Info("no CPU requests for " + key)
|
|
|
|
|
|
|
+ klog.V(2).Info("no CPU requests for " + newKey)
|
|
|
CPUReqV = []*Vector{&Vector{}}
|
|
CPUReqV = []*Vector{&Vector{}}
|
|
|
}
|
|
}
|
|
|
- GPUReqV, ok := GPUReqMap[key]
|
|
|
|
|
|
|
+ GPUReqV, ok := GPUReqMap[newKey]
|
|
|
if !ok {
|
|
if !ok {
|
|
|
- klog.V(2).Info("no GPU requests for " + key)
|
|
|
|
|
|
|
+ klog.V(2).Info("no GPU requests for " + newKey)
|
|
|
GPUReqV = []*Vector{&Vector{}}
|
|
GPUReqV = []*Vector{&Vector{}}
|
|
|
}
|
|
}
|
|
|
- CPUUsedV, ok := CPUUsedMap[key]
|
|
|
|
|
|
|
+ CPUUsedV, ok := CPUUsedMap[newKey]
|
|
|
if !ok {
|
|
if !ok {
|
|
|
- klog.V(2).Info("no CPU usage for " + key)
|
|
|
|
|
|
|
+ klog.V(2).Info("no CPU usage for " + newKey)
|
|
|
CPUUsedV = []*Vector{&Vector{}}
|
|
CPUUsedV = []*Vector{&Vector{}}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -283,13 +286,13 @@ func ComputeCostData(cli prometheusClient.Client, clientset kubernetes.Interface
|
|
|
}
|
|
}
|
|
|
costs.CPUAllocation = getContainerAllocation(costs.CPUReq, costs.CPUUsed)
|
|
costs.CPUAllocation = getContainerAllocation(costs.CPUReq, costs.CPUUsed)
|
|
|
costs.RAMAllocation = getContainerAllocation(costs.RAMReq, costs.RAMUsed)
|
|
costs.RAMAllocation = getContainerAllocation(costs.RAMReq, costs.RAMUsed)
|
|
|
- containerNameCost[key] = costs
|
|
|
|
|
|
|
+ containerNameCost[newKey] = costs
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
// The container has been deleted. Not all information is sent to prometheus via ksm, so fill out what we can without k8s api
|
|
// The container has been deleted. Not all information is sent to prometheus via ksm, so fill out what we can without k8s api
|
|
|
// TODO: The nodename should be available from the prometheus query. Check if that node still exists and use that price
|
|
// TODO: The nodename should be available from the prometheus query. Check if that node still exists and use that price
|
|
|
- klog.V(3).Info("The node " + key + " has been deleted. Calculating allocation but resulting object will be missing data.")
|
|
|
|
|
|
|
+ klog.V(3).Info("The container " + key + " has been deleted. Calculating allocation but resulting object will be missing data.")
|
|
|
c, _ := newContainerMetricFromKey(key)
|
|
c, _ := newContainerMetricFromKey(key)
|
|
|
RAMReqV, ok := RAMReqMap[key]
|
|
RAMReqV, ok := RAMReqMap[key]
|
|
|
if !ok {
|
|
if !ok {
|
|
@@ -687,29 +690,31 @@ func ComputeCostDataRange(cli prometheusClient.Client, clientset kubernetes.Inte
|
|
|
for i, container := range pod.Spec.Containers {
|
|
for i, container := range pod.Spec.Containers {
|
|
|
containerName := container.Name
|
|
containerName := container.Name
|
|
|
|
|
|
|
|
- RAMReqV, ok := RAMReqMap[key]
|
|
|
|
|
|
|
+ newKey := ns + "," + podName + "," + containerName
|
|
|
|
|
+
|
|
|
|
|
+ RAMReqV, ok := RAMReqMap[newKey]
|
|
|
if !ok {
|
|
if !ok {
|
|
|
- klog.V(2).Info("no RAM requests for " + key)
|
|
|
|
|
|
|
+ klog.V(2).Info("no RAM requests for " + newKey)
|
|
|
RAMReqV = []*Vector{}
|
|
RAMReqV = []*Vector{}
|
|
|
}
|
|
}
|
|
|
- RAMUsedV, ok := RAMUsedMap[key]
|
|
|
|
|
|
|
+ RAMUsedV, ok := RAMUsedMap[newKey]
|
|
|
if !ok {
|
|
if !ok {
|
|
|
- klog.V(2).Info("no RAM usage for " + key)
|
|
|
|
|
|
|
+ klog.V(2).Info("no RAM usage for " + newKey)
|
|
|
RAMUsedV = []*Vector{}
|
|
RAMUsedV = []*Vector{}
|
|
|
}
|
|
}
|
|
|
- CPUReqV, ok := CPUReqMap[key]
|
|
|
|
|
|
|
+ CPUReqV, ok := CPUReqMap[newKey]
|
|
|
if !ok {
|
|
if !ok {
|
|
|
- klog.V(2).Info("no CPU requests for " + key)
|
|
|
|
|
|
|
+ klog.V(2).Info("no CPU requests for " + newKey)
|
|
|
CPUReqV = []*Vector{}
|
|
CPUReqV = []*Vector{}
|
|
|
}
|
|
}
|
|
|
- GPUReqV, ok := GPUReqMap[key]
|
|
|
|
|
|
|
+ GPUReqV, ok := GPUReqMap[newKey]
|
|
|
if !ok {
|
|
if !ok {
|
|
|
- klog.V(2).Info("no GPU requests for " + key)
|
|
|
|
|
|
|
+ klog.V(2).Info("no GPU requests for " + newKey)
|
|
|
GPUReqV = []*Vector{}
|
|
GPUReqV = []*Vector{}
|
|
|
}
|
|
}
|
|
|
- CPUUsedV, ok := CPUUsedMap[key]
|
|
|
|
|
|
|
+ CPUUsedV, ok := CPUUsedMap[newKey]
|
|
|
if !ok {
|
|
if !ok {
|
|
|
- klog.V(2).Info("no CPU usage for " + key)
|
|
|
|
|
|
|
+ klog.V(2).Info("no CPU usage for " + newKey)
|
|
|
CPUUsedV = []*Vector{}
|
|
CPUUsedV = []*Vector{}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -739,13 +744,13 @@ func ComputeCostDataRange(cli prometheusClient.Client, clientset kubernetes.Inte
|
|
|
}
|
|
}
|
|
|
costs.CPUAllocation = getContainerAllocation(costs.CPUReq, costs.CPUUsed)
|
|
costs.CPUAllocation = getContainerAllocation(costs.CPUReq, costs.CPUUsed)
|
|
|
costs.RAMAllocation = getContainerAllocation(costs.RAMReq, costs.RAMUsed)
|
|
costs.RAMAllocation = getContainerAllocation(costs.RAMReq, costs.RAMUsed)
|
|
|
- containerNameCost[key] = costs
|
|
|
|
|
|
|
+ containerNameCost[newKey] = costs
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
// The container has been deleted. Not all information is sent to prometheus via ksm, so fill out what we can without k8s api
|
|
// The container has been deleted. Not all information is sent to prometheus via ksm, so fill out what we can without k8s api
|
|
|
// TODO: The nodename should be available from the prometheus query. Check if that node still exists and use that price
|
|
// TODO: The nodename should be available from the prometheus query. Check if that node still exists and use that price
|
|
|
- klog.V(3).Info("The node " + key + " has been deleted. Calculating allocation but resulting object will be missing data.")
|
|
|
|
|
|
|
+ klog.V(3).Info("The container " + key + " has been deleted. Calculating allocation but resulting object will be missing data.")
|
|
|
c, _ := newContainerMetricFromKey(key)
|
|
c, _ := newContainerMetricFromKey(key)
|
|
|
RAMReqV, ok := RAMReqMap[key]
|
|
RAMReqV, ok := RAMReqMap[key]
|
|
|
if !ok {
|
|
if !ok {
|