@@ -33,6 +33,8 @@ import (
3333 "k8s.io/client-go/kubernetes/fake"
3434 "k8s.io/client-go/tools/cache"
3535
36+ "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/admission-controller/resource/pod/patch"
37+
3638 vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"
3739 "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/test"
3840)
@@ -47,6 +49,10 @@ func getBasicVpa() *vpa_types.VerticalPodAutoscaler {
4749 return test .VerticalPodAutoscaler ().WithContainer ("any" ).Get ()
4850}
4951
52+ func getNoopPatchCalculators () []patch.Calculator {
53+ return []patch.Calculator {}
54+ }
55+
5056func TestEvictReplicatedByController (t * testing.T ) {
5157 rc := apiv1.ReplicationController {
5258 ObjectMeta : metav1.ObjectMeta {
@@ -73,13 +79,15 @@ func TestEvictReplicatedByController(t *testing.T) {
7379 replicas int32
7480 evictionTolerance float64
7581 vpa * vpa_types.VerticalPodAutoscaler
82+ calculators []patch.Calculator
7683 pods []podWithExpectations
7784 }{
7885 {
7986 name : "Evict only first pod (half of 3)." ,
8087 replicas : 3 ,
8188 evictionTolerance : 0.5 ,
8289 vpa : getBasicVpa (),
90+ calculators : getNoopPatchCalculators (),
8391 pods : []podWithExpectations {
8492 {
8593 pod : generatePod ().Get (),
@@ -103,6 +111,7 @@ func TestEvictReplicatedByController(t *testing.T) {
103111 replicas : 4 ,
104112 evictionTolerance : 0.5 ,
105113 vpa : getBasicVpa (),
114+ calculators : getNoopPatchCalculators (),
106115 pods : []podWithExpectations {
107116 {
108117
@@ -132,6 +141,7 @@ func TestEvictReplicatedByController(t *testing.T) {
132141 replicas : 4 ,
133142 evictionTolerance : 0.5 ,
134143 vpa : getBasicVpa (),
144+ calculators : getNoopPatchCalculators (),
135145 pods : []podWithExpectations {
136146 {
137147 pod : generatePod ().Get (),
@@ -155,6 +165,7 @@ func TestEvictReplicatedByController(t *testing.T) {
155165 replicas : 3 ,
156166 evictionTolerance : 0.1 ,
157167 vpa : getBasicVpa (),
168+ calculators : getNoopPatchCalculators (),
158169 pods : []podWithExpectations {
159170 {
160171 pod : generatePod ().Get (),
@@ -178,6 +189,7 @@ func TestEvictReplicatedByController(t *testing.T) {
178189 replicas : 3 ,
179190 evictionTolerance : 0.1 ,
180191 vpa : getBasicVpa (),
192+ calculators : getNoopPatchCalculators (),
181193 pods : []podWithExpectations {
182194 {
183195 pod : generatePod ().Get (),
@@ -196,6 +208,7 @@ func TestEvictReplicatedByController(t *testing.T) {
196208 replicas : 3 ,
197209 evictionTolerance : 0.5 ,
198210 vpa : getBasicVpa (),
211+ calculators : getNoopPatchCalculators (),
199212 pods : []podWithExpectations {
200213 {
201214 pod : generatePod ().Get (),
@@ -219,6 +232,7 @@ func TestEvictReplicatedByController(t *testing.T) {
219232 replicas : 4 ,
220233 evictionTolerance : 0.5 ,
221234 vpa : getBasicVpa (),
235+ calculators : getNoopPatchCalculators (),
222236 pods : []podWithExpectations {
223237 {
224238 pod : generatePod ().Get (),
@@ -247,6 +261,7 @@ func TestEvictReplicatedByController(t *testing.T) {
247261 replicas : 1 ,
248262 evictionTolerance : 0.5 ,
249263 vpa : getBasicVpa (),
264+ calculators : getNoopPatchCalculators (),
250265 pods : []podWithExpectations {
251266 {
252267 pod : generatePod ().Get (),
@@ -260,6 +275,7 @@ func TestEvictReplicatedByController(t *testing.T) {
260275 replicas : 1 ,
261276 evictionTolerance : 0.5 ,
262277 vpa : vpaSingleReplica ,
278+ calculators : getNoopPatchCalculators (),
263279 pods : []podWithExpectations {
264280 {
265281 pod : generatePod ().Get (),
@@ -279,7 +295,7 @@ func TestEvictReplicatedByController(t *testing.T) {
279295 pods = append (pods , p .pod )
280296 }
281297 factory , _ := getEvictionRestrictionFactory (& rc , nil , nil , nil , 2 , testCase .evictionTolerance )
282- eviction := factory .NewPodsEvictionRestriction (pods , testCase .vpa )
298+ eviction := factory .NewPodsEvictionRestriction (pods , testCase .vpa , testCase . calculators )
283299 for i , p := range testCase .pods {
284300 assert .Equalf (t , p .canEvict , eviction .CanEvict (p .pod ), "TC %v - unexpected CanEvict result for pod-%v %#v" , testCase .name , i , p .pod )
285301 }
@@ -318,7 +334,7 @@ func TestEvictReplicatedByReplicaSet(t *testing.T) {
318334
319335 basicVpa := getBasicVpa ()
320336 factory , _ := getEvictionRestrictionFactory (nil , & rs , nil , nil , 2 , 0.5 )
321- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
337+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
322338
323339 for _ , pod := range pods {
324340 assert .True (t , eviction .CanEvict (pod ))
@@ -358,7 +374,7 @@ func TestEvictReplicatedByStatefulSet(t *testing.T) {
358374
359375 basicVpa := getBasicVpa ()
360376 factory , _ := getEvictionRestrictionFactory (nil , nil , & ss , nil , 2 , 0.5 )
361- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
377+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
362378
363379 for _ , pod := range pods {
364380 assert .True (t , eviction .CanEvict (pod ))
@@ -397,7 +413,7 @@ func TestEvictReplicatedByDaemonSet(t *testing.T) {
397413
398414 basicVpa := getBasicVpa ()
399415 factory , _ := getEvictionRestrictionFactory (nil , nil , nil , & ds , 2 , 0.5 )
400- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
416+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
401417
402418 for _ , pod := range pods {
403419 assert .True (t , eviction .CanEvict (pod ))
@@ -433,7 +449,7 @@ func TestEvictReplicatedByJob(t *testing.T) {
433449
434450 basicVpa := getBasicVpa ()
435451 factory , _ := getEvictionRestrictionFactory (nil , nil , nil , nil , 2 , 0.5 )
436- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
452+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
437453
438454 for _ , pod := range pods {
439455 assert .True (t , eviction .CanEvict (pod ))
@@ -473,7 +489,7 @@ func TestEvictTooFewReplicas(t *testing.T) {
473489
474490 basicVpa := getBasicVpa ()
475491 factory , _ := getEvictionRestrictionFactory (& rc , nil , nil , nil , 10 , 0.5 )
476- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
492+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
477493
478494 for _ , pod := range pods {
479495 assert .False (t , eviction .CanEvict (pod ))
@@ -510,7 +526,7 @@ func TestEvictionTolerance(t *testing.T) {
510526
511527 basicVpa := getBasicVpa ()
512528 factory , _ := getEvictionRestrictionFactory (& rc , nil , nil , nil , 2 /*minReplicas*/ , tolerance )
513- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
529+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
514530
515531 for _ , pod := range pods {
516532 assert .True (t , eviction .CanEvict (pod ))
@@ -551,7 +567,7 @@ func TestEvictAtLeastOne(t *testing.T) {
551567
552568 basicVpa := getBasicVpa ()
553569 factory , _ := getEvictionRestrictionFactory (& rc , nil , nil , nil , 2 , tolerance )
554- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
570+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
555571
556572 for _ , pod := range pods {
557573 assert .True (t , eviction .CanEvict (pod ))
@@ -591,6 +607,7 @@ func TestEvictEmitEvent(t *testing.T) {
591607 replicas int32
592608 evictionTolerance float64
593609 vpa * vpa_types.VerticalPodAutoscaler
610+ calculators []patch.Calculator
594611 pods []podWithExpectations
595612 errorExpected bool
596613 }{
@@ -599,6 +616,7 @@ func TestEvictEmitEvent(t *testing.T) {
599616 replicas : 4 ,
600617 evictionTolerance : 0.5 ,
601618 vpa : basicVpa ,
619+ calculators : getNoopPatchCalculators (),
602620 pods : []podWithExpectations {
603621 {
604622 pod : generatePod ().WithPhase (apiv1 .PodPending ).Get (),
@@ -618,6 +636,7 @@ func TestEvictEmitEvent(t *testing.T) {
618636 replicas : 4 ,
619637 evictionTolerance : 0.5 ,
620638 vpa : basicVpa ,
639+ calculators : getNoopPatchCalculators (),
621640 pods : []podWithExpectations {
622641
623642 {
@@ -639,7 +658,7 @@ func TestEvictEmitEvent(t *testing.T) {
639658 pods = append (pods , p .pod )
640659 }
641660 factory , _ := getEvictionRestrictionFactory (& rc , nil , nil , nil , 2 , testCase .evictionTolerance )
642- eviction := factory .NewPodsEvictionRestriction (pods , testCase .vpa )
661+ eviction := factory .NewPodsEvictionRestriction (pods , testCase .vpa , testCase . calculators )
643662
644663 for _ , p := range testCase .pods {
645664 mockRecorder := test .MockEventRecorder ()
0 commit comments