aboutsummaryrefslogtreecommitdiff
path: root/plugin/federation/kubernetes_api_test.go
blob: 4b62605d18939a1d593712cbf6c709006452aac5 (plain) (blame)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package federation

import (
	"github.com/coredns/coredns/plugin/kubernetes"
	"github.com/coredns/coredns/plugin/kubernetes/object"
	"github.com/coredns/coredns/plugin/pkg/watch"

	api "k8s.io/api/core/v1"
	meta "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type APIConnFederationTest struct {
	zone, region string
}

func (APIConnFederationTest) HasSynced() bool                           { return true }
func (APIConnFederationTest) Run()                                      { return }
func (APIConnFederationTest) Stop() error                               { return nil }
func (APIConnFederationTest) SvcIndexReverse(string) []*object.Service  { return nil }
func (APIConnFederationTest) EpIndexReverse(string) []*object.Endpoints { return nil }
func (APIConnFederationTest) Modified() int64                           { return 0 }
func (APIConnFederationTest) SetWatchChan(watch.Chan)                   {}
func (APIConnFederationTest) Watch(string) error                        { return nil }
func (APIConnFederationTest) StopWatching(string)                       {}

func (APIConnFederationTest) PodIndex(string) []*object.Pod {
	return []*object.Pod{
		{Namespace: "podns", PodIP: "10.240.0.1"}, // Remote IP set in test.ResponseWriter
	}
}

func (APIConnFederationTest) SvcIndex(string) []*object.Service {
	svcs := []*object.Service{
		{
			Name:      "svc1",
			Namespace: "testns",
			ClusterIP: "10.0.0.1",
			Ports: []api.ServicePort{
				{Name: "http", Protocol: "tcp", Port: 80},
			},
		},
		{
			Name:      "hdls1",
			Namespace: "testns",
			ClusterIP: api.ClusterIPNone,
		},
		{
			Name:         "external",
			Namespace:    "testns",
			ExternalName: "ext.interwebs.test",
			Ports: []api.ServicePort{
				{Name: "http", Protocol: "tcp", Port: 80},
			},
		},
	}
	return svcs
}

func (APIConnFederationTest) ServiceList() []*object.Service {
	svcs := []*object.Service{
		{
			Name:      "svc1",
			Namespace: "testns",
			ClusterIP: "10.0.0.1",
			Ports: []api.ServicePort{
				{Name: "http", Protocol: "tcp", Port: 80},
			},
		},
		{
			Name:      "hdls1",
			Namespace: "testns",
			ClusterIP: api.ClusterIPNone,
		},
		{
			Name:         "external",
			Namespace:    "testns",
			ExternalName: "ext.interwebs.test",
			Ports: []api.ServicePort{
				{Name: "http", Protocol: "tcp", Port: 80},
			},
		},
	}
	return svcs
}

func (APIConnFederationTest) EpIndex(string) []*object.Endpoints {
	eps := []*object.Endpoints{
		{
			Subsets: []object.EndpointSubset{
				{
					Addresses: []object.EndpointAddress{
						{IP: "172.0.0.1", Hostname: "ep1a"},
					},
					Ports: []object.EndpointPort{
						{Port: 80, Protocol: "tcp", Name: "http"},
					},
				},
			},
			Name:      "svc1",
			Namespace: "testns",
		},
	}
	return eps
}

func (APIConnFederationTest) EndpointsList() []*object.Endpoints {
	eps := []*object.Endpoints{
		{
			Subsets: []object.EndpointSubset{
				{
					Addresses: []object.EndpointAddress{
						{IP: "172.0.0.1", Hostname: "ep1a"},
					},
					Ports: []object.EndpointPort{
						{Port: 80, Protocol: "tcp", Name: "http"},
					},
				},
			},
			Name:      "svc1",
			Namespace: "testns",
		},
	}
	return eps
}

func (a APIConnFederationTest) GetNodeByName(name string) (*api.Node, error) {
	return &api.Node{
		ObjectMeta: meta.ObjectMeta{
			Name: "test.node.foo.bar",
			Labels: map[string]string{
				kubernetes.LabelRegion: a.region,
				kubernetes.LabelZone:   a.zone,
			},
		},
	}, nil
}

func (APIConnFederationTest) GetNamespaceByName(name string) (*api.Namespace, error) {
	return &api.Namespace{
		ObjectMeta: meta.ObjectMeta{
			Name: name,
		},
	}, nil
}