Skip to content

Commit

Permalink
Ignore Containers without recommendations for EvictionRequirements
Browse files Browse the repository at this point in the history
  • Loading branch information
voelzmo committed Dec 20, 2024
1 parent 50c6590 commit fd02293
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type scalingDirectionPodEvictionAdmission struct {

// Admit admits a Pod for eviction in one of three cases
// * no EvictionRequirement exists for this Pod
// * no Recommendation exists for at least one Container in this Pod
// * no Resource requests are set for at least one Container in this Pod
// * all EvictionRequirements are evaluated to 'true' for at least one Container in this Pod
func (s *scalingDirectionPodEvictionAdmission) Admit(pod *apiv1.Pod, resources *vpa_types.RecommendedPodResources) bool {
Expand All @@ -45,8 +44,10 @@ func (s *scalingDirectionPodEvictionAdmission) Admit(pod *apiv1.Pod, resources *
}
for _, container := range pod.Spec.Containers {
recommendedResources := vpa_utils.GetRecommendationForContainer(container.Name, resources)
// if a container doesn't have a recommendation, the VPA has set `.containerPolicy.mode: off` for this container,
// so we can skip this container
if recommendedResources == nil {
return true
continue
}
if s.admitContainer(container, recommendedResources, podEvictionRequirements) {
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,4 +402,24 @@ func TestAdmitForMultipleContainer(t *testing.T) {

assert.Equal(tt, false, sdpea.Admit(pod, recommendation))
})

t.Run("it should not admit the Pod even if there is a container that doesn't have a Recommendation and the other one doesn't fulfill the EvictionRequirements", func(tt *testing.T) {
evictionRequirements := map[*corev1.Pod][]*v1.EvictionRequirement{
pod: {
{
Resources: []corev1.ResourceName{corev1.ResourceCPU},
ChangeRequirement: v1.TargetHigherThanRequests,
},
},
}
sdpea := NewScalingDirectionPodEvictionAdmission()
sdpea.(*scalingDirectionPodEvictionAdmission).EvictionRequirements = evictionRequirements
recommendation := &v1.RecommendedPodResources{
ContainerRecommendations: []v1.RecommendedContainerResources{
test.Recommendation().WithContainer(container2Name).WithTarget("300m", "10Gi").GetContainerResources(),
},
}

assert.Equal(tt, false, sdpea.Admit(pod, recommendation))
})
}

0 comments on commit fd02293

Please sign in to comment.