From 991308df3ba618e447c3e8db3b4280eecc1a88e3 Mon Sep 17 00:00:00 2001 From: itonyli Date: Mon, 13 May 2024 16:37:07 +0800 Subject: [PATCH 1/2] Fix 6808 --- .../priority/scaling_direction_pod_eviction_admission.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vertical-pod-autoscaler/pkg/updater/priority/scaling_direction_pod_eviction_admission.go b/vertical-pod-autoscaler/pkg/updater/priority/scaling_direction_pod_eviction_admission.go index 878e1ca9acbe..af3b4b6e0a9f 100644 --- a/vertical-pod-autoscaler/pkg/updater/priority/scaling_direction_pod_eviction_admission.go +++ b/vertical-pod-autoscaler/pkg/updater/priority/scaling_direction_pod_eviction_admission.go @@ -108,6 +108,10 @@ func (s *scalingDirectionPodEvictionAdmission) LoopInit(_ []*apiv1.Pod, vpaContr s.EvictionRequirements = make(map[*apiv1.Pod][]*vpa_types.EvictionRequirement) for vpa, pods := range vpaControlledPods { for _, pod := range pods { + // When UpdatePolicy is not specified, the default policy will be followed, and the EvictionRequirements field will be nil + if vpa.Spec.UpdatePolicy == nil { + continue + } s.EvictionRequirements[pod] = vpa.Spec.UpdatePolicy.EvictionRequirements } } From cd673e3253ed12d5bbbda057108695e773d8334f Mon Sep 17 00:00:00 2001 From: itonyli Date: Tue, 14 May 2024 14:16:27 +0800 Subject: [PATCH 2/2] add unit test for issue 6808 --- ...aling_direction_pod_eviction_admission_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/vertical-pod-autoscaler/pkg/updater/priority/scaling_direction_pod_eviction_admission_test.go b/vertical-pod-autoscaler/pkg/updater/priority/scaling_direction_pod_eviction_admission_test.go index 1ee28f4e26d5..22780b658fa2 100644 --- a/vertical-pod-autoscaler/pkg/updater/priority/scaling_direction_pod_eviction_admission_test.go +++ b/vertical-pod-autoscaler/pkg/updater/priority/scaling_direction_pod_eviction_admission_test.go @@ -55,6 +55,21 @@ func TestLoopInit(t *testing.T) { Get() vpaToPodMap := map[*v1.VerticalPodAutoscaler][]*corev1.Pod{testVPA: {pod, pod2}} + t.Run("it should not require UpdateMode and EvictionRequirements.", func(t *testing.T) { + sdpea := NewScalingDirectionPodEvictionAdmission() + sdpea.LoopInit(nil, vpaToPodMap) + + newTestVPA := test.VerticalPodAutoscaler(). + WithName("test-vpa"). + WithContainer(container1Name). + Get() + + newVpaToPodMap := map[*v1.VerticalPodAutoscaler][]*corev1.Pod{newTestVPA: {pod, pod2}} + + sdpea.LoopInit(nil, newVpaToPodMap) + assert.Len(t, sdpea.(*scalingDirectionPodEvictionAdmission).EvictionRequirements, 0) + }) + t.Run("it should store EvictionRequirements from VPA in a map per Pod", func(t *testing.T) { sdpea := NewScalingDirectionPodEvictionAdmission() sdpea.LoopInit(nil, vpaToPodMap)