Skip to content

Commit

Permalink
Merge pull request #6820 from itonyli/issues/6808
Browse files Browse the repository at this point in the history
Fix nil pointer panic in eviction admission
  • Loading branch information
k8s-ci-robot authored May 14, 2024
2 parents 77652cd + 495f895 commit 4ad9c05
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4ad9c05

Please sign in to comment.