diff --git a/api/kubernetes/cli/applications.go b/api/kubernetes/cli/applications.go index d12ab0575..90b7774e9 100644 --- a/api/kubernetes/cli/applications.go +++ b/api/kubernetes/cli/applications.go @@ -133,7 +133,7 @@ func (kcl *KubeClient) GetApplicationsResource(namespace, node string) (models.K } for _, pod := range pods.Items { - podResources := calculateResourceUsage(pod) + podResources := calculatePodResourceUsage(pod) resource.CPURequest += podResources.CPURequest resource.CPULimit += podResources.CPULimit resource.MemoryRequest += podResources.MemoryRequest @@ -191,7 +191,12 @@ func (kcl *KubeClient) ConvertPodToApplication(pod corev1.Pod, replicaSets []app } if withResource { - application.Resource = calculateResourceUsage(pod) + podResources := calculatePodResourceUsage(pod) + // multiply by the number of requested pods in the application (not the running count) + application.Resource.CPURequest = podResources.CPURequest * float64(application.TotalPodsCount) + application.Resource.CPULimit = podResources.CPULimit * float64(application.TotalPodsCount) + application.Resource.MemoryRequest = podResources.MemoryRequest * int64(application.TotalPodsCount) + application.Resource.MemoryLimit = podResources.MemoryLimit * int64(application.TotalPodsCount) } return &application, nil @@ -340,8 +345,8 @@ func updateApplicationWithService(application models.K8sApplication, services [] return application } -// calculateResourceUsage calculates the resource usage for a pod in CPU cores and Bytes -func calculateResourceUsage(pod corev1.Pod) models.K8sApplicationResource { +// calculatePodResourceUsage calculates the resource usage for a pod in CPU cores and Bytes +func calculatePodResourceUsage(pod corev1.Pod) models.K8sApplicationResource { resource := models.K8sApplicationResource{} for _, container := range pod.Spec.Containers { // CPU cores as a decimal