Skip to content

Commit bab77cd

Browse files
committed
Address review feedback from plkokanov
1 parent 055affa commit bab77cd

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

vertical-pod-autoscaler/pkg/utils/vpa/capping.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ func applyVPAPolicyForContainer(containerName string,
200200

201201
var maxAllowed apiv1.ResourceList
202202
if containerPolicy != nil {
203-
maxAllowed = containerPolicy.MaxAllowed
203+
// Deep copy containerPolicy.MaxAllowed as maxAllowed can later on be merged with globalMaxAllowed.
204+
// Deep copy is needed to prevent unwanted modifications to containerPolicy.MaxAllowed.
205+
maxAllowed = containerPolicy.MaxAllowed.DeepCopy()
204206
}
205207
if maxAllowed == nil {
206208
maxAllowed = globalMaxAllowed

vertical-pod-autoscaler/pkg/utils/vpa/capping_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,14 @@ func TestApplyVPAPolicy(t *testing.T) {
569569

570570
for _, tt := range tests {
571571
t.Run(tt.Name, func(t *testing.T) {
572+
resourcePolicyCopy := tt.ResourcePolicy.DeepCopy()
573+
572574
actual, err := ApplyVPAPolicy(tt.PodRecommendation, tt.ResourcePolicy, tt.GlobalMaxAllowed)
573575
assert.Nil(t, err)
574576
assert.Equal(t, tt.Expected, actual)
577+
578+
// Make sure that the func does not have a side affect and does not modify the passed resource policy.
579+
assert.Equal(t, resourcePolicyCopy, tt.ResourcePolicy)
575580
})
576581
}
577582
}

0 commit comments

Comments
 (0)