@@ -42,7 +42,6 @@ func NewProcessor() PriorityProcessor {
42
42
type defaultPriorityProcessor struct {
43
43
}
44
44
45
- // TODO: jklaw90 support initContainers
46
45
func (* defaultPriorityProcessor ) GetUpdatePriority (pod * apiv1.Pod , vpa * vpa_types.VerticalPodAutoscaler ,
47
46
recommendation * vpa_types.RecommendedPodResources ) PodPriority {
48
47
outsideRecommendedRange := false
@@ -54,14 +53,14 @@ func (*defaultPriorityProcessor) GetUpdatePriority(pod *apiv1.Pod, vpa *vpa_type
54
53
55
54
hasObservedContainers , vpaContainerSet := parseVpaObservedContainers (pod )
56
55
57
- for _ , podContainer := range pod . Spec . Containers {
56
+ processContainer := func ( podContainer apiv1. Container ) {
58
57
if hasObservedContainers && ! vpaContainerSet .Has (podContainer .Name ) {
59
58
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
61
60
}
62
61
recommendedRequest := vpa_api_util .GetRecommendationForContainer (podContainer .Name , recommendation )
63
62
if recommendedRequest == nil {
64
- continue
63
+ return
65
64
}
66
65
for resourceName , recommended := range recommendedRequest .Target {
67
66
totalRecommendedPerResource [resourceName ] += recommended .MilliValue ()
@@ -78,15 +77,19 @@ func (*defaultPriorityProcessor) GetUpdatePriority(pod *apiv1.Pod, vpa *vpa_type
78
77
outsideRecommendedRange = true
79
78
}
80
79
} 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.
85
80
scaleUp = true
86
81
outsideRecommendedRange = true
87
82
}
88
83
}
89
84
}
85
+
86
+ for _ , podContainer := range pod .Spec .Containers {
87
+ processContainer (podContainer )
88
+ }
89
+ for _ , initContainer := range pod .Spec .InitContainers {
90
+ processContainer (initContainer )
91
+ }
92
+
90
93
resourceDiff := 0.0
91
94
for resource , totalRecommended := range totalRecommendedPerResource {
92
95
totalRequest := math .Max (float64 (totalRequestPerResource [resource ]), 1.0 )
0 commit comments