mirror of
https://github.com/outbackdingo/cozystack.git
synced 2026-01-27 18:18:41 +00:00
* Count Workload resources for pods by requests, not limits * Do not count init container requests * Prefix Workloads for pods with `pod-`, just like the other types to prevent possible name collisions (closes #787) The previous version of the WorkloadMonitor controller incorrectly summed resource limits on pods, rather than requests. This prevented it from tracking the resource allocation for pods, which only had requests specified, which is particularly the case for kubevirt's virtual machine pods. Additionally, it counted the limits for all containers, including init containers, which are short-lived and do not contribute much to the total resource usage. Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
27 lines
687 B
Go
27 lines
687 B
Go
package controller
|
|
|
|
import (
|
|
"testing"
|
|
|
|
cozyv1alpha1 "github.com/cozystack/cozystack/api/v1alpha1"
|
|
corev1 "k8s.io/api/core/v1"
|
|
)
|
|
|
|
func TestUnprefixedMonitoredObjectReturnsNil(t *testing.T) {
|
|
w := &cozyv1alpha1.Workload{}
|
|
w.Name = "unprefixed-name"
|
|
obj := getMonitoredObject(w)
|
|
if obj != nil {
|
|
t.Errorf(`getMonitoredObject(&Workload{Name: "%s"}) == %v, want nil`, w.Name, obj)
|
|
}
|
|
}
|
|
|
|
func TestPodMonitoredObject(t *testing.T) {
|
|
w := &cozyv1alpha1.Workload{}
|
|
w.Name = "pod-mypod"
|
|
obj := getMonitoredObject(w)
|
|
if pod, ok := obj.(*corev1.Pod); !ok || pod.Name != "mypod" {
|
|
t.Errorf(`getMonitoredObject(&Workload{Name: "%s"}) == %v, want &Pod{Name: "mypod"}`, w.Name, obj)
|
|
}
|
|
}
|