BK8s datasource middleware -- PoC for A records (#153)
* Laying down kubernetes middleware foundation * Duplicated a bunch of code form etcd middleware * Duplicated code hacked to compile and load as a separate middleware * Adding verbose build option to Makefile * Removing stubzone and tls support tls and stubzone support was carried over from base etcd middleware code. Removing to simplify the kube middleware implementation. (For now.) * Adding conf directory for sample conf files * Removing stubzone support from query handler * Remove upstream and proxy from k8s corefile. Not sure that upstream or proxy makes sense for a k8s backed zone. * Comment out use of singleflight serialization * Removing parsing support for "upstream" directive from k8s * Removing upstream directive parsing code * Removing CNAME and TXT lookup implementation * Create README.md Brain-dump of DNS record name assembly and open work items. * Adding notes about wildcard handling * Adding basic k8s API client * Fleshing out methods on k8s connector * Remove PathPrefix from middleware init * Removing incorrect plural * Adding brute-force k8s service lookup functions * Initializing k8s API connector during startup * Hacking around to call k8s connector * Parsing incoming domain name into serviceName and namespace * Improving and simplifying k8s zone matching and label segmentation * Removing unused functions carried over from etcd middleware * Adding basic return of k8s data to DNS client * updated debugging println statements to flag with "[debug]" * removed code in kubernetes.go::Records that was a hold-over from etcd middleware. * Removed some random exploratory hacking. * Minior README.md updates * Updating with demo instructions * Updating README.md with CoreFile and removing completed TODO items * Updating conf file and README to reflect DNS response cache works * Disabling DNS response caching * Adding debug statement on entry to Records() * Changing port number in exampes to port 53. * Misc style and clarity changes * Removing empty function definitions * Adding comment to track future cleanup * Refactoring README to follow style of other middleware * Exposing dataobject field (typo)
This commit is contained in:
parent
446eaa957d
commit
d04abdf422
14 changed files with 1560 additions and 1 deletions
125
middleware/kubernetes/msg/service_test.go
Normal file
125
middleware/kubernetes/msg/service_test.go
Normal file
|
@ -0,0 +1,125 @@
|
|||
package msg
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSplit255(t *testing.T) {
|
||||
xs := split255("abc")
|
||||
if len(xs) != 1 && xs[0] != "abc" {
|
||||
t.Errorf("Failure to split abc")
|
||||
}
|
||||
s := ""
|
||||
for i := 0; i < 255; i++ {
|
||||
s += "a"
|
||||
}
|
||||
xs = split255(s)
|
||||
if len(xs) != 1 && xs[0] != s {
|
||||
t.Errorf("failure to split 255 char long string")
|
||||
}
|
||||
s += "b"
|
||||
xs = split255(s)
|
||||
if len(xs) != 2 || xs[1] != "b" {
|
||||
t.Errorf("failure to split 256 char long string: %d", len(xs))
|
||||
}
|
||||
for i := 0; i < 255; i++ {
|
||||
s += "a"
|
||||
}
|
||||
xs = split255(s)
|
||||
if len(xs) != 3 || xs[2] != "a" {
|
||||
t.Errorf("failure to split 510 char long string: %d", len(xs))
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroup(t *testing.T) {
|
||||
// Key are in the wrong order, but for this test it does not matter.
|
||||
sx := Group(
|
||||
[]Service{
|
||||
{Host: "127.0.0.1", Group: "g1", Key: "b/sub/dom1/skydns/test"},
|
||||
{Host: "127.0.0.2", Group: "g2", Key: "a/dom1/skydns/test"},
|
||||
},
|
||||
)
|
||||
// Expecting to return the shortest key with a Group attribute.
|
||||
if len(sx) != 1 {
|
||||
t.Fatalf("failure to group zeroth set: %v", sx)
|
||||
}
|
||||
if sx[0].Key != "a/dom1/skydns/test" {
|
||||
t.Fatalf("failure to group zeroth set: %v, wrong Key", sx)
|
||||
}
|
||||
|
||||
// Groups disagree, so we will not do anything.
|
||||
sx = Group(
|
||||
[]Service{
|
||||
{Host: "server1", Group: "g1", Key: "region1/skydns/test"},
|
||||
{Host: "server2", Group: "g2", Key: "region1/skydns/test"},
|
||||
},
|
||||
)
|
||||
if len(sx) != 2 {
|
||||
t.Fatalf("failure to group first set: %v", sx)
|
||||
}
|
||||
|
||||
// Group is g1, include only the top-level one.
|
||||
sx = Group(
|
||||
[]Service{
|
||||
{Host: "server1", Group: "g1", Key: "a/dom/region1/skydns/test"},
|
||||
{Host: "server2", Group: "g2", Key: "a/subdom/dom/region1/skydns/test"},
|
||||
},
|
||||
)
|
||||
if len(sx) != 1 {
|
||||
t.Fatalf("failure to group second set: %v", sx)
|
||||
}
|
||||
|
||||
// Groupless services must be included.
|
||||
sx = Group(
|
||||
[]Service{
|
||||
{Host: "server1", Group: "g1", Key: "a/dom/region1/skydns/test"},
|
||||
{Host: "server2", Group: "g2", Key: "a/subdom/dom/region1/skydns/test"},
|
||||
{Host: "server2", Group: "", Key: "b/subdom/dom/region1/skydns/test"},
|
||||
},
|
||||
)
|
||||
if len(sx) != 2 {
|
||||
t.Fatalf("failure to group third set: %v", sx)
|
||||
}
|
||||
|
||||
// Empty group on the highest level: include that one also.
|
||||
sx = Group(
|
||||
[]Service{
|
||||
{Host: "server1", Group: "g1", Key: "a/dom/region1/skydns/test"},
|
||||
{Host: "server1", Group: "", Key: "b/dom/region1/skydns/test"},
|
||||
{Host: "server2", Group: "g2", Key: "a/subdom/dom/region1/skydns/test"},
|
||||
},
|
||||
)
|
||||
if len(sx) != 2 {
|
||||
t.Fatalf("failure to group fourth set: %v", sx)
|
||||
}
|
||||
|
||||
// Empty group on the highest level: include that one also, and the rest.
|
||||
sx = Group(
|
||||
[]Service{
|
||||
{Host: "server1", Group: "g5", Key: "a/dom/region1/skydns/test"},
|
||||
{Host: "server1", Group: "", Key: "b/dom/region1/skydns/test"},
|
||||
{Host: "server2", Group: "g5", Key: "a/subdom/dom/region1/skydns/test"},
|
||||
},
|
||||
)
|
||||
if len(sx) != 3 {
|
||||
t.Fatalf("failure to group fith set: %v", sx)
|
||||
}
|
||||
|
||||
// One group.
|
||||
sx = Group(
|
||||
[]Service{
|
||||
{Host: "server1", Group: "g6", Key: "a/dom/region1/skydns/test"},
|
||||
},
|
||||
)
|
||||
if len(sx) != 1 {
|
||||
t.Fatalf("failure to group sixth set: %v", sx)
|
||||
}
|
||||
|
||||
// No group, once service
|
||||
sx = Group(
|
||||
[]Service{
|
||||
{Host: "server1", Key: "a/dom/region1/skydns/test"},
|
||||
},
|
||||
)
|
||||
if len(sx) != 1 {
|
||||
t.Fatalf("failure to group seventh set: %v", sx)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue