-
Notifications
You must be signed in to change notification settings - Fork 228
/
horizontalpodautoscaler.go
88 lines (80 loc) · 3.47 KB
/
horizontalpodautoscaler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package mocks
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
"golang.stackrox.io/kube-linter/pkg/objectkinds"
autoscalingV1 "k8s.io/api/autoscaling/v1"
autoscalingV2 "k8s.io/api/autoscaling/v2"
autoscalingV2Beta1 "k8s.io/api/autoscaling/v2beta1"
autoscalingV2Beta2 "k8s.io/api/autoscaling/v2beta2"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// AddMockHorizontalPodAutoscaler adds a mock HorizontalPodAutoscaler to LintContext
func (l *MockLintContext) AddMockHorizontalPodAutoscaler(t *testing.T, name, version string) {
require.NotEmpty(t, name)
switch version {
case "v2beta1":
l.objects[name] = &autoscalingV2Beta1.HorizontalPodAutoscaler{
TypeMeta: metaV1.TypeMeta{
Kind: objectkinds.HorizontalPodAutoscaler,
APIVersion: objectkinds.GetHorizontalPodAutoscalerAPIVersion(version),
},
ObjectMeta: metaV1.ObjectMeta{Name: name},
Spec: autoscalingV2Beta1.HorizontalPodAutoscalerSpec{},
}
case "v2beta2":
l.objects[name] = &autoscalingV2Beta2.HorizontalPodAutoscaler{
TypeMeta: metaV1.TypeMeta{
Kind: objectkinds.HorizontalPodAutoscaler,
APIVersion: objectkinds.GetHorizontalPodAutoscalerAPIVersion(version),
},
ObjectMeta: metaV1.ObjectMeta{Name: name},
Spec: autoscalingV2Beta2.HorizontalPodAutoscalerSpec{},
}
case "v2":
l.objects[name] = &autoscalingV2.HorizontalPodAutoscaler{
TypeMeta: metaV1.TypeMeta{
Kind: objectkinds.HorizontalPodAutoscaler,
APIVersion: objectkinds.GetHorizontalPodAutoscalerAPIVersion(version),
},
ObjectMeta: metaV1.ObjectMeta{Name: name},
Spec: autoscalingV2.HorizontalPodAutoscalerSpec{},
}
case "v1":
l.objects[name] = &autoscalingV1.HorizontalPodAutoscaler{
TypeMeta: metaV1.TypeMeta{
Kind: objectkinds.HorizontalPodAutoscaler,
APIVersion: objectkinds.GetHorizontalPodAutoscalerAPIVersion(version),
},
ObjectMeta: metaV1.ObjectMeta{Name: name},
Spec: autoscalingV1.HorizontalPodAutoscalerSpec{},
}
default:
require.FailNow(t, fmt.Sprintf("Unknown autoscaling version %s", version))
}
}
// ModifyHorizontalPodAutoscalerV2Beta1 modifies a given HorizontalPodAutoscaler in the context via the passed function.
func (l *MockLintContext) ModifyHorizontalPodAutoscalerV2Beta1(t *testing.T, name string, f func(hpa *autoscalingV2Beta1.HorizontalPodAutoscaler)) {
r, ok := l.objects[name].(*autoscalingV2Beta1.HorizontalPodAutoscaler)
require.True(t, ok)
f(r)
}
// ModifyHorizontalPodAutoscalerV2Beta2 modifies a given HorizontalPodAutoscaler in the context via the passed function.
func (l *MockLintContext) ModifyHorizontalPodAutoscalerV2Beta2(t *testing.T, name string, f func(hpa *autoscalingV2Beta2.HorizontalPodAutoscaler)) {
r, ok := l.objects[name].(*autoscalingV2Beta2.HorizontalPodAutoscaler)
require.True(t, ok)
f(r)
}
// ModifyHorizontalPodAutoscalerV2 modifies a given HorizontalPodAutoscaler in the context via the passed function.
func (l *MockLintContext) ModifyHorizontalPodAutoscalerV2(t *testing.T, name string, f func(hpa *autoscalingV2.HorizontalPodAutoscaler)) {
r, ok := l.objects[name].(*autoscalingV2.HorizontalPodAutoscaler)
require.True(t, ok)
f(r)
}
// ModifyHorizontalPodAutoscalerV1 modifies a given HorizontalPodAutoscaler in the context via the passed function.
func (l *MockLintContext) ModifyHorizontalPodAutoscalerV1(t *testing.T, name string, f func(hpa *autoscalingV1.HorizontalPodAutoscaler)) {
r, ok := l.objects[name].(*autoscalingV1.HorizontalPodAutoscaler)
require.True(t, ok)
f(r)
}