@@ -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 appsinformer "k8s.io/client-go/informers/apps/v1"
3233 coreinformer "k8s.io/client-go/informers/core/v1"
3334 "k8s.io/client-go/kubernetes/fake"
@@ -47,6 +48,10 @@ func getBasicVpa() *vpa_types.VerticalPodAutoscaler {
4748 return test .VerticalPodAutoscaler ().WithContainer ("any" ).Get ()
4849}
4950
51+ func getNoopPatchCalculators () []patch.Calculator {
52+ return []patch.Calculator {}
53+ }
54+
5055func TestEvictReplicatedByController (t * testing.T ) {
5156 rc := apiv1.ReplicationController {
5257 ObjectMeta : metav1.ObjectMeta {
@@ -73,13 +78,15 @@ func TestEvictReplicatedByController(t *testing.T) {
7378 replicas int32
7479 evictionTolerance float64
7580 vpa * vpa_types.VerticalPodAutoscaler
81+ calculators []patch.Calculator
7682 pods []podWithExpectations
7783 }{
7884 {
7985 name : "Evict only first pod (half of 3)." ,
8086 replicas : 3 ,
8187 evictionTolerance : 0.5 ,
8288 vpa : getBasicVpa (),
89+ calculators : getNoopPatchCalculators (),
8390 pods : []podWithExpectations {
8491 {
8592 pod : generatePod ().Get (),
@@ -103,6 +110,7 @@ func TestEvictReplicatedByController(t *testing.T) {
103110 replicas : 4 ,
104111 evictionTolerance : 0.5 ,
105112 vpa : getBasicVpa (),
113+ calculators : getNoopPatchCalculators (),
106114 pods : []podWithExpectations {
107115 {
108116
@@ -132,6 +140,7 @@ func TestEvictReplicatedByController(t *testing.T) {
132140 replicas : 4 ,
133141 evictionTolerance : 0.5 ,
134142 vpa : getBasicVpa (),
143+ calculators : getNoopPatchCalculators (),
135144 pods : []podWithExpectations {
136145 {
137146 pod : generatePod ().Get (),
@@ -155,6 +164,7 @@ func TestEvictReplicatedByController(t *testing.T) {
155164 replicas : 3 ,
156165 evictionTolerance : 0.1 ,
157166 vpa : getBasicVpa (),
167+ calculators : getNoopPatchCalculators (),
158168 pods : []podWithExpectations {
159169 {
160170 pod : generatePod ().Get (),
@@ -178,6 +188,7 @@ func TestEvictReplicatedByController(t *testing.T) {
178188 replicas : 3 ,
179189 evictionTolerance : 0.1 ,
180190 vpa : getBasicVpa (),
191+ calculators : getNoopPatchCalculators (),
181192 pods : []podWithExpectations {
182193 {
183194 pod : generatePod ().Get (),
@@ -196,6 +207,7 @@ func TestEvictReplicatedByController(t *testing.T) {
196207 replicas : 3 ,
197208 evictionTolerance : 0.5 ,
198209 vpa : getBasicVpa (),
210+ calculators : getNoopPatchCalculators (),
199211 pods : []podWithExpectations {
200212 {
201213 pod : generatePod ().Get (),
@@ -219,6 +231,7 @@ func TestEvictReplicatedByController(t *testing.T) {
219231 replicas : 4 ,
220232 evictionTolerance : 0.5 ,
221233 vpa : getBasicVpa (),
234+ calculators : getNoopPatchCalculators (),
222235 pods : []podWithExpectations {
223236 {
224237 pod : generatePod ().Get (),
@@ -247,6 +260,7 @@ func TestEvictReplicatedByController(t *testing.T) {
247260 replicas : 1 ,
248261 evictionTolerance : 0.5 ,
249262 vpa : getBasicVpa (),
263+ calculators : getNoopPatchCalculators (),
250264 pods : []podWithExpectations {
251265 {
252266 pod : generatePod ().Get (),
@@ -260,6 +274,7 @@ func TestEvictReplicatedByController(t *testing.T) {
260274 replicas : 1 ,
261275 evictionTolerance : 0.5 ,
262276 vpa : vpaSingleReplica ,
277+ calculators : getNoopPatchCalculators (),
263278 pods : []podWithExpectations {
264279 {
265280 pod : generatePod ().Get (),
@@ -279,7 +294,7 @@ func TestEvictReplicatedByController(t *testing.T) {
279294 pods = append (pods , p .pod )
280295 }
281296 factory , _ := getEvictionRestrictionFactory (& rc , nil , nil , nil , 2 , testCase .evictionTolerance )
282- eviction := factory .NewPodsEvictionRestriction (pods , testCase .vpa )
297+ eviction := factory .NewPodsEvictionRestriction (pods , testCase .vpa , testCase . calculators )
283298 for i , p := range testCase .pods {
284299 assert .Equalf (t , p .canEvict , eviction .CanEvict (p .pod ), "TC %v - unexpected CanEvict result for pod-%v %#v" , testCase .name , i , p .pod )
285300 }
@@ -318,7 +333,7 @@ func TestEvictReplicatedByReplicaSet(t *testing.T) {
318333
319334 basicVpa := getBasicVpa ()
320335 factory , _ := getEvictionRestrictionFactory (nil , & rs , nil , nil , 2 , 0.5 )
321- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
336+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
322337
323338 for _ , pod := range pods {
324339 assert .True (t , eviction .CanEvict (pod ))
@@ -358,7 +373,7 @@ func TestEvictReplicatedByStatefulSet(t *testing.T) {
358373
359374 basicVpa := getBasicVpa ()
360375 factory , _ := getEvictionRestrictionFactory (nil , nil , & ss , nil , 2 , 0.5 )
361- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
376+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
362377
363378 for _ , pod := range pods {
364379 assert .True (t , eviction .CanEvict (pod ))
@@ -397,7 +412,7 @@ func TestEvictReplicatedByDaemonSet(t *testing.T) {
397412
398413 basicVpa := getBasicVpa ()
399414 factory , _ := getEvictionRestrictionFactory (nil , nil , nil , & ds , 2 , 0.5 )
400- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
415+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
401416
402417 for _ , pod := range pods {
403418 assert .True (t , eviction .CanEvict (pod ))
@@ -433,7 +448,7 @@ func TestEvictReplicatedByJob(t *testing.T) {
433448
434449 basicVpa := getBasicVpa ()
435450 factory , _ := getEvictionRestrictionFactory (nil , nil , nil , nil , 2 , 0.5 )
436- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
451+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
437452
438453 for _ , pod := range pods {
439454 assert .True (t , eviction .CanEvict (pod ))
@@ -473,7 +488,7 @@ func TestEvictTooFewReplicas(t *testing.T) {
473488
474489 basicVpa := getBasicVpa ()
475490 factory , _ := getEvictionRestrictionFactory (& rc , nil , nil , nil , 10 , 0.5 )
476- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
491+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
477492
478493 for _ , pod := range pods {
479494 assert .False (t , eviction .CanEvict (pod ))
@@ -510,7 +525,7 @@ func TestEvictionTolerance(t *testing.T) {
510525
511526 basicVpa := getBasicVpa ()
512527 factory , _ := getEvictionRestrictionFactory (& rc , nil , nil , nil , 2 /*minReplicas*/ , tolerance )
513- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
528+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
514529
515530 for _ , pod := range pods {
516531 assert .True (t , eviction .CanEvict (pod ))
@@ -551,7 +566,7 @@ func TestEvictAtLeastOne(t *testing.T) {
551566
552567 basicVpa := getBasicVpa ()
553568 factory , _ := getEvictionRestrictionFactory (& rc , nil , nil , nil , 2 , tolerance )
554- eviction := factory .NewPodsEvictionRestriction (pods , basicVpa )
569+ eviction := factory .NewPodsEvictionRestriction (pods , basicVpa , getNoopPatchCalculators () )
555570
556571 for _ , pod := range pods {
557572 assert .True (t , eviction .CanEvict (pod ))
@@ -591,6 +606,7 @@ func TestEvictEmitEvent(t *testing.T) {
591606 replicas int32
592607 evictionTolerance float64
593608 vpa * vpa_types.VerticalPodAutoscaler
609+ calculators []patch.Calculator
594610 pods []podWithExpectations
595611 errorExpected bool
596612 }{
@@ -599,6 +615,7 @@ func TestEvictEmitEvent(t *testing.T) {
599615 replicas : 4 ,
600616 evictionTolerance : 0.5 ,
601617 vpa : basicVpa ,
618+ calculators : getNoopPatchCalculators (),
602619 pods : []podWithExpectations {
603620 {
604621 pod : generatePod ().WithPhase (apiv1 .PodPending ).Get (),
@@ -618,6 +635,7 @@ func TestEvictEmitEvent(t *testing.T) {
618635 replicas : 4 ,
619636 evictionTolerance : 0.5 ,
620637 vpa : basicVpa ,
638+ calculators : getNoopPatchCalculators (),
621639 pods : []podWithExpectations {
622640
623641 {
@@ -639,7 +657,7 @@ func TestEvictEmitEvent(t *testing.T) {
639657 pods = append (pods , p .pod )
640658 }
641659 factory , _ := getEvictionRestrictionFactory (& rc , nil , nil , nil , 2 , testCase .evictionTolerance )
642- eviction := factory .NewPodsEvictionRestriction (pods , testCase .vpa )
660+ eviction := factory .NewPodsEvictionRestriction (pods , testCase .vpa , testCase . calculators )
643661
644662 for _ , p := range testCase .pods {
645663 mockRecorder := test .MockEventRecorder ()
0 commit comments