aboutsummaryrefslogtreecommitdiff
path: root/middleware/kubernetes/autopath
diff options
context:
space:
mode:
Diffstat (limited to 'middleware/kubernetes/autopath')
-rw-r--r--middleware/kubernetes/autopath/autopath.go75
-rw-r--r--middleware/kubernetes/autopath/autopath_test.go26
-rw-r--r--middleware/kubernetes/autopath/cname.go10
3 files changed, 0 insertions, 111 deletions
diff --git a/middleware/kubernetes/autopath/autopath.go b/middleware/kubernetes/autopath/autopath.go
deleted file mode 100644
index c1b2179ae..000000000
--- a/middleware/kubernetes/autopath/autopath.go
+++ /dev/null
@@ -1,75 +0,0 @@
-package autopath
-
-import (
- "strings"
-
- "github.com/miekg/dns"
-)
-
-// Writer implements a ResponseWriter that also does the following:
-// * reverts question section of a packet to its original state.
-// This is done to avoid the 'Question section mismatch:' error in client.
-// * Defers write to the client if the response code is NXDOMAIN. This is needed
-// to enable further search path probing if a search was not successful.
-// * Allow forced write to client regardless of response code. This is needed to
-// write the packet to the client if the final search in the path fails to
-// produce results.
-// * Overwrites response code with Writer.Rcode if the response code
-// is NXDOMAIN (NameError). This is needed to support the AutoPath.OnNXDOMAIN
-// function, which returns a NOERROR to client instead of NXDOMAIN if the final
-// search in the path fails to produce results.
-type Writer struct {
- dns.ResponseWriter
- original dns.Question
- Rcode int
-}
-
-// AutoPath enables server side search path lookups for pods.
-type AutoPath struct {
- NDots int
- ResolvConfFile string
- HostSearchPath []string
- OnNXDOMAIN int
-}
-
-// NewWriter returns a pointer to a new Writer
-func NewWriter(w dns.ResponseWriter, r *dns.Msg) *Writer {
- return &Writer{
- ResponseWriter: w,
- original: r.Question[0],
- Rcode: dns.RcodeSuccess,
- }
-}
-
-// WriteMsg writes to client, unless response will be NXDOMAIN.
-func (apw *Writer) WriteMsg(res *dns.Msg) error {
- if res.Rcode == dns.RcodeNameError {
- res.Rcode = apw.Rcode
- }
-
- for _, a := range res.Answer {
- if apw.original.Name == a.Header().Name {
- continue
- }
- res.Answer = append(res.Answer, nil)
- copy(res.Answer[1:], res.Answer)
- res.Answer[0] = CNAME(apw.original.Name, a.Header().Name, a.Header().Ttl)
- }
- res.Question[0] = apw.original
-
- return apw.ResponseWriter.WriteMsg(res)
-}
-
-// Write is a wrapper that records the size of the message that gets written.
-func (apw *Writer) Write(buf []byte) (int, error) {
- n, err := apw.ResponseWriter.Write(buf)
- return n, err
-}
-
-func SplitSearch(zone, question, namespace string) (name, search string, ok bool) {
- search = strings.Join([]string{namespace, "svc", zone}, ".")
- if dns.IsSubDomain(search, question) {
- return question[:len(question)-len(search)-1], search, true
- }
- return "", "", false
-}
diff --git a/middleware/kubernetes/autopath/autopath_test.go b/middleware/kubernetes/autopath/autopath_test.go
deleted file mode 100644
index 787896e42..000000000
--- a/middleware/kubernetes/autopath/autopath_test.go
+++ /dev/null
@@ -1,26 +0,0 @@
-package autopath
-
-import "testing"
-
-func TestSplitSearchPath(t *testing.T) {
- type testCase struct {
- question string
- namespace string
- expectedName string
- expectedSearch string
- expectedOk bool
- }
- tests := []testCase{
- {question: "test.blah.com", namespace: "ns1", expectedName: "", expectedSearch: "", expectedOk: false},
- {question: "foo.com.ns2.svc.interwebs.nets", namespace: "ns1", expectedName: "", expectedSearch: "", expectedOk: false},
- {question: "foo.com.svc.interwebs.nets", namespace: "ns1", expectedName: "", expectedSearch: "", expectedOk: false},
- {question: "foo.com.ns1.svc.interwebs.nets", namespace: "ns1", expectedName: "foo.com", expectedSearch: "ns1.svc.interwebs.nets", expectedOk: true},
- }
- zone := "interwebs.nets"
- for _, c := range tests {
- name, search, ok := SplitSearch(zone, c.question, c.namespace)
- if c.expectedName != name || c.expectedSearch != search || c.expectedOk != ok {
- t.Errorf("Case %v: Expected name'%v', search:'%v', ok:'%v'. Got name:'%v', search:'%v', ok:'%v'.", c.question, c.expectedName, c.expectedSearch, c.expectedOk, name, search, ok)
- }
- }
-}
diff --git a/middleware/kubernetes/autopath/cname.go b/middleware/kubernetes/autopath/cname.go
deleted file mode 100644
index 471266747..000000000
--- a/middleware/kubernetes/autopath/cname.go
+++ /dev/null
@@ -1,10 +0,0 @@
-package autopath
-
-import "github.com/miekg/dns"
-
-// CNAME returns a new CNAME formed from name target and ttl.
-func CNAME(name string, target string, ttl uint32) *dns.CNAME {
- return &dns.CNAME{
- Hdr: dns.RR_Header{Name: name, Rrtype: dns.TypeCNAME, Class: dns.ClassINET, Ttl: ttl},
- Target: dns.Fqdn(target)}
-}