Skip to content

Commit

Permalink
Merge pull request #6833 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…6820-to-vpa-release-1.1

[vpa-release-1.1] Fix nil pointer panic in eviction admission
  • Loading branch information
k8s-ci-robot authored May 15, 2024
2 parents b396895 + cd673e3 commit 0ec9707
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 0ec9707

Please sign in to comment.