-
Notifications
You must be signed in to change notification settings - Fork 11
/
pod.go
79 lines (67 loc) · 1.63 KB
/
pod.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
package test
import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type FakePodOption func(*corev1.Pod)
func MakeFakePod(name, namespace string, cpu, memory string, opts ...FakePodOption) *corev1.Pod {
res := corev1.ResourceList{}
if cpu != "" {
res[corev1.ResourceCPU] = resource.MustParse(cpu)
}
if memory != "" {
res[corev1.ResourceMemory] = resource.MustParse(memory)
}
pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "container",
Image: "nginx",
Resources: corev1.ResourceRequirements{
Requests: res,
},
},
},
},
}
for _, opt := range opts {
opt(pod)
}
return pod
}
func WithPodAnnotations(annotations map[string]string) FakePodOption {
return func(pod *corev1.Pod) {
pod.ObjectMeta.Annotations = annotations
}
}
func WithPodLabels(labels map[string]string) FakePodOption {
return func(pod *corev1.Pod) {
pod.ObjectMeta.Labels = labels
}
}
func WithPodNodeName(nodeName string) FakePodOption {
return func(pod *corev1.Pod) {
pod.Spec.NodeName = nodeName
}
}
func WithPodTolerations(tolerations []corev1.Toleration) FakePodOption {
return func(pod *corev1.Pod) {
pod.Spec.Tolerations = tolerations
}
}
func WithPodAffinity(affinity *corev1.Affinity) FakePodOption {
return func(pod *corev1.Pod) {
pod.Spec.Affinity = affinity
}
}
func WithPodNodeSelector(nodeSelector map[string]string) FakePodOption {
return func(pod *corev1.Pod) {
pod.Spec.NodeSelector = nodeSelector
}
}