diff options
Diffstat (limited to 'plugin/kubernetes/kubernetes_test.go')
-rw-r--r-- | plugin/kubernetes/kubernetes_test.go | 327 |
1 files changed, 112 insertions, 215 deletions
diff --git a/plugin/kubernetes/kubernetes_test.go b/plugin/kubernetes/kubernetes_test.go index 36d00a92f..f35c9cd2c 100644 --- a/plugin/kubernetes/kubernetes_test.go +++ b/plugin/kubernetes/kubernetes_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/coredns/coredns/plugin" + "github.com/coredns/coredns/plugin/kubernetes/object" "github.com/coredns/coredns/plugin/pkg/watch" "github.com/coredns/coredns/request" @@ -49,7 +50,7 @@ func TestEndpointHostname(t *testing.T) { {"10.11.12.13", "", "hello-abcde", "hello-abcde", true}, } for _, test := range tests { - result := endpointHostname(api.EndpointAddress{IP: test.ip, Hostname: test.hostname, TargetRef: &api.ObjectReference{Name: test.podName}}, test.endpointNameMode) + result := endpointHostname(object.EndpointAddress{IP: test.ip, Hostname: test.hostname, TargetRefName: test.podName}, test.endpointNameMode) if result != test.expected { t.Errorf("Expected endpoint name for (ip:%v hostname:%v) to be '%v', but got '%v'", test.ip, test.hostname, test.expected, result) } @@ -58,184 +59,122 @@ func TestEndpointHostname(t *testing.T) { type APIConnServiceTest struct{} -func (APIConnServiceTest) HasSynced() bool { return true } -func (APIConnServiceTest) Run() { return } -func (APIConnServiceTest) Stop() error { return nil } -func (APIConnServiceTest) PodIndex(string) []*api.Pod { return nil } -func (APIConnServiceTest) SvcIndexReverse(string) []*api.Service { return nil } -func (APIConnServiceTest) EpIndexReverse(string) []*api.Endpoints { return nil } -func (APIConnServiceTest) Modified() int64 { return 0 } -func (APIConnServiceTest) SetWatchChan(watch.Chan) {} -func (APIConnServiceTest) Watch(string) error { return nil } -func (APIConnServiceTest) StopWatching(string) {} +func (APIConnServiceTest) HasSynced() bool { return true } +func (APIConnServiceTest) Run() { return } +func (APIConnServiceTest) Stop() error { return nil } +func (APIConnServiceTest) PodIndex(string) []*object.Pod { return nil } +func (APIConnServiceTest) SvcIndexReverse(string) []*object.Service { return nil } +func (APIConnServiceTest) EpIndexReverse(string) []*object.Endpoints { return nil } +func (APIConnServiceTest) Modified() int64 { return 0 } +func (APIConnServiceTest) SetWatchChan(watch.Chan) {} +func (APIConnServiceTest) Watch(string) error { return nil } +func (APIConnServiceTest) StopWatching(string) {} -func (APIConnServiceTest) SvcIndex(string) []*api.Service { - svcs := []*api.Service{ +func (APIConnServiceTest) SvcIndex(string) []*object.Service { + svcs := []*object.Service{ { - ObjectMeta: meta.ObjectMeta{ - Name: "svc1", - Namespace: "testns", - }, - Spec: api.ServiceSpec{ - ClusterIP: "10.0.0.1", - Ports: []api.ServicePort{{ - Name: "http", - Protocol: "tcp", - Port: 80, - }}, + Name: "svc1", + Namespace: "testns", + ClusterIP: "10.0.0.1", + Ports: []api.ServicePort{ + {Name: "http", Protocol: "tcp", Port: 80}, }, }, { - ObjectMeta: meta.ObjectMeta{ - Name: "hdls1", - Namespace: "testns", - }, - Spec: api.ServiceSpec{ - ClusterIP: api.ClusterIPNone, - }, + Name: "hdls1", + Namespace: "testns", + ClusterIP: api.ClusterIPNone, }, { - ObjectMeta: meta.ObjectMeta{ - Name: "external", - Namespace: "testns", - }, - Spec: api.ServiceSpec{ - ExternalName: "coredns.io", - Ports: []api.ServicePort{{ - Name: "http", - Protocol: "tcp", - Port: 80, - }}, - Type: api.ServiceTypeExternalName, + Name: "external", + Namespace: "testns", + ExternalName: "coredns.io", + Type: api.ServiceTypeExternalName, + Ports: []api.ServicePort{ + {Name: "http", Protocol: "tcp", Port: 80}, }, }, } return svcs } -func (APIConnServiceTest) ServiceList() []*api.Service { - svcs := []*api.Service{ +func (APIConnServiceTest) ServiceList() []*object.Service { + svcs := []*object.Service{ { - ObjectMeta: meta.ObjectMeta{ - Name: "svc1", - Namespace: "testns", - }, - Spec: api.ServiceSpec{ - ClusterIP: "10.0.0.1", - Ports: []api.ServicePort{{ - Name: "http", - Protocol: "tcp", - Port: 80, - }}, + Name: "svc1", + Namespace: "testns", + ClusterIP: "10.0.0.1", + Ports: []api.ServicePort{ + {Name: "http", Protocol: "tcp", Port: 80}, }, }, { - ObjectMeta: meta.ObjectMeta{ - Name: "hdls1", - Namespace: "testns", - }, - Spec: api.ServiceSpec{ - ClusterIP: api.ClusterIPNone, - }, + Name: "hdls1", + Namespace: "testns", + ClusterIP: api.ClusterIPNone, }, { - ObjectMeta: meta.ObjectMeta{ - Name: "external", - Namespace: "testns", - }, - Spec: api.ServiceSpec{ - ExternalName: "coredns.io", - Ports: []api.ServicePort{{ - Name: "http", - Protocol: "tcp", - Port: 80, - }}, - Type: api.ServiceTypeExternalName, + Name: "external", + Namespace: "testns", + ExternalName: "coredns.io", + Type: api.ServiceTypeExternalName, + Ports: []api.ServicePort{ + {Name: "http", Protocol: "tcp", Port: 80}, }, }, } return svcs } -func (APIConnServiceTest) EpIndex(string) []*api.Endpoints { - n := "test.node.foo.bar" - - eps := []*api.Endpoints{ +func (APIConnServiceTest) EpIndex(string) []*object.Endpoints { + eps := []*object.Endpoints{ { - Subsets: []api.EndpointSubset{ + Subsets: []object.EndpointSubset{ { - Addresses: []api.EndpointAddress{ - { - IP: "172.0.0.1", - Hostname: "ep1a", - }, + Addresses: []object.EndpointAddress{ + {IP: "172.0.0.1", Hostname: "ep1a"}, }, - Ports: []api.EndpointPort{ - { - Port: 80, - Protocol: "tcp", - Name: "http", - }, + Ports: []object.EndpointPort{ + {Port: 80, Protocol: "tcp", Name: "http"}, }, }, }, - ObjectMeta: meta.ObjectMeta{ - Name: "svc1", - Namespace: "testns", - }, + Name: "svc1", + Namespace: "testns", }, { - Subsets: []api.EndpointSubset{ + Subsets: []object.EndpointSubset{ { - Addresses: []api.EndpointAddress{ - { - IP: "172.0.0.2", - }, + Addresses: []object.EndpointAddress{ + {IP: "172.0.0.2"}, }, - Ports: []api.EndpointPort{ - { - Port: 80, - Protocol: "tcp", - Name: "http", - }, + Ports: []object.EndpointPort{ + {Port: 80, Protocol: "tcp", Name: "http"}, }, }, }, - ObjectMeta: meta.ObjectMeta{ - Name: "hdls1", - Namespace: "testns", - }, + Name: "hdls1", + Namespace: "testns", }, { - Subsets: []api.EndpointSubset{ + Subsets: []object.EndpointSubset{ { - Addresses: []api.EndpointAddress{ - { - IP: "172.0.0.3", - }, + Addresses: []object.EndpointAddress{ + {IP: "172.0.0.3"}, }, - Ports: []api.EndpointPort{ - { - Port: 80, - Protocol: "tcp", - Name: "http", - }, + Ports: []object.EndpointPort{ + {Port: 80, Protocol: "tcp", Name: "http"}, }, }, }, - ObjectMeta: meta.ObjectMeta{ - Name: "hdls1", - Namespace: "testns", - }, + Name: "hdls1", + Namespace: "testns", }, { - Subsets: []api.EndpointSubset{ + Subsets: []object.EndpointSubset{ { - Addresses: []api.EndpointAddress{ - { - IP: "10.9.8.7", - NodeName: &n, - }, + Addresses: []object.EndpointAddress{ + {IP: "10.9.8.7", NodeName: "test.node.foo.bar"}, }, }, }, @@ -244,85 +183,55 @@ func (APIConnServiceTest) EpIndex(string) []*api.Endpoints { return eps } -func (APIConnServiceTest) EndpointsList() []*api.Endpoints { - n := "test.node.foo.bar" - - eps := []*api.Endpoints{ +func (APIConnServiceTest) EndpointsList() []*object.Endpoints { + eps := []*object.Endpoints{ { - Subsets: []api.EndpointSubset{ + Subsets: []object.EndpointSubset{ { - Addresses: []api.EndpointAddress{ - { - IP: "172.0.0.1", - Hostname: "ep1a", - }, + Addresses: []object.EndpointAddress{ + {IP: "172.0.0.1", Hostname: "ep1a"}, }, - Ports: []api.EndpointPort{ - { - Port: 80, - Protocol: "tcp", - Name: "http", - }, + Ports: []object.EndpointPort{ + {Port: 80, Protocol: "tcp", Name: "http"}, }, }, }, - ObjectMeta: meta.ObjectMeta{ - Name: "svc1", - Namespace: "testns", - }, + Name: "svc1", + Namespace: "testns", }, { - Subsets: []api.EndpointSubset{ + Subsets: []object.EndpointSubset{ { - Addresses: []api.EndpointAddress{ - { - IP: "172.0.0.2", - }, + Addresses: []object.EndpointAddress{ + {IP: "172.0.0.2"}, }, - Ports: []api.EndpointPort{ - { - Port: 80, - Protocol: "tcp", - Name: "http", - }, + Ports: []object.EndpointPort{ + {Port: 80, Protocol: "tcp", Name: "http"}, }, }, }, - ObjectMeta: meta.ObjectMeta{ - Name: "hdls1", - Namespace: "testns", - }, + Name: "hdls1", + Namespace: "testns", }, { - Subsets: []api.EndpointSubset{ + Subsets: []object.EndpointSubset{ { - Addresses: []api.EndpointAddress{ - { - IP: "172.0.0.3", - }, + Addresses: []object.EndpointAddress{ + {IP: "172.0.0.3"}, }, - Ports: []api.EndpointPort{ - { - Port: 80, - Protocol: "tcp", - Name: "http", - }, + Ports: []object.EndpointPort{ + {Port: 80, Protocol: "tcp", Name: "http"}, }, }, }, - ObjectMeta: meta.ObjectMeta{ - Name: "hdls1", - Namespace: "testns", - }, + Name: "hdls1", + Namespace: "testns", }, { - Subsets: []api.EndpointSubset{ + Subsets: []object.EndpointSubset{ { - Addresses: []api.EndpointAddress{ - { - IP: "10.9.8.7", - NodeName: &n, - }, + Addresses: []object.EndpointAddress{ + {IP: "10.9.8.7", NodeName: "test.node.foo.bar"}, }, }, }, @@ -397,11 +306,9 @@ func TestServices(t *testing.T) { func TestServiceFQDN(t *testing.T) { fqdn := serviceFQDN( - &api.Service{ - ObjectMeta: meta.ObjectMeta{ - Name: "svc1", - Namespace: "testns", - }, + &object.Service{ + Name: "svc1", + Namespace: "testns", }, "cluster.local") expected := "svc1.testns.svc.cluster.local." @@ -412,14 +319,10 @@ func TestServiceFQDN(t *testing.T) { func TestPodFQDN(t *testing.T) { fqdn := podFQDN( - &api.Pod{ - ObjectMeta: meta.ObjectMeta{ - Name: "pod1", - Namespace: "testns", - }, - Status: api.PodStatus{ - PodIP: "10.10.0.10", - }, + &object.Pod{ + Name: "pod1", + Namespace: "testns", + PodIP: "10.10.0.10", }, "cluster.local") expected := "10-10-0-10.testns.pod.cluster.local." @@ -427,14 +330,10 @@ func TestPodFQDN(t *testing.T) { t.Errorf("Expected '%v', got '%v'.", expected, fqdn) } fqdn = podFQDN( - &api.Pod{ - ObjectMeta: meta.ObjectMeta{ - Name: "pod1", - Namespace: "testns", - }, - Status: api.PodStatus{ - PodIP: "aaaa:bbbb:cccc::zzzz", - }, + &object.Pod{ + Name: "pod1", + Namespace: "testns", + PodIP: "aaaa:bbbb:cccc::zzzz", }, "cluster.local") expected = "aaaa-bbbb-cccc--zzzz.testns.pod.cluster.local." @@ -445,10 +344,10 @@ func TestPodFQDN(t *testing.T) { func TestEndpointFQDN(t *testing.T) { fqdns := endpointFQDN( - &api.Endpoints{ - Subsets: []api.EndpointSubset{ + &object.Endpoints{ + Subsets: []object.EndpointSubset{ { - Addresses: []api.EndpointAddress{ + Addresses: []object.EndpointAddress{ { IP: "172.0.0.1", Hostname: "ep1a", @@ -459,10 +358,8 @@ func TestEndpointFQDN(t *testing.T) { }, }, }, - ObjectMeta: meta.ObjectMeta{ - Name: "svc1", - Namespace: "testns", - }, + Name: "svc1", + Namespace: "testns", }, "cluster.local", false) expected := []string{ |