Merge pull request #132 from zryfish/fix_resource_limit
fix resource limit
This commit is contained in:
@@ -83,7 +83,7 @@ func FormatContainerMetrics(namespace, podName, containerName string) ContainerM
|
||||
cpuRequestMetrics, err := cpuRequest.GetObjectArray("metrics")
|
||||
if err == nil && len(cpuRequestMetrics) != 0 {
|
||||
requestCpu, _ := cpuRequestMetrics[0].GetFloat64("value")
|
||||
resultContainer.CpuRequest = fmt.Sprintf("%.1f", requestCpu)
|
||||
resultContainer.CpuRequest = FormatResourceLimit(requestCpu)
|
||||
} else {
|
||||
resultContainer.CpuRequest = Inf
|
||||
}
|
||||
@@ -92,7 +92,7 @@ func FormatContainerMetrics(namespace, podName, containerName string) ContainerM
|
||||
cpuLimitMetrics, err := cpuLimit.GetObjectArray("metrics")
|
||||
if err == nil && len(cpuLimitMetrics) != 0 {
|
||||
limitCpu, _ := cpuLimitMetrics[0].GetFloat64("value")
|
||||
resultContainer.CpuLimit = fmt.Sprintf("%.1f", limitCpu)
|
||||
resultContainer.CpuLimit = FormatResourceLimit(limitCpu)
|
||||
} else {
|
||||
resultContainer.CpuLimit = Inf
|
||||
}
|
||||
@@ -101,7 +101,7 @@ func FormatContainerMetrics(namespace, podName, containerName string) ContainerM
|
||||
memoryRequstMetrics, err := memoryRequst.GetObjectArray("metrics")
|
||||
if err == nil && len(memoryRequstMetrics) != 0 {
|
||||
requestMemory, _ := memoryRequstMetrics[0].GetFloat64("value")
|
||||
resultContainer.MemoryRequest = fmt.Sprintf("%.1f", requestMemory)
|
||||
resultContainer.MemoryRequest = FormatResourceLimit(requestMemory)
|
||||
} else {
|
||||
resultContainer.MemoryRequest = Inf
|
||||
}
|
||||
@@ -110,7 +110,7 @@ func FormatContainerMetrics(namespace, podName, containerName string) ContainerM
|
||||
memoryLimitMetrics, err := memoryLimit.GetObjectArray("metrics")
|
||||
if err == nil && len(memoryLimitMetrics) != 0 {
|
||||
limitMemory, _ := memoryLimitMetrics[0].GetFloat64("value")
|
||||
resultContainer.MemoryLimit = fmt.Sprintf("%.1f", limitMemory)
|
||||
resultContainer.MemoryLimit = FormatResourceLimit(limitMemory)
|
||||
} else {
|
||||
resultContainer.MemoryLimit = Inf
|
||||
}
|
||||
|
||||
@@ -228,6 +228,14 @@ func GetAllPodMetrics() constants.PageableResponse {
|
||||
return podMetrics
|
||||
}
|
||||
|
||||
func FormatResourceLimit(limit float64) string {
|
||||
if limit <= 0 {
|
||||
return Inf
|
||||
} else {
|
||||
return fmt.Sprintf("%.1f", limit)
|
||||
}
|
||||
}
|
||||
|
||||
func FormatPodMetrics(namespace string, pod string) PodMetrics {
|
||||
|
||||
var resultPod PodMetrics
|
||||
@@ -260,8 +268,8 @@ func FormatPodMetrics(namespace string, pod string) PodMetrics {
|
||||
if len(cpuLimitMetrics) == 0 {
|
||||
resultPod.CPULimit = Inf
|
||||
} else {
|
||||
data, _ := cpuLimitMetrics[0].GetNumber("value")
|
||||
resultPod.CPULimit = data.String()
|
||||
data, _ := cpuLimitMetrics[0].GetFloat64("value")
|
||||
resultPod.CPULimit = FormatResourceLimit(data)
|
||||
}
|
||||
|
||||
memoryRequest := client.GetHeapsterMetricsJson("/namespaces/" + namespace + "/pods/" + pod + "/metrics/memory/request")
|
||||
@@ -276,7 +284,7 @@ func FormatPodMetrics(namespace string, pod string) PodMetrics {
|
||||
data, _ := memoryRequestMetrics[0].GetNumber("value")
|
||||
memoryReq, _ := data.Float64()
|
||||
memoryReq = memoryReq / 1024 / 1024
|
||||
resultPod.MemoryRequest = fmt.Sprintf("%.1f", memoryReq)
|
||||
resultPod.MemoryRequest = FormatResourceLimit(memoryReq)
|
||||
}
|
||||
|
||||
memoryLimit := client.GetHeapsterMetricsJson("/namespaces/" + namespace + "/pods/" + pod + "/metrics/memory/limit")
|
||||
@@ -288,7 +296,7 @@ func FormatPodMetrics(namespace string, pod string) PodMetrics {
|
||||
data, _ := memoryLimitMetrics[0].GetNumber("value")
|
||||
memoryLim, _ := data.Float64()
|
||||
memoryLim = memoryLim / 1024 / 1024
|
||||
resultPod.MemoryLimit = fmt.Sprintf("%.1f", memoryLim)
|
||||
resultPod.MemoryLimit = FormatResourceLimit(memoryLim)
|
||||
}
|
||||
|
||||
cpuUsageRate := client.GetHeapsterMetricsJson("/namespaces/" + namespace + "/pods/" + pod + "/metrics/cpu/usage_rate")
|
||||
|
||||
@@ -76,7 +76,7 @@ func GetAllRoutersOfUser(username string) ([]coreV1.Service, error) {
|
||||
allNamespace, namespaces, err := iam.GetUserNamespaces(username, v1.PolicyRule{
|
||||
Verbs: []string{"get", "list"},
|
||||
APIGroups: []string{"extensions"},
|
||||
Resources: []string{"ingresses"},
|
||||
Resources: []string{"services"},
|
||||
})
|
||||
|
||||
// return by cluster role
|
||||
|
||||
Reference in New Issue
Block a user