Skip to content

Commit d945ca7

Browse files
authored
Merge pull request kubernetes#3641 from yaroslava-serdiuk/DS2
change how DaemonSet utilization is calculated
2 parents c90cf16 + 8480c79 commit d945ca7

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

cluster-autoscaler/simulator/cluster.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,15 @@ func calculateUtilizationOfResource(node *apiv1.Node, nodeInfo *schedulerframewo
258258
return 0, fmt.Errorf("%v is 0 at %s", resourceName, node.Name)
259259
}
260260
podsRequest := resource.MustParse("0")
261+
daemonSetUtilization := resource.MustParse("0")
261262
for _, podInfo := range nodeInfo.Pods {
262263
// factor daemonset pods out of the utilization calculations
263264
if skipDaemonSetPods && pod_util.IsDaemonSetPod(podInfo.Pod) {
265+
for _, container := range podInfo.Pod.Spec.Containers {
266+
if resourceValue, found := container.Resources.Requests[resourceName]; found {
267+
daemonSetUtilization.Add(resourceValue)
268+
}
269+
}
264270
continue
265271
}
266272
// factor mirror pods out of the utilization calculations
@@ -273,7 +279,7 @@ func calculateUtilizationOfResource(node *apiv1.Node, nodeInfo *schedulerframewo
273279
}
274280
}
275281
}
276-
return float64(podsRequest.MilliValue()) / float64(nodeAllocatable.MilliValue()), nil
282+
return float64(podsRequest.MilliValue()) / float64(nodeAllocatable.MilliValue()-daemonSetUtilization.MilliValue()), nil
277283
}
278284

279285
func findPlaceFor(removedNode string, pods []*apiv1.Pod, nodes map[string]bool,

cluster-autoscaler/simulator/cluster_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestUtilization(t *testing.T) {
5959
nodeInfo = schedulerframework.NewNodeInfo(pod, pod, pod2, daemonSetPod3, daemonSetPod4)
6060
utilInfo, err = CalculateUtilization(node, nodeInfo, true, false, gpuLabel)
6161
assert.NoError(t, err)
62-
assert.InEpsilon(t, 2.0/10, utilInfo.Utilization, 0.01)
62+
assert.InEpsilon(t, 2.5/10, utilInfo.Utilization, 0.01)
6363

6464
nodeInfo = schedulerframework.NewNodeInfo(pod, pod2, daemonSetPod3)
6565
utilInfo, err = CalculateUtilization(node, nodeInfo, false, false, gpuLabel)

0 commit comments

Comments
 (0)