mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
fix(applications): scale resource usage by pod count [r8s-127] (#33)
Some checks failed
Label Conflicts / triage (push) Has been cancelled
Some checks failed
Label Conflicts / triage (push) Has been cancelled
This commit is contained in:
parent
da4b2e3a56
commit
7b88975bcb
1 changed files with 9 additions and 4 deletions
|
@ -133,7 +133,7 @@ func (kcl *KubeClient) GetApplicationsResource(namespace, node string) (models.K
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, pod := range pods.Items {
|
for _, pod := range pods.Items {
|
||||||
podResources := calculateResourceUsage(pod)
|
podResources := calculatePodResourceUsage(pod)
|
||||||
resource.CPURequest += podResources.CPURequest
|
resource.CPURequest += podResources.CPURequest
|
||||||
resource.CPULimit += podResources.CPULimit
|
resource.CPULimit += podResources.CPULimit
|
||||||
resource.MemoryRequest += podResources.MemoryRequest
|
resource.MemoryRequest += podResources.MemoryRequest
|
||||||
|
@ -191,7 +191,12 @@ func (kcl *KubeClient) ConvertPodToApplication(pod corev1.Pod, replicaSets []app
|
||||||
}
|
}
|
||||||
|
|
||||||
if withResource {
|
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
|
return &application, nil
|
||||||
|
@ -340,8 +345,8 @@ func updateApplicationWithService(application models.K8sApplication, services []
|
||||||
return application
|
return application
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculateResourceUsage calculates the resource usage for a pod in CPU cores and Bytes
|
// calculatePodResourceUsage calculates the resource usage for a pod in CPU cores and Bytes
|
||||||
func calculateResourceUsage(pod corev1.Pod) models.K8sApplicationResource {
|
func calculatePodResourceUsage(pod corev1.Pod) models.K8sApplicationResource {
|
||||||
resource := models.K8sApplicationResource{}
|
resource := models.K8sApplicationResource{}
|
||||||
for _, container := range pod.Spec.Containers {
|
for _, container := range pod.Spec.Containers {
|
||||||
// CPU cores as a decimal
|
// CPU cores as a decimal
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue