Skip to content

Commit

Permalink
Address review feedback from plkokanov
Browse files Browse the repository at this point in the history
  • Loading branch information
ialidzhikov committed Feb 11, 2025
1 parent 055affa commit bab77cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion vertical-pod-autoscaler/pkg/utils/vpa/capping.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ func applyVPAPolicyForContainer(containerName string,

var maxAllowed apiv1.ResourceList
if containerPolicy != nil {
maxAllowed = containerPolicy.MaxAllowed
// Deep copy containerPolicy.MaxAllowed as maxAllowed can later on be merged with globalMaxAllowed.
// Deep copy is needed to prevent unwanted modifications to containerPolicy.MaxAllowed.
maxAllowed = containerPolicy.MaxAllowed.DeepCopy()
}
if maxAllowed == nil {
maxAllowed = globalMaxAllowed
Expand Down
5 changes: 5 additions & 0 deletions vertical-pod-autoscaler/pkg/utils/vpa/capping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,14 @@ func TestApplyVPAPolicy(t *testing.T) {

for _, tt := range tests {
t.Run(tt.Name, func(t *testing.T) {
resourcePolicyCopy := tt.ResourcePolicy.DeepCopy()

actual, err := ApplyVPAPolicy(tt.PodRecommendation, tt.ResourcePolicy, tt.GlobalMaxAllowed)
assert.Nil(t, err)
assert.Equal(t, tt.Expected, actual)

// Make sure that the func does not have a side affect and does not modify the passed resource policy.
assert.Equal(t, resourcePolicyCopy, tt.ResourcePolicy)
})
}
}
Expand Down

0 comments on commit bab77cd

Please sign in to comment.