Skip to content

Commit e6356b6

Browse files
committed
VPA: move inplace and eviction logic into separate files
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. Signed-off-by: Max Cao <[email protected]>
1 parent 93a37e4 commit e6356b6

File tree

17 files changed

+1189
-888
lines changed

17 files changed

+1189
-888
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.Spec
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,21 @@ 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+
// Spec refers to the spec of the pod.
31+
Spec PatchResourceTarget = "Spec"
32+
// Status refers to the status subresource of the pod.
33+
Status PatchResourceTarget = "Status"
34+
// Resize refers to the resize subresource of the pod.
35+
Resize PatchResourceTarget = "Resize"
36+
)
37+
2638
// Calculator is capable of calculating required patches for pod.
2739
type Calculator interface {
2840
CalculatePatches(pod *core.Pod, vpa *vpa_types.VerticalPodAutoscaler) ([]resource.PatchRecord, error)
41+
// PatchResourceTarget returns the resource this calculator should calculate patches for.
42+
PatchResourceTarget() PatchResourceTarget
2943
}

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 Spec
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
@@ -73,6 +73,10 @@ func (c *resourcesUpdatesPatchCalculator) CalculatePatches(pod *core.Pod, vpa *v
7373
return result, nil
7474
}
7575

76+
func (*resourcesUpdatesPatchCalculator) PatchResourceTarget() PatchResourceTarget {
77+
return Spec
78+
}
79+
7680
func getContainerPatch(pod *core.Pod, i int, annotationsPerContainer vpa_api_util.ContainerToAnnotationsMap, containerResources vpa_api_util.ContainerResources) ([]resource_admission.PatchRecord, string) {
7781
var patches []resource_admission.PatchRecord
7882
// Add empty resources object if missing.

0 commit comments

Comments
 (0)