Skip to content

Commit

Permalink
Addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ingvagabund committed Nov 20, 2024
1 parent b740ec1 commit 6305d68
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pkg/descheduler/metricscollector/metricscollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ func (mc *MetricsCollector) Run(ctx context.Context) {
}, 5*time.Second, ctx.Done())
}

// During experiments rounding to int error causes weightedAverage to never
// reach value even when weightedAverage is repeated many times in a row.
// The difference between the limit and computed average stops within 5 units.
// Nevertheless, the value is expected to change in time. So the weighted
// average nevers gets a chance to converge. Which makes the computed
// error negligible.
func weightedAverage(prevValue, value int64) int64 {
return int64(math.Round(beta*float64(prevValue) + (1-beta)*float64(value)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ func TestLowNodeUtilization(t *testing.T) {
fakeClient := fake.NewSimpleClientset(objs...)

var collector *metricscollector.MetricsCollector
if len(tc.nodemetricses) > 0 || len(tc.podmetricses) > 0 {
if metricsEnabled {
metricsClientset := fakemetricsclient.NewSimpleClientset()
for _, nodemetrics := range tc.nodemetricses {
metricsClientset.Tracker().Create(nodesgvr, nodemetrics, "")
Expand Down
5 changes: 4 additions & 1 deletion pkg/framework/plugins/nodeutilization/usageclients.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,12 @@ func (client *actualUsageClient) podUsage(pod *v1.Pod) (map[v1.ResourceName]*res
totalUsage := make(map[v1.ResourceName]*resource.Quantity)
for _, container := range podMetrics.Containers {
for _, resourceName := range client.resourceNames {
if _, exists := container.Usage[resourceName]; !exists {
if resourceName == v1.ResourcePods {
continue
}
if _, exists := container.Usage[resourceName]; !exists {
return nil, fmt.Errorf("pod %v/%v: container %q is missing %q resource", pod.Namespace, pod.Name, container.Name, resourceName)
}
if totalUsage[resourceName] == nil {
totalUsage[resourceName] = utilptr.To[resource.Quantity](container.Usage[resourceName].DeepCopy())
} else {
Expand Down

0 comments on commit 6305d68

Please sign in to comment.