Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vpa-release-1.1] Fix nil pointer panic in eviction admission #6833

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading