Skip to content

Commit ed9358c

Browse files
committed
VPA: refactor in-place and eviction logic
This commit refactors inplace logic outside of the pods eviction restriction and separates them into their own files. Also this commit adds PatchResourceTarget to calculators to allow them to explictly specify to the caller which resource/subresource they should be patched to. This commit also creates a utils subpackage in order to prevent dependency cycles in the unit tests, and adds various unit tests. Lastly, this commit adds a rateLimiter specifically for limiting inPlaceResize API calls. Signed-off-by: Max Cao <[email protected]>
1 parent afc3ec3 commit ed9358c

20 files changed

+1852
-1223
lines changed

vertical-pod-autoscaler/pkg/admission-controller/resource/pod/handler_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ type fakePatchCalculator struct {
5454
err error
5555
}
5656

57+
func (*fakePatchCalculator) PatchResourceTarget() patch.PatchResourceTarget {
58+
return patch.Pod
59+
}
60+
5761
func (c *fakePatchCalculator) CalculatePatches(_ *apiv1.Pod, _ *vpa_types.VerticalPodAutoscaler) (
5862
[]resource_admission.PatchRecord, error) {
5963
return c.patches, c.err

vertical-pod-autoscaler/pkg/admission-controller/resource/pod/patch/calculator.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,22 @@ import (
2323
vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"
2424
)
2525

26+
// PatchResourceTarget is the type of resource that can be patched.
27+
type PatchResourceTarget string
28+
29+
const (
30+
// Pod refers to the pod resource itself.
31+
Pod PatchResourceTarget = "Pod"
32+
// Resize refers to the resize subresource of the pod.
33+
Resize PatchResourceTarget = "Resize"
34+
35+
// Future subresources can be added here.
36+
// e.g. Status PatchResourceTarget = "Status"
37+
)
38+
2639
// Calculator is capable of calculating required patches for pod.
2740
type Calculator interface {
2841
CalculatePatches(pod *core.Pod, vpa *vpa_types.VerticalPodAutoscaler) ([]resource.PatchRecord, error)
42+
// PatchResourceTarget returns the resource this calculator should calculate patches for.
43+
PatchResourceTarget() PatchResourceTarget
2944
}

vertical-pod-autoscaler/pkg/admission-controller/resource/pod/patch/observed_containers.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ func (*observedContainers) CalculatePatches(pod *core.Pod, _ *vpa_types.Vertical
3131
return []resource_admission.PatchRecord{GetAddAnnotationPatch(annotations.VpaObservedContainersLabel, vpaObservedContainersValue)}, nil
3232
}
3333

34+
func (*observedContainers) PatchResourceTarget() PatchResourceTarget {
35+
return Pod
36+
}
37+
3438
// NewObservedContainersCalculator returns calculator for
3539
// observed containers patches.
3640
func NewObservedContainersCalculator() Calculator {

vertical-pod-autoscaler/pkg/admission-controller/resource/pod/patch/resource_updates.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ func NewResourceUpdatesCalculator(recommendationProvider recommendation.Provider
4646
}
4747
}
4848

49+
func (*resourcesUpdatesPatchCalculator) PatchResourceTarget() PatchResourceTarget {
50+
return Pod
51+
}
52+
4953
func (c *resourcesUpdatesPatchCalculator) CalculatePatches(pod *core.Pod, vpa *vpa_types.VerticalPodAutoscaler) ([]resource_admission.PatchRecord, error) {
5054
result := []resource_admission.PatchRecord{}
5155

0 commit comments

Comments
 (0)