Commit 241e3dbc authored by Miek Gieben's avatar Miek Gieben Committed by GitHub

mw/k8s: cleanups (#893)

* mw/k8s: cleanups

Remove some constants that aren't used any more. Make PrimaryZone
private because it doesn't need to be exported. Remove test that
did not cover corner case as expressed in setup.go

* cleanup this as well
parent 028a6db4
......@@ -32,7 +32,6 @@ import (
type Kubernetes struct {
Next middleware.Handler
Zones []string
primaryZone int
Proxy proxy.Proxy // Proxy for looking up names during the resolution process
APIServerList []string
APIProxy *apiProxy
......@@ -49,6 +48,7 @@ type Kubernetes struct {
ReverseCidrs []net.IPNet
Fallthrough bool
primaryZoneIndex int
interfaceAddrsFunc func() net.IP
autoPathSearch []string // Local search path from /etc/resolv.conf. Needed for autopath.
}
......@@ -154,9 +154,9 @@ func (k *Kubernetes) Services(state request.Request, exact bool, opt middleware.
return nil, nil, nil
}
// PrimaryZone will return the first non-reverse zone being handled by this middleware
func (k *Kubernetes) PrimaryZone() string {
return k.Zones[k.primaryZone]
// primaryZone will return the first non-reverse zone being handled by this middleware
func (k *Kubernetes) primaryZone() string {
return k.Zones[k.primaryZoneIndex]
}
// Lookup implements the ServiceBackend interface.
......@@ -538,7 +538,7 @@ func (k *Kubernetes) getServiceRecordForIP(ip, name string) []msg.Service {
continue
}
if service.Spec.ClusterIP == ip {
domain := strings.Join([]string{service.Name, service.Namespace, Svc, k.PrimaryZone()}, ".")
domain := strings.Join([]string{service.Name, service.Namespace, Svc, k.primaryZone()}, ".")
return []msg.Service{{Host: domain}}
}
}
......@@ -551,7 +551,7 @@ func (k *Kubernetes) getServiceRecordForIP(ip, name string) []msg.Service {
for _, eps := range ep.Subsets {
for _, addr := range eps.Addresses {
if addr.IP == ip {
domain := strings.Join([]string{endpointHostname(addr), ep.ObjectMeta.Name, ep.ObjectMeta.Namespace, Svc, k.PrimaryZone()}, ".")
domain := strings.Join([]string{endpointHostname(addr), ep.ObjectMeta.Name, ep.ObjectMeta.Namespace, Svc, k.primaryZone()}, ".")
return []msg.Service{{Host: domain}}
}
}
......
......@@ -10,15 +10,6 @@ import (
"k8s.io/client-go/1.5/pkg/api"
)
func TestPrimaryZone(t *testing.T) {
k := Kubernetes{Zones: []string{"inter.webs.test", "inter.nets.test"}}
expected := "inter.webs.test"
result := k.PrimaryZone()
if result != expected {
t.Errorf("Expected result '%v'. Instead got result '%v'.", expected, result)
}
}
func TestWildcard(t *testing.T) {
var tests = []struct {
s string
......@@ -104,7 +95,6 @@ func (APIConnServiceTest) ServiceList() []*api.Service {
},
}
return svcs
}
func (APIConnServiceTest) EndpointsList() api.EndpointsList {
......
......@@ -14,13 +14,13 @@ func TestIsRequestInReverseRange(t *testing.T) {
}{
{"1.2.3.0/24", "4.3.2.1.in-addr.arpa.", true},
{"1.2.3.0/24", "5.3.2.1.in-addr.arpa.", true},
{"5.6.0.0/16", "5.4.6.5.in-addr.arpa.", true},
{"1.2.3.0/24", "5.4.2.1.in-addr.arpa.", false},
{"5.6.0.0/16", "5.4.2.1.in-addr.arpa.", false},
{"5.6.0.0/16", "5.4.6.5.in-addr.arpa.", true},
{"5.6.0.0/16", "5.6.0.1.in-addr.arpa.", false},
}
k := Kubernetes{Zones: []string{"inter.webs.test"}}
k := Kubernetes{}
for _, test := range tests {
_, cidr, _ := net.ParseCIDR(test.cidr)
......
......@@ -87,16 +87,16 @@ func kubernetesParse(c *caddy.Controller) (*Kubernetes, error) {
}
}
k8s.primaryZone = -1
k8s.primaryZoneIndex = -1
for i, z := range k8s.Zones {
if strings.HasSuffix(z, "in-addr.arpa.") || strings.HasSuffix(z, "ip6.arpa.") {
continue
}
k8s.primaryZone = i
k8s.primaryZoneIndex = i
break
}
if k8s.primaryZone == -1 {
if k8s.primaryZoneIndex == -1 {
return nil, errors.New("non-reverse zone name must be given for Kubernetes")
}
......@@ -222,8 +222,4 @@ func searchFromResolvConf() []string {
return rc.Search
}
const (
defaultResyncPeriod = 5 * time.Minute
defautNdots = 0
defaultOnNXDOMAIN = dns.RcodeSuccess
)
const defaultResyncPeriod = 5 * time.Minute
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment