Watch feature (#1527)
* Add part 1 watch functionality. (squashed) * add funcs for service/endpoint fqdns * add endpoints watch * document exposed funcs * only send subset deltas * locking for watch map * tests and docs * add pod watch * remove debugs prints * feedback part 1 * add error reporting to proto * inform clients of server stop+errors * add grpc options param * use proper context * Review feedback: * Removed client (will move to another repo) * Use new log functions * Change watchChan to be for string not []string * Rework how k8s plugin stores watch tracking info to simplify * Normalize the qname on watch request * Add blank line back * Revert another spurious change * Fix tests * Add stop channel. Fix tests. Better docs for plugin interface. * fmt.Printf -> log.Warningf * Move from dnsserver to plugin/pkg/watch * gofmt * remove dead client watches * sate linter * linter omg
This commit is contained in:
parent
b7480d5d12
commit
99287d091c
17 changed files with 980 additions and 60 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/coredns/coredns/plugin/pkg/watch"
|
||||
"github.com/coredns/coredns/request"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
|
@ -64,6 +65,9 @@ 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) SvcIndex(string) []*api.Service {
|
||||
svcs := []*api.Service{
|
||||
|
@ -390,3 +394,85 @@ func TestServices(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceFQDN(t *testing.T) {
|
||||
fqdn := serviceFQDN(
|
||||
&api.Service{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: "svc1",
|
||||
Namespace: "testns",
|
||||
},
|
||||
}, "cluster.local")
|
||||
|
||||
expected := "svc1.testns.svc.cluster.local."
|
||||
if fqdn != expected {
|
||||
t.Errorf("Expected '%v', got '%v'.", expected, fqdn)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPodFQDN(t *testing.T) {
|
||||
fqdn := podFQDN(
|
||||
&api.Pod{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: "pod1",
|
||||
Namespace: "testns",
|
||||
},
|
||||
Status: api.PodStatus{
|
||||
PodIP: "10.10.0.10",
|
||||
},
|
||||
}, "cluster.local")
|
||||
|
||||
expected := "10-10-0-10.testns.pod.cluster.local."
|
||||
if fqdn != expected {
|
||||
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",
|
||||
},
|
||||
}, "cluster.local")
|
||||
|
||||
expected = "aaaa-bbbb-cccc--zzzz.testns.pod.cluster.local."
|
||||
if fqdn != expected {
|
||||
t.Errorf("Expected '%v', got '%v'.", expected, fqdn)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEndpointFQDN(t *testing.T) {
|
||||
fqdns := endpointFQDN(
|
||||
&api.Endpoints{
|
||||
Subsets: []api.EndpointSubset{
|
||||
{
|
||||
Addresses: []api.EndpointAddress{
|
||||
{
|
||||
IP: "172.0.0.1",
|
||||
Hostname: "ep1a",
|
||||
},
|
||||
{
|
||||
IP: "172.0.0.2",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: "svc1",
|
||||
Namespace: "testns",
|
||||
},
|
||||
}, "cluster.local", false)
|
||||
|
||||
expected := []string{
|
||||
"ep1a.svc1.testns.svc.cluster.local.",
|
||||
"172-0-0-2.svc1.testns.svc.cluster.local.",
|
||||
}
|
||||
|
||||
for i := range fqdns {
|
||||
if fqdns[i] != expected[i] {
|
||||
t.Errorf("Expected '%v', got '%v'.", expected[i], fqdns[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue