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

Bugfix: Check recommendation is non-nil before iterating #105

Merged
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
13 changes: 9 additions & 4 deletions vertical-pod-autoscaler/pkg/utils/vpa/allowed_resource_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,19 @@ func (p *allowedResourceFilter) Apply(podRecommendation *vpa_types.RecommendedPo
policy *vpa_types.PodResourcePolicy,
conditions []vpa_types.VerticalPodAutoscalerCondition,
pod *corev1.Pod) (*vpa_types.RecommendedPodResources, ContainerToAnnotationsMap, error) {
recommendation := podRecommendation

if podRecommendation == nil || policy == nil {
// If there is no recommendation or no policies have been defined then no recommendation can be computed.
return podRecommendation, nil, nil
}

accumulatedContainerToAnnotationsMap := ContainerToAnnotationsMap{}

for i, containerRecommendation := range recommendation.ContainerRecommendations {
recommendation.ContainerRecommendations[i] = filterAllowedContainerResources(containerRecommendation, p.allowedResources)
for i, containerRecommendation := range podRecommendation.ContainerRecommendations {
podRecommendation.ContainerRecommendations[i] = filterAllowedContainerResources(containerRecommendation, p.allowedResources)
}

return recommendation, accumulatedContainerToAnnotationsMap, nil
return podRecommendation, accumulatedContainerToAnnotationsMap, nil
}

func filterAllowedContainerResources(recommendation vpa_types.RecommendedContainerResources, allowedResources []corev1.ResourceName) vpa_types.RecommendedContainerResources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestAllowedResourceFilter(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
processor := NewAllowedResourceFilter(tc.allowedResources)
processedRecommendation, _, err := processor.Apply(&tc.recommendation, nil, nil, nil)
processedRecommendation, _, err := processor.Apply(&tc.recommendation, &vpa_types.PodResourcePolicy{}, nil, nil)
assert.NoError(t, err)
assert.Equal(t, tc.expectedRecommendation, *processedRecommendation)
})
Expand Down
Loading