Skip to content

Commit f0a34c0

Browse files
committed
Move PriorityProcessorFake out of test file
1 parent a28bc40 commit f0a34c0

File tree

2 files changed

+49
-26
lines changed

2 files changed

+49
-26
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package priority
18+
19+
import (
20+
"fmt"
21+
22+
corev1 "k8s.io/api/core/v1"
23+
vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"
24+
)
25+
26+
type fakePriorityProcessor struct {
27+
priorities map[string]PodPriority
28+
}
29+
30+
// NewFakeProcessor returns a fake processor for testing that can be initialized
31+
// with a map from pod name to priority expected to be returned.
32+
func NewFakeProcessor(priorities map[string]PodPriority) PriorityProcessor {
33+
return &fakePriorityProcessor{
34+
priorities: priorities,
35+
}
36+
}
37+
38+
func (f *fakePriorityProcessor) GetUpdatePriority(pod *corev1.Pod, vpa *vpa_types.VerticalPodAutoscaler,
39+
recommendation *vpa_types.RecommendedPodResources) PodPriority {
40+
prio, ok := f.priorities[pod.Name]
41+
if !ok {
42+
panic(fmt.Sprintf("Unexpected pod name: %v", pod.Name))
43+
}
44+
return PodPriority{
45+
ScaleUp: prio.ScaleUp,
46+
ResourceDiff: prio.ResourceDiff,
47+
OutsideRecommendedRange: prio.OutsideRecommendedRange,
48+
}
49+
}

vertical-pod-autoscaler/pkg/updater/priority/priority_processor_test.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package priority
1818

1919
import (
20-
"fmt"
2120
"testing"
2221

2322
corev1 "k8s.io/api/core/v1"
@@ -285,28 +284,3 @@ func TestGetUpdatePriority_VpaObservedContainers(t *testing.T) {
285284
})
286285
}
287286
}
288-
289-
type fakePriorityProcessor struct {
290-
priorities map[string]PodPriority
291-
}
292-
293-
// NewFakeProcessor returns a fake processor for testing that can be initialized
294-
// with a map from pod name to priority expected to be returned.
295-
func NewFakeProcessor(priorities map[string]PodPriority) PriorityProcessor {
296-
return &fakePriorityProcessor{
297-
priorities: priorities,
298-
}
299-
}
300-
301-
func (f *fakePriorityProcessor) GetUpdatePriority(pod *corev1.Pod, vpa *vpa_types.VerticalPodAutoscaler,
302-
recommendation *vpa_types.RecommendedPodResources) PodPriority {
303-
prio, ok := f.priorities[pod.Name]
304-
if !ok {
305-
panic(fmt.Sprintf("Unexpected pod name: %v", pod.Name))
306-
}
307-
return PodPriority{
308-
ScaleUp: prio.ScaleUp,
309-
ResourceDiff: prio.ResourceDiff,
310-
OutsideRecommendedRange: prio.OutsideRecommendedRange,
311-
}
312-
}

0 commit comments

Comments
 (0)