Skip to content

Commit 5eb981b

Browse files
committed
add init sidecars to priority calcuations
1 parent 8f4ed38 commit 5eb981b

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

vertical-pod-autoscaler/pkg/updater/priority/priority_processor.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ func NewProcessor() PriorityProcessor {
4242
type defaultPriorityProcessor struct {
4343
}
4444

45-
// TODO: jklaw90 support initContainers
4645
func (*defaultPriorityProcessor) GetUpdatePriority(pod *apiv1.Pod, vpa *vpa_types.VerticalPodAutoscaler,
4746
recommendation *vpa_types.RecommendedPodResources) PodPriority {
4847
outsideRecommendedRange := false
@@ -54,14 +53,14 @@ func (*defaultPriorityProcessor) GetUpdatePriority(pod *apiv1.Pod, vpa *vpa_type
5453

5554
hasObservedContainers, vpaContainerSet := parseVpaObservedContainers(pod)
5655

57-
for _, podContainer := range pod.Spec.Containers {
56+
processContainer := func(podContainer apiv1.Container) {
5857
if hasObservedContainers && !vpaContainerSet.Has(podContainer.Name) {
5958
klog.V(4).InfoS("Not listed in VPA observed containers label. Skipping container priority calculations", "label", annotations.VpaObservedContainersLabel, "observedContainers", pod.GetAnnotations()[annotations.VpaObservedContainersLabel], "containerName", podContainer.Name, "vpa", klog.KObj(vpa))
60-
continue
59+
return
6160
}
6261
recommendedRequest := vpa_api_util.GetRecommendationForContainer(podContainer.Name, recommendation)
6362
if recommendedRequest == nil {
64-
continue
63+
return
6564
}
6665
for resourceName, recommended := range recommendedRequest.Target {
6766
totalRecommendedPerResource[resourceName] += recommended.MilliValue()
@@ -78,15 +77,19 @@ func (*defaultPriorityProcessor) GetUpdatePriority(pod *apiv1.Pod, vpa *vpa_type
7877
outsideRecommendedRange = true
7978
}
8079
} else {
81-
// Note: if the request is not specified, the container will use the
82-
// namespace default request. Currently we ignore it and treat such
83-
// containers as if they had 0 request. A more correct approach would
84-
// be to always calculate the 'effective' request.
8580
scaleUp = true
8681
outsideRecommendedRange = true
8782
}
8883
}
8984
}
85+
86+
for _, podContainer := range pod.Spec.Containers {
87+
processContainer(podContainer)
88+
}
89+
for _, initContainer := range pod.Spec.InitContainers {
90+
processContainer(initContainer)
91+
}
92+
9093
resourceDiff := 0.0
9194
for resource, totalRecommended := range totalRecommendedPerResource {
9295
totalRequest := math.Max(float64(totalRequestPerResource[resource]), 1.0)

0 commit comments

Comments
 (0)