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 } } 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)