@@ -28,6 +28,7 @@ import (
2828 batchv1 "k8s.io/api/batch/v1"
2929 apiv1 "k8s.io/api/core/v1"
3030 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31+ "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/admission-controller/resource/pod/patch"
3132 vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"
3233 "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/test"
3334 appsinformer "k8s.io/client-go/informers/apps/v1"
@@ -46,6 +47,10 @@ func getBasicVpa() *vpa_types.VerticalPodAutoscaler {
4647 return test .VerticalPodAutoscaler ().WithContainer ("any" ).Get ()
4748}
4849
50+ func getNoopPatchCalculators () []patch.Calculator {
51+ return []patch.Calculator {}
52+ }
53+
4954func TestEvictReplicatedByController (t * testing.T ) {
5055 rc := apiv1.ReplicationController {
5156 ObjectMeta : metav1.ObjectMeta {
@@ -72,13 +77,15 @@ func TestEvictReplicatedByController(t *testing.T) {
7277 replicas int32
7378 evictionTolerance float64
7479 vpa * vpa_types.VerticalPodAutoscaler
80+ calculators []patch.Calculator
7581 pods []podWithExpectations
7682 }{
7783 {
7884 name : "Evict only first pod (half of 3)." ,
7985 replicas : 3 ,
8086 evictionTolerance : 0.5 ,
8187 vpa : getBasicVpa (),
88+ calculators : getNoopPatchCalculators (),
8289 pods : []podWithExpectations {
8390 {
8491 pod : generatePod ().Get (),
@@ -102,6 +109,7 @@ func TestEvictReplicatedByController(t *testing.T) {
102109 replicas : 4 ,
103110 evictionTolerance : 0.5 ,
104111 vpa : getBasicVpa (),
112+ calculators : getNoopPatchCalculators (),
105113 pods : []podWithExpectations {
106114 {
107115
@@ -131,6 +139,7 @@ func TestEvictReplicatedByController(t *testing.T) {
131139 replicas : 4 ,
132140 evictionTolerance : 0.5 ,
133141 vpa : getBasicVpa (),
142+ calculators : getNoopPatchCalculators (),
134143 pods : []podWithExpectations {
135144 {
136145 pod : generatePod ().Get (),
@@ -154,6 +163,7 @@ func TestEvictReplicatedByController(t *testing.T) {
154163 replicas : 3 ,
155164 evictionTolerance : 0.1 ,
156165 vpa : getBasicVpa (),
166+ calculators : getNoopPatchCalculators (),
157167 pods : []podWithExpectations {
158168 {
159169 pod : generatePod ().Get (),
@@ -177,6 +187,7 @@ func TestEvictReplicatedByController(t *testing.T) {
177187 replicas : 3 ,
178188 evictionTolerance : 0.1 ,
179189 vpa : getBasicVpa (),
190+ calculators : getNoopPatchCalculators (),
180191 pods : []podWithExpectations {
181192 {
182193 pod : generatePod ().Get (),
@@ -195,6 +206,7 @@ func TestEvictReplicatedByController(t *testing.T) {
195206 replicas : 3 ,
196207 evictionTolerance : 0.5 ,
197208 vpa : getBasicVpa (),
209+ calculators : getNoopPatchCalculators (),
198210 pods : []podWithExpectations {
199211 {
200212 pod : generatePod ().Get (),
@@ -218,6 +230,7 @@ func TestEvictReplicatedByController(t *testing.T) {
218230 replicas : 4 ,
219231 evictionTolerance : 0.5 ,
220232 vpa : getBasicVpa (),
233+ calculators : getNoopPatchCalculators (),
221234 pods : []podWithExpectations {
222235 {
223236 pod : generatePod ().Get (),
@@ -246,6 +259,7 @@ func TestEvictReplicatedByController(t *testing.T) {
246259 replicas : 1 ,
247260 evictionTolerance : 0.5 ,
248261 vpa : getBasicVpa (),
262+ calculators : getNoopPatchCalculators (),
249263 pods : []podWithExpectations {
250264 {
251265 pod : generatePod ().Get (),
@@ -259,6 +273,7 @@ func TestEvictReplicatedByController(t *testing.T) {
259273 replicas : 1 ,
260274 evictionTolerance : 0.5 ,
261275 vpa : vpaSingleReplica ,
276+ calculators : getNoopPatchCalculators (),
262277 pods : []podWithExpectations {
263278 {
264279 pod : generatePod ().Get (),
@@ -278,7 +293,7 @@ func TestEvictReplicatedByController(t *testing.T) {
278293 pods = append (pods , p .pod )
279294 }
280295 factory , _ := getEvictionRestrictionFactory (& rc , nil , nil , nil , 2 , testCase .evictionTolerance )
281- eviction := factory .NewPodsEvictionRestriction (pods , testCase .vpa )
296+ eviction := factory .NewPodsEvictionRestriction (pods , testCase .vpa , testCase . calculators )
282297 for i , p := range testCase .pods {
283298 assert .Equalf (t , p .canEvict , eviction .CanEvict (p .pod ), "TC %v - unexpected CanEvict result for pod-%v %#v" , testCase .name , i , p .pod )
284299 }
@@ -317,7 +332,7 @@ func TestEvictReplicatedByReplicaSet(t *testing.T) {
317332
318333 basicVpa := getBasicVpa ()
319334 factory , _ := getEvictionRestrictionFactory (nil , & rs , nil , nil , 2 , 0.5 )
320- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
335+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
321336
322337 for _ , pod := range pods {
323338 assert .True (t , eviction .CanEvict (pod ))
@@ -357,7 +372,7 @@ func TestEvictReplicatedByStatefulSet(t *testing.T) {
357372
358373 basicVpa := getBasicVpa ()
359374 factory , _ := getEvictionRestrictionFactory (nil , nil , & ss , nil , 2 , 0.5 )
360- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
375+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
361376
362377 for _ , pod := range pods {
363378 assert .True (t , eviction .CanEvict (pod ))
@@ -396,7 +411,7 @@ func TestEvictReplicatedByDaemonSet(t *testing.T) {
396411
397412 basicVpa := getBasicVpa ()
398413 factory , _ := getEvictionRestrictionFactory (nil , nil , nil , & ds , 2 , 0.5 )
399- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
414+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
400415
401416 for _ , pod := range pods {
402417 assert .True (t , eviction .CanEvict (pod ))
@@ -432,7 +447,7 @@ func TestEvictReplicatedByJob(t *testing.T) {
432447
433448 basicVpa := getBasicVpa ()
434449 factory , _ := getEvictionRestrictionFactory (nil , nil , nil , nil , 2 , 0.5 )
435- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
450+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
436451
437452 for _ , pod := range pods {
438453 assert .True (t , eviction .CanEvict (pod ))
@@ -472,7 +487,7 @@ func TestEvictTooFewReplicas(t *testing.T) {
472487
473488 basicVpa := getBasicVpa ()
474489 factory , _ := getEvictionRestrictionFactory (& rc , nil , nil , nil , 10 , 0.5 )
475- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
490+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
476491
477492 for _ , pod := range pods {
478493 assert .False (t , eviction .CanEvict (pod ))
@@ -509,7 +524,7 @@ func TestEvictionTolerance(t *testing.T) {
509524
510525 basicVpa := getBasicVpa ()
511526 factory , _ := getEvictionRestrictionFactory (& rc , nil , nil , nil , 2 /*minReplicas*/ , tolerance )
512- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
527+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
513528
514529 for _ , pod := range pods {
515530 assert .True (t , eviction .CanEvict (pod ))
@@ -550,7 +565,7 @@ func TestEvictAtLeastOne(t *testing.T) {
550565
551566 basicVpa := getBasicVpa ()
552567 factory , _ := getEvictionRestrictionFactory (& rc , nil , nil , nil , 2 , tolerance )
553- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
568+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
554569
555570 for _ , pod := range pods {
556571 assert .True (t , eviction .CanEvict (pod ))
@@ -590,6 +605,7 @@ func TestEvictEmitEvent(t *testing.T) {
590605 replicas int32
591606 evictionTolerance float64
592607 vpa * vpa_types.VerticalPodAutoscaler
608+ calculators []patch.Calculator
593609 pods []podWithExpectations
594610 errorExpected bool
595611 }{
@@ -598,6 +614,7 @@ func TestEvictEmitEvent(t *testing.T) {
598614 replicas : 4 ,
599615 evictionTolerance : 0.5 ,
600616 vpa : basicVpa ,
617+ calculators : getNoopPatchCalculators (),
601618 pods : []podWithExpectations {
602619 {
603620 pod : generatePod ().WithPhase (apiv1 .PodPending ).Get (),
@@ -617,6 +634,7 @@ func TestEvictEmitEvent(t *testing.T) {
617634 replicas : 4 ,
618635 evictionTolerance : 0.5 ,
619636 vpa : basicVpa ,
637+ calculators : getNoopPatchCalculators (),
620638 pods : []podWithExpectations {
621639
622640 {
@@ -638,7 +656,7 @@ func TestEvictEmitEvent(t *testing.T) {
638656 pods = append (pods , p .pod )
639657 }
640658 factory , _ := getEvictionRestrictionFactory (& rc , nil , nil , nil , 2 , testCase .evictionTolerance )
641- eviction := factory .NewPodsEvictionRestriction (pods , testCase .vpa )
659+ eviction := factory .NewPodsEvictionRestriction (pods , testCase .vpa , testCase . calculators )
642660
643661 for _ , p := range testCase .pods {
644662 mockRecorder := test .MockEventRecorder ()
0 commit comments