mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-30 17:53:21 -04:00 
			
		
		
		
	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
This commit is contained in:
		| @@ -32,7 +32,6 @@ import ( | |||||||
| type Kubernetes struct { | type Kubernetes struct { | ||||||
| 	Next          middleware.Handler | 	Next          middleware.Handler | ||||||
| 	Zones         []string | 	Zones         []string | ||||||
| 	primaryZone   int |  | ||||||
| 	Proxy         proxy.Proxy // Proxy for looking up names during the resolution process | 	Proxy         proxy.Proxy // Proxy for looking up names during the resolution process | ||||||
| 	APIServerList []string | 	APIServerList []string | ||||||
| 	APIProxy      *apiProxy | 	APIProxy      *apiProxy | ||||||
| @@ -49,6 +48,7 @@ type Kubernetes struct { | |||||||
| 	ReverseCidrs  []net.IPNet | 	ReverseCidrs  []net.IPNet | ||||||
| 	Fallthrough   bool | 	Fallthrough   bool | ||||||
|  |  | ||||||
|  | 	primaryZoneIndex   int | ||||||
| 	interfaceAddrsFunc func() net.IP | 	interfaceAddrsFunc func() net.IP | ||||||
| 	autoPathSearch     []string // Local search path from /etc/resolv.conf. Needed for autopath. | 	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 | 	return nil, nil, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // PrimaryZone will return the first non-reverse zone being handled by this middleware | // primaryZone will return the first non-reverse zone being handled by this middleware | ||||||
| func (k *Kubernetes) PrimaryZone() string { | func (k *Kubernetes) primaryZone() string { | ||||||
| 	return k.Zones[k.primaryZone] | 	return k.Zones[k.primaryZoneIndex] | ||||||
| } | } | ||||||
|  |  | ||||||
| // Lookup implements the ServiceBackend interface. | // Lookup implements the ServiceBackend interface. | ||||||
| @@ -538,7 +538,7 @@ func (k *Kubernetes) getServiceRecordForIP(ip, name string) []msg.Service { | |||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 		if service.Spec.ClusterIP == ip { | 		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}} | 			return []msg.Service{{Host: domain}} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| @@ -551,7 +551,7 @@ func (k *Kubernetes) getServiceRecordForIP(ip, name string) []msg.Service { | |||||||
| 		for _, eps := range ep.Subsets { | 		for _, eps := range ep.Subsets { | ||||||
| 			for _, addr := range eps.Addresses { | 			for _, addr := range eps.Addresses { | ||||||
| 				if addr.IP == ip { | 				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}} | 					return []msg.Service{{Host: domain}} | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|   | |||||||
| @@ -10,15 +10,6 @@ import ( | |||||||
| 	"k8s.io/client-go/1.5/pkg/api" | 	"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) { | func TestWildcard(t *testing.T) { | ||||||
| 	var tests = []struct { | 	var tests = []struct { | ||||||
| 		s        string | 		s        string | ||||||
| @@ -104,7 +95,6 @@ func (APIConnServiceTest) ServiceList() []*api.Service { | |||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	return svcs | 	return svcs | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| func (APIConnServiceTest) EndpointsList() api.EndpointsList { | 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", "4.3.2.1.in-addr.arpa.", true}, | ||||||
| 		{"1.2.3.0/24", "5.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}, | 		{"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.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}, | 		{"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 { | 	for _, test := range tests { | ||||||
| 		_, cidr, _ := net.ParseCIDR(test.cidr) | 		_, 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 { | 			for i, z := range k8s.Zones { | ||||||
| 				if strings.HasSuffix(z, "in-addr.arpa.") || strings.HasSuffix(z, "ip6.arpa.") { | 				if strings.HasSuffix(z, "in-addr.arpa.") || strings.HasSuffix(z, "ip6.arpa.") { | ||||||
| 					continue | 					continue | ||||||
| 				} | 				} | ||||||
| 				k8s.primaryZone = i | 				k8s.primaryZoneIndex = i | ||||||
| 				break | 				break | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			if k8s.primaryZone == -1 { | 			if k8s.primaryZoneIndex == -1 { | ||||||
| 				return nil, errors.New("non-reverse zone name must be given for Kubernetes") | 				return nil, errors.New("non-reverse zone name must be given for Kubernetes") | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| @@ -222,8 +222,4 @@ func searchFromResolvConf() []string { | |||||||
| 	return rc.Search | 	return rc.Search | ||||||
| } | } | ||||||
|  |  | ||||||
| const ( | const defaultResyncPeriod = 5 * time.Minute | ||||||
| 	defaultResyncPeriod = 5 * time.Minute |  | ||||||
| 	defautNdots         = 0 |  | ||||||
| 	defaultOnNXDOMAIN   = dns.RcodeSuccess |  | ||||||
| ) |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user