/
dummy.go
106 lines (87 loc) · 3.05 KB
/
dummy.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
106
package store
import (
"github.com/kubernetes-sigs/aws-alb-ingress-controller/internal/ingress/annotations"
"github.com/kubernetes-sigs/aws-alb-ingress-controller/internal/ingress/controller/config"
"github.com/kubernetes-sigs/aws-alb-ingress-controller/internal/ingress/controller/dummy"
corev1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
)
type Dummy struct {
cfg *config.Configuration
GetIngressAnnotationsResponse *annotations.Ingress
GetServiceAnnotationsResponse *annotations.Service
GetServiceFunc func(string) (*corev1.Service, error)
ListNodesFunc func() []*corev1.Node
GetNodeInstanceIDFunc func(*corev1.Node) (string, error)
GetServiceEndpointsFunc func(string) (*corev1.Endpoints, error)
GetPodFunc func(string) (*corev1.Pod, error)
}
// GetConfigMap ...
func (d Dummy) GetConfigMap(key string) (*corev1.ConfigMap, error) {
return nil, nil
}
// GetService ...
func (d Dummy) GetService(key string) (*corev1.Service, error) {
return d.GetServiceFunc(key)
}
// GetServiceEndpoints ...
func (d Dummy) GetServiceEndpoints(key string) (*corev1.Endpoints, error) {
return d.GetServiceEndpointsFunc(key)
}
// GetServicePods ...
func (d Dummy) GetPod(key string) (*corev1.Pod, error) {
return d.GetPodFunc(key)
}
// GetServiceAnnotations ...
func (d Dummy) GetServiceAnnotations(key string, ingress *annotations.Ingress) (*annotations.Service, error) {
return d.GetServiceAnnotationsResponse, nil
}
// GetIngress ...
func (d Dummy) GetIngress(key string) (*extensions.Ingress, error) {
return nil, nil
}
// ListNodes ...
func (d Dummy) ListNodes() []*corev1.Node {
return d.ListNodesFunc()
}
// ListIngresses ...
func (d Dummy) ListIngresses() []*extensions.Ingress {
return nil
}
// GetIngressAnnotations ...
func (d Dummy) GetIngressAnnotations(key string) (*annotations.Ingress, error) {
return d.GetIngressAnnotationsResponse, nil
}
// Run ...
func (d Dummy) Run(stopCh chan struct{}) {
}
// GetConfig ...
func (d Dummy) GetConfig() *config.Configuration {
if d.cfg != nil {
return d.cfg
}
return &config.Configuration{}
}
// SetConfig ...
func (d *Dummy) SetConfig(c *config.Configuration) {
d.cfg = c
}
// GetInstanceIDFromPodIP ...
func (d *Dummy) GetNodeInstanceID(node *corev1.Node) (string, error) {
return d.GetNodeInstanceIDFunc(node)
}
// GetInstanceIDFromPodIP ...
func (d *Dummy) GetInstanceIDFromPodIP(s string) (string, error) {
return "", nil
}
func NewDummy() *Dummy {
return &Dummy{
GetServiceFunc: func(_ string) (*corev1.Service, error) { return dummy.NewService(), nil },
ListNodesFunc: func() []*corev1.Node { return nil },
GetNodeInstanceIDFunc: func(*corev1.Node) (string, error) { return "", nil },
GetServiceEndpointsFunc: func(string) (*corev1.Endpoints, error) { return nil, nil },
GetPodFunc: func(string) (*corev1.Pod, error) { return &corev1.Pod{}, nil },
GetIngressAnnotationsResponse: annotations.NewIngressDummy(),
GetServiceAnnotationsResponse: annotations.NewServiceDummy(),
}
}