|
| 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 | +} |
0 commit comments