-
Notifications
You must be signed in to change notification settings - Fork 127
/
sync_cluster_context.go
105 lines (80 loc) · 2.97 KB
/
sync_cluster_context.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package fake
import (
"errors"
"fmt"
v1 "k8s.io/api/core/v1"
networking "k8s.io/api/networking/v1beta1"
"k8s.io/client-go/tools/cache"
"k8s.io/kubelet/pkg/apis/stats/v1alpha1"
"github.com/G-Research/armada/internal/executor/domain"
)
type SyncFakeClusterContext struct {
Pods map[string]*v1.Pod
}
func NewSyncFakeClusterContext() *SyncFakeClusterContext {
c := &SyncFakeClusterContext{Pods: map[string]*v1.Pod{}}
return c
}
func (*SyncFakeClusterContext) Stop() {}
func (c *SyncFakeClusterContext) AddPodEventHandler(handler cache.ResourceEventHandlerFuncs) {}
func (c *SyncFakeClusterContext) GetBatchPods() ([]*v1.Pod, error) {
pods := make([]*v1.Pod, 0, len(c.Pods))
for _, p := range c.Pods {
pods = append(pods, p.DeepCopy())
}
return pods, nil
}
func (c *SyncFakeClusterContext) GetAllPods() ([]*v1.Pod, error) {
return c.GetBatchPods()
}
func (c *SyncFakeClusterContext) GetActiveBatchPods() ([]*v1.Pod, error) {
return c.GetBatchPods()
}
func (c *SyncFakeClusterContext) GetNodes() ([]*v1.Node, error) {
return make([]*v1.Node, 0), nil
}
func (c *SyncFakeClusterContext) GetNode(nodeName string) (*v1.Node, error) {
return nil, errors.New("GetNode Not implemented")
}
func (c *SyncFakeClusterContext) GetPodEvents(pod *v1.Pod) ([]*v1.Event, error) {
return []*v1.Event{}, nil
}
func (c *SyncFakeClusterContext) SubmitService(service *v1.Service) (*v1.Service, error) {
return nil, fmt.Errorf("Services not implemented in SyncFakeClusterContext")
}
func (c *SyncFakeClusterContext) GetServices(pod *v1.Pod) ([]*v1.Service, error) {
return nil, fmt.Errorf("Services not implemented in SyncFakeClusterContext")
}
func (c *SyncFakeClusterContext) DeleteService(service *v1.Service) error {
return fmt.Errorf("Services not implemented in SyncFakeClusterContext")
}
func (c *SyncFakeClusterContext) SubmitIngress(ingress *networking.Ingress) (*networking.Ingress, error) {
return nil, fmt.Errorf("Ingresses not implemented in SyncFakeClusterContext")
}
func (c *SyncFakeClusterContext) GetIngresses(pod *v1.Pod) ([]*networking.Ingress, error) {
return nil, fmt.Errorf("Ingresses not implemented in SyncFakeClusterContext")
}
func (c *SyncFakeClusterContext) DeleteIngress(ingress *networking.Ingress) error {
return fmt.Errorf("Ingresses not implemented in SyncFakeClusterContext")
}
func (c *SyncFakeClusterContext) SubmitPod(pod *v1.Pod, owner string, ownerGroups []string) (*v1.Pod, error) {
c.Pods[pod.Labels[domain.JobId]] = pod
return pod, nil
}
func (c *SyncFakeClusterContext) AddAnnotation(pod *v1.Pod, annotations map[string]string) error {
return nil
}
func (c *SyncFakeClusterContext) DeletePods(pods []*v1.Pod) {
for _, p := range pods {
delete(c.Pods, p.Labels[domain.JobId])
}
}
func (c *SyncFakeClusterContext) GetClusterId() string {
return "cluster-id-1"
}
func (c *SyncFakeClusterContext) GetClusterPool() string {
return "pool"
}
func (c *SyncFakeClusterContext) GetNodeStatsSummary(node *v1.Node) (*v1alpha1.Summary, error) {
return &v1alpha1.Summary{}, nil
}