| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | package kubernetes
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import (
 | 
					
						
							| 
									
										
										
										
											2017-01-20 02:22:11 -05:00
										 |  |  | 	"errors"
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | 	"fmt"
 | 
					
						
							|  |  |  | 	"sync"
 | 
					
						
							| 
									
										
										
										
											2018-02-08 10:11:04 -06:00
										 |  |  | 	"sync/atomic"
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | 	"time"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 	"github.com/coredns/coredns/plugin/kubernetes/object"
 | 
					
						
							| 
									
										
										
										
											2018-06-27 07:45:32 -07:00
										 |  |  | 	dnswatch "github.com/coredns/coredns/plugin/pkg/watch"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-03 19:11:28 +08:00
										 |  |  | 	api "k8s.io/api/core/v1"
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 	meta "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
					
						
							|  |  |  | 	"k8s.io/apimachinery/pkg/labels"
 | 
					
						
							|  |  |  | 	"k8s.io/apimachinery/pkg/runtime"
 | 
					
						
							|  |  |  | 	"k8s.io/apimachinery/pkg/watch"
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 	"k8s.io/client-go/kubernetes"
 | 
					
						
							|  |  |  | 	"k8s.io/client-go/tools/cache"
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-08 10:11:04 -06:00
										 |  |  | const (
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | 	podIPIndex            = "PodIP"
 | 
					
						
							|  |  |  | 	svcNameNamespaceIndex = "NameNamespace"
 | 
					
						
							|  |  |  | 	svcIPIndex            = "ServiceIP"
 | 
					
						
							|  |  |  | 	epNameNamespaceIndex  = "EndpointNameNamespace"
 | 
					
						
							|  |  |  | 	epIPIndex             = "EndpointsIP"
 | 
					
						
							| 
									
										
										
										
											2018-02-08 10:11:04 -06:00
										 |  |  | )
 | 
					
						
							| 
									
										
										
										
											2017-01-20 02:22:11 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-22 16:05:48 -04:00
										 |  |  | type dnsController interface {
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 	ServiceList() []*object.Service
 | 
					
						
							|  |  |  | 	EndpointsList() []*object.Endpoints
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | 	SvcIndex(string) []*object.Service
 | 
					
						
							|  |  |  | 	SvcIndexReverse(string) []*object.Service
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 	PodIndex(string) []*object.Pod
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | 	EpIndex(string) []*object.Endpoints
 | 
					
						
							|  |  |  | 	EpIndexReverse(string) []*object.Endpoints
 | 
					
						
							| 
									
										
										
										
											2017-06-14 09:38:00 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 	GetNodeByName(string) (*api.Node, error)
 | 
					
						
							| 
									
										
										
										
											2017-11-13 21:51:51 +00:00
										 |  |  | 	GetNamespaceByName(string) (*api.Namespace, error)
 | 
					
						
							| 
									
										
										
										
											2017-06-14 09:38:00 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-22 16:05:48 -04:00
										 |  |  | 	Run()
 | 
					
						
							| 
									
										
										
										
											2017-10-20 22:53:17 +01:00
										 |  |  | 	HasSynced() bool
 | 
					
						
							| 
									
										
										
										
											2017-05-22 16:05:48 -04:00
										 |  |  | 	Stop() error
 | 
					
						
							| 
									
										
										
										
											2018-02-08 10:11:04 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Modified returns the timestamp of the most recent changes
 | 
					
						
							|  |  |  | 	Modified() int64
 | 
					
						
							| 
									
										
										
										
											2018-06-27 07:45:32 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Watch-related items
 | 
					
						
							|  |  |  | 	SetWatchChan(dnswatch.Chan)
 | 
					
						
							|  |  |  | 	Watch(string) error
 | 
					
						
							|  |  |  | 	StopWatching(string)
 | 
					
						
							| 
									
										
										
										
											2017-05-22 16:05:48 -04:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type dnsControl struct {
 | 
					
						
							| 
									
										
										
										
											2018-02-08 10:11:04 -06:00
										 |  |  | 	// Modified tracks timestamp of the most recent changes
 | 
					
						
							|  |  |  | 	// It needs to be first because it is guarnteed to be 8-byte
 | 
					
						
							|  |  |  | 	// aligned ( we use sync.LoadAtomic with this )
 | 
					
						
							|  |  |  | 	modified int64
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 10:43:09 -05:00
										 |  |  | 	client kubernetes.Interface
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 23:44:18 +03:00
										 |  |  | 	selector labels.Selector
 | 
					
						
							| 
									
										
										
										
											2016-08-12 20:44:08 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 	svcController cache.Controller
 | 
					
						
							|  |  |  | 	podController cache.Controller
 | 
					
						
							|  |  |  | 	epController  cache.Controller
 | 
					
						
							| 
									
										
										
										
											2018-02-15 14:21:54 -05:00
										 |  |  | 	nsController  cache.Controller
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 	svcLister cache.Indexer
 | 
					
						
							|  |  |  | 	podLister cache.Indexer
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 	epLister  cache.Indexer
 | 
					
						
							| 
									
										
										
										
											2018-09-22 15:12:02 +01:00
										 |  |  | 	nsLister  cache.Store
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// stopLock is used to enforce only a single call to Stop is active.
 | 
					
						
							|  |  |  | 	// Needed because we allow stopping through an http endpoint and
 | 
					
						
							|  |  |  | 	// allowing concurrent stoppers leads to stack traces.
 | 
					
						
							|  |  |  | 	stopLock sync.Mutex
 | 
					
						
							|  |  |  | 	shutdown bool
 | 
					
						
							|  |  |  | 	stopCh   chan struct{}
 | 
					
						
							| 
									
										
										
										
											2018-06-27 07:45:32 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// watch-related items channel
 | 
					
						
							|  |  |  | 	watchChan        dnswatch.Chan
 | 
					
						
							| 
									
										
										
										
											2018-09-22 18:13:33 +01:00
										 |  |  | 	watched          map[string]struct{}
 | 
					
						
							| 
									
										
										
										
											2018-06-27 07:45:32 -07:00
										 |  |  | 	zones            []string
 | 
					
						
							|  |  |  | 	endpointNameMode bool
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-14 09:38:00 -04:00
										 |  |  | type dnsControlOpts struct {
 | 
					
						
							| 
									
										
										
										
											2018-02-16 11:05:52 -05:00
										 |  |  | 	initPodCache       bool
 | 
					
						
							|  |  |  | 	initEndpointsCache bool
 | 
					
						
							|  |  |  | 	resyncPeriod       time.Duration
 | 
					
						
							| 
									
										
										
										
											2018-05-23 14:57:59 +02:00
										 |  |  | 	ignoreEmptyService bool
 | 
					
						
							| 
									
										
										
										
											2017-08-22 21:52:18 +01:00
										 |  |  | 	// Label handling.
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 	labelSelector *meta.LabelSelector
 | 
					
						
							| 
									
										
										
										
											2018-01-24 23:44:18 +03:00
										 |  |  | 	selector      labels.Selector
 | 
					
						
							| 
									
										
										
										
											2018-06-27 07:45:32 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	zones            []string
 | 
					
						
							|  |  |  | 	endpointNameMode bool
 | 
					
						
							| 
									
										
										
										
											2017-06-14 09:38:00 -04:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-12 12:46:35 +01:00
										 |  |  | // newDNSController creates a controller for CoreDNS.
 | 
					
						
							| 
									
										
										
										
											2018-09-29 10:43:09 -05:00
										 |  |  | func newdnsController(kubeClient kubernetes.Interface, opts dnsControlOpts) *dnsControl {
 | 
					
						
							| 
									
										
										
										
											2017-05-22 16:05:48 -04:00
										 |  |  | 	dns := dnsControl{
 | 
					
						
							| 
									
										
										
										
											2018-06-27 07:45:32 -07:00
										 |  |  | 		client:           kubeClient,
 | 
					
						
							|  |  |  | 		selector:         opts.selector,
 | 
					
						
							|  |  |  | 		stopCh:           make(chan struct{}),
 | 
					
						
							| 
									
										
										
										
											2018-09-22 18:13:33 +01:00
										 |  |  | 		watched:          make(map[string]struct{}),
 | 
					
						
							| 
									
										
										
										
											2018-06-27 07:45:32 -07:00
										 |  |  | 		zones:            opts.zones,
 | 
					
						
							|  |  |  | 		endpointNameMode: opts.endpointNameMode,
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2018-02-15 14:21:54 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 	dns.svcLister, dns.svcController = object.NewIndexerInformer(
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | 		&cache.ListWatch{
 | 
					
						
							| 
									
										
										
										
											2018-09-22 16:08:21 +01:00
										 |  |  | 			ListFunc:  serviceListFunc(dns.client, api.NamespaceAll, dns.selector),
 | 
					
						
							|  |  |  | 			WatchFunc: serviceWatchFunc(dns.client, api.NamespaceAll, dns.selector),
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | 		},
 | 
					
						
							| 
									
										
										
										
											2018-10-17 19:35:00 +01:00
										 |  |  | 		&api.Service{},
 | 
					
						
							| 
									
										
										
										
											2017-08-22 21:52:18 +01:00
										 |  |  | 		opts.resyncPeriod,
 | 
					
						
							| 
									
										
										
										
											2018-02-08 10:11:04 -06:00
										 |  |  | 		cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete},
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | 		cache.Indexers{svcNameNamespaceIndex: svcNameNamespaceIndexFunc, svcIPIndex: svcIPIndexFunc},
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 		object.ToService,
 | 
					
						
							|  |  |  | 	)
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-14 09:38:00 -04:00
										 |  |  | 	if opts.initPodCache {
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 		dns.podLister, dns.podController = object.NewIndexerInformer(
 | 
					
						
							| 
									
										
										
										
											2017-01-20 02:22:11 -05:00
										 |  |  | 			&cache.ListWatch{
 | 
					
						
							| 
									
										
										
										
											2018-09-22 16:08:21 +01:00
										 |  |  | 				ListFunc:  podListFunc(dns.client, api.NamespaceAll, dns.selector),
 | 
					
						
							|  |  |  | 				WatchFunc: podWatchFunc(dns.client, api.NamespaceAll, dns.selector),
 | 
					
						
							| 
									
										
										
										
											2017-01-20 02:22:11 -05:00
										 |  |  | 			},
 | 
					
						
							| 
									
										
										
										
											2018-10-17 19:35:00 +01:00
										 |  |  | 			&api.Pod{},
 | 
					
						
							| 
									
										
										
										
											2017-08-22 21:52:18 +01:00
										 |  |  | 			opts.resyncPeriod,
 | 
					
						
							| 
									
										
										
										
											2018-02-08 10:11:04 -06:00
										 |  |  | 			cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete},
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 			cache.Indexers{podIPIndex: podIPIndexFunc},
 | 
					
						
							|  |  |  | 			object.ToPod,
 | 
					
						
							|  |  |  | 		)
 | 
					
						
							| 
									
										
										
										
											2017-01-20 02:22:11 -05:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2018-02-15 14:21:54 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-16 11:05:52 -05:00
										 |  |  | 	if opts.initEndpointsCache {
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 		dns.epLister, dns.epController = object.NewIndexerInformer(
 | 
					
						
							| 
									
										
										
										
											2018-02-16 11:05:52 -05:00
										 |  |  | 			&cache.ListWatch{
 | 
					
						
							| 
									
										
										
										
											2018-09-22 16:08:21 +01:00
										 |  |  | 				ListFunc:  endpointsListFunc(dns.client, api.NamespaceAll, dns.selector),
 | 
					
						
							|  |  |  | 				WatchFunc: endpointsWatchFunc(dns.client, api.NamespaceAll, dns.selector),
 | 
					
						
							| 
									
										
										
										
											2018-02-16 11:05:52 -05:00
										 |  |  | 			},
 | 
					
						
							|  |  |  | 			&api.Endpoints{},
 | 
					
						
							|  |  |  | 			opts.resyncPeriod,
 | 
					
						
							|  |  |  | 			cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete},
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | 			cache.Indexers{epNameNamespaceIndex: epNameNamespaceIndexFunc, epIPIndex: epIPIndexFunc},
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 			object.ToEndpoints)
 | 
					
						
							| 
									
										
										
										
											2018-02-16 11:05:52 -05:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2016-12-02 17:50:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-22 15:12:02 +01:00
										 |  |  | 	dns.nsLister, dns.nsController = cache.NewInformer(
 | 
					
						
							| 
									
										
										
										
											2018-02-15 14:21:54 -05:00
										 |  |  | 		&cache.ListWatch{
 | 
					
						
							|  |  |  | 			ListFunc:  namespaceListFunc(dns.client, dns.selector),
 | 
					
						
							|  |  |  | 			WatchFunc: namespaceWatchFunc(dns.client, dns.selector),
 | 
					
						
							|  |  |  | 		},
 | 
					
						
							|  |  |  | 		&api.Namespace{}, opts.resyncPeriod, cache.ResourceEventHandlerFuncs{})
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | 	return &dns
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-20 02:22:11 -05:00
										 |  |  | func podIPIndexFunc(obj interface{}) ([]string, error) {
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 	p, ok := obj.(*object.Pod)
 | 
					
						
							| 
									
										
										
										
											2017-01-20 02:22:11 -05:00
										 |  |  | 	if !ok {
 | 
					
						
							| 
									
										
										
										
											2018-09-22 16:54:06 +01:00
										 |  |  | 		return nil, errObj
 | 
					
						
							| 
									
										
										
										
											2017-01-20 02:22:11 -05:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 	return []string{p.PodIP}, nil
 | 
					
						
							| 
									
										
										
										
											2017-01-20 02:22:11 -05:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | func svcIPIndexFunc(obj interface{}) ([]string, error) {
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 	svc, ok := obj.(*object.Service)
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 	if !ok {
 | 
					
						
							| 
									
										
										
										
											2018-09-22 16:54:06 +01:00
										 |  |  | 		return nil, errObj
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 	return []string{svc.ClusterIP}, nil
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | func svcNameNamespaceIndexFunc(obj interface{}) ([]string, error) {
 | 
					
						
							|  |  |  | 	s, ok := obj.(*object.Service)
 | 
					
						
							|  |  |  | 	if !ok {
 | 
					
						
							|  |  |  | 		return nil, errObj
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	return []string{s.Index}, nil
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func epNameNamespaceIndexFunc(obj interface{}) ([]string, error) {
 | 
					
						
							|  |  |  | 	s, ok := obj.(*object.Endpoints)
 | 
					
						
							|  |  |  | 	if !ok {
 | 
					
						
							|  |  |  | 		return nil, errObj
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	return []string{s.Index}, nil
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | func epIPIndexFunc(obj interface{}) ([]string, error) {
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 	ep, ok := obj.(*object.Endpoints)
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 	if !ok {
 | 
					
						
							| 
									
										
										
										
											2018-09-22 16:54:06 +01:00
										 |  |  | 		return nil, errObj
 | 
					
						
							| 
									
										
										
										
											2017-11-10 15:38:45 -05:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 	return ep.IndexIP, nil
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 10:43:09 -05:00
										 |  |  | func serviceListFunc(c kubernetes.Interface, ns string, s labels.Selector) func(meta.ListOptions) (runtime.Object, error) {
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 	return func(opts meta.ListOptions) (runtime.Object, error) {
 | 
					
						
							| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | 		if s != nil {
 | 
					
						
							| 
									
										
										
										
											2018-01-24 23:44:18 +03:00
										 |  |  | 			opts.LabelSelector = s.String()
 | 
					
						
							| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2018-01-03 19:11:28 +08:00
										 |  |  | 		listV1, err := c.CoreV1().Services(ns).List(opts)
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 		return listV1, err
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 10:43:09 -05:00
										 |  |  | func podListFunc(c kubernetes.Interface, ns string, s labels.Selector) func(meta.ListOptions) (runtime.Object, error) {
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 	return func(opts meta.ListOptions) (runtime.Object, error) {
 | 
					
						
							| 
									
										
										
										
											2017-01-20 02:22:11 -05:00
										 |  |  | 		if s != nil {
 | 
					
						
							| 
									
										
										
										
											2018-01-24 23:44:18 +03:00
										 |  |  | 			opts.LabelSelector = s.String()
 | 
					
						
							| 
									
										
										
										
											2017-01-20 02:22:11 -05:00
										 |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2018-01-03 19:11:28 +08:00
										 |  |  | 		listV1, err := c.CoreV1().Pods(ns).List(opts)
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 		return listV1, err
 | 
					
						
							| 
									
										
										
										
											2017-01-20 02:22:11 -05:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 10:43:09 -05:00
										 |  |  | func serviceWatchFunc(c kubernetes.Interface, ns string, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) {
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 	return func(options meta.ListOptions) (watch.Interface, error) {
 | 
					
						
							| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | 		if s != nil {
 | 
					
						
							| 
									
										
										
										
											2018-01-24 23:44:18 +03:00
										 |  |  | 			options.LabelSelector = s.String()
 | 
					
						
							| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2018-01-03 19:11:28 +08:00
										 |  |  | 		w, err := c.CoreV1().Services(ns).Watch(options)
 | 
					
						
							| 
									
										
										
										
											2018-09-22 16:54:06 +01:00
										 |  |  | 		return w, err
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 10:43:09 -05:00
										 |  |  | func podWatchFunc(c kubernetes.Interface, ns string, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) {
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 	return func(options meta.ListOptions) (watch.Interface, error) {
 | 
					
						
							| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | 		if s != nil {
 | 
					
						
							| 
									
										
										
										
											2018-01-24 23:44:18 +03:00
										 |  |  | 			options.LabelSelector = s.String()
 | 
					
						
							| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2018-01-03 19:11:28 +08:00
										 |  |  | 		w, err := c.CoreV1().Pods(ns).Watch(options)
 | 
					
						
							| 
									
										
										
										
											2018-09-22 16:54:06 +01:00
										 |  |  | 		return w, err
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 10:43:09 -05:00
										 |  |  | func endpointsListFunc(c kubernetes.Interface, ns string, s labels.Selector) func(meta.ListOptions) (runtime.Object, error) {
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 	return func(opts meta.ListOptions) (runtime.Object, error) {
 | 
					
						
							| 
									
										
										
										
											2016-12-02 17:50:01 -05:00
										 |  |  | 		if s != nil {
 | 
					
						
							| 
									
										
										
										
											2018-01-24 23:44:18 +03:00
										 |  |  | 			opts.LabelSelector = s.String()
 | 
					
						
							| 
									
										
										
										
											2016-12-02 17:50:01 -05:00
										 |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2018-01-03 19:11:28 +08:00
										 |  |  | 		listV1, err := c.CoreV1().Endpoints(ns).List(opts)
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 		return listV1, err
 | 
					
						
							| 
									
										
										
										
											2016-12-02 17:50:01 -05:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 10:43:09 -05:00
										 |  |  | func endpointsWatchFunc(c kubernetes.Interface, ns string, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) {
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 	return func(options meta.ListOptions) (watch.Interface, error) {
 | 
					
						
							| 
									
										
										
										
											2016-12-02 17:50:01 -05:00
										 |  |  | 		if s != nil {
 | 
					
						
							| 
									
										
										
										
											2018-01-24 23:44:18 +03:00
										 |  |  | 			options.LabelSelector = s.String()
 | 
					
						
							| 
									
										
										
										
											2016-12-02 17:50:01 -05:00
										 |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2018-01-03 19:11:28 +08:00
										 |  |  | 		w, err := c.CoreV1().Endpoints(ns).Watch(options)
 | 
					
						
							| 
									
										
										
										
											2018-09-22 16:54:06 +01:00
										 |  |  | 		return w, err
 | 
					
						
							| 
									
										
										
										
											2016-12-02 17:50:01 -05:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 10:43:09 -05:00
										 |  |  | func namespaceListFunc(c kubernetes.Interface, s labels.Selector) func(meta.ListOptions) (runtime.Object, error) {
 | 
					
						
							| 
									
										
										
										
											2018-02-15 14:21:54 -05:00
										 |  |  | 	return func(opts meta.ListOptions) (runtime.Object, error) {
 | 
					
						
							|  |  |  | 		if s != nil {
 | 
					
						
							|  |  |  | 			opts.LabelSelector = s.String()
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 		listV1, err := c.CoreV1().Namespaces().List(opts)
 | 
					
						
							|  |  |  | 		return listV1, err
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 10:43:09 -05:00
										 |  |  | func namespaceWatchFunc(c kubernetes.Interface, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) {
 | 
					
						
							| 
									
										
										
										
											2018-02-15 14:21:54 -05:00
										 |  |  | 	return func(options meta.ListOptions) (watch.Interface, error) {
 | 
					
						
							|  |  |  | 		if s != nil {
 | 
					
						
							|  |  |  | 			options.LabelSelector = s.String()
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 		w, err := c.CoreV1().Namespaces().Watch(options)
 | 
					
						
							| 
									
										
										
										
											2018-09-22 16:54:06 +01:00
										 |  |  | 		return w, err
 | 
					
						
							| 
									
										
										
										
											2018-02-15 14:21:54 -05:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-22 15:12:02 +01:00
										 |  |  | func (dns *dnsControl) SetWatchChan(c dnswatch.Chan) { dns.watchChan = c }
 | 
					
						
							|  |  |  | func (dns *dnsControl) StopWatching(qname string)    { delete(dns.watched, qname) }
 | 
					
						
							| 
									
										
										
										
											2018-06-27 07:45:32 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (dns *dnsControl) Watch(qname string) error {
 | 
					
						
							|  |  |  | 	if dns.watchChan == nil {
 | 
					
						
							|  |  |  | 		return fmt.Errorf("cannot start watch because the channel has not been set")
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2018-09-22 18:13:33 +01:00
										 |  |  | 	dns.watched[qname] = struct{}{}
 | 
					
						
							| 
									
										
										
										
											2018-06-27 07:45:32 -07:00
										 |  |  | 	return nil
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | // Stop stops the  controller.
 | 
					
						
							| 
									
										
										
										
											2017-05-22 16:05:48 -04:00
										 |  |  | func (dns *dnsControl) Stop() error {
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | 	dns.stopLock.Lock()
 | 
					
						
							|  |  |  | 	defer dns.stopLock.Unlock()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Only try draining the workqueue if we haven't already.
 | 
					
						
							|  |  |  | 	if !dns.shutdown {
 | 
					
						
							|  |  |  | 		close(dns.stopCh)
 | 
					
						
							|  |  |  | 		dns.shutdown = true
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return nil
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return fmt.Errorf("shutdown already in progress")
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Run starts the controller.
 | 
					
						
							| 
									
										
										
										
											2017-05-22 16:05:48 -04:00
										 |  |  | func (dns *dnsControl) Run() {
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | 	go dns.svcController.Run(dns.stopCh)
 | 
					
						
							| 
									
										
										
										
											2018-02-16 11:05:52 -05:00
										 |  |  | 	if dns.epController != nil {
 | 
					
						
							|  |  |  | 		go dns.epController.Run(dns.stopCh)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2017-01-20 02:22:11 -05:00
										 |  |  | 	if dns.podController != nil {
 | 
					
						
							|  |  |  | 		go dns.podController.Run(dns.stopCh)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2018-02-15 14:21:54 -05:00
										 |  |  | 	go dns.nsController.Run(dns.stopCh)
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | 	<-dns.stopCh
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-20 22:53:17 +01:00
										 |  |  | // HasSynced calls on all controllers.
 | 
					
						
							|  |  |  | func (dns *dnsControl) HasSynced() bool {
 | 
					
						
							|  |  |  | 	a := dns.svcController.HasSynced()
 | 
					
						
							| 
									
										
										
										
											2018-02-16 11:05:52 -05:00
										 |  |  | 	b := true
 | 
					
						
							|  |  |  | 	if dns.epController != nil {
 | 
					
						
							|  |  |  | 		b = dns.epController.HasSynced()
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2017-10-20 22:53:17 +01:00
										 |  |  | 	c := true
 | 
					
						
							|  |  |  | 	if dns.podController != nil {
 | 
					
						
							|  |  |  | 		c = dns.podController.HasSynced()
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2018-02-15 14:21:54 -05:00
										 |  |  | 	d := dns.nsController.HasSynced()
 | 
					
						
							|  |  |  | 	return a && b && c && d
 | 
					
						
							| 
									
										
										
										
											2017-10-20 22:53:17 +01:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | func (dns *dnsControl) ServiceList() (svcs []*object.Service) {
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 	os := dns.svcLister.List()
 | 
					
						
							|  |  |  | 	for _, o := range os {
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 		s, ok := o.(*object.Service)
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 		if !ok {
 | 
					
						
							|  |  |  | 			continue
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 		svcs = append(svcs, s)
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2016-09-23 10:13:02 -03:00
										 |  |  | 	return svcs
 | 
					
						
							| 
									
										
										
										
											2016-08-05 18:19:51 -07:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | func (dns *dnsControl) EndpointsList() (eps []*object.Endpoints) {
 | 
					
						
							|  |  |  | 	os := dns.epLister.List()
 | 
					
						
							|  |  |  | 	for _, o := range os {
 | 
					
						
							|  |  |  | 		ep, ok := o.(*object.Endpoints)
 | 
					
						
							|  |  |  | 		if !ok {
 | 
					
						
							|  |  |  | 			continue
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 		eps = append(eps, ep)
 | 
					
						
							| 
									
										
										
										
											2017-09-21 13:06:35 -04:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 	return eps
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (dns *dnsControl) PodIndex(ip string) (pods []*object.Pod) {
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 	os, err := dns.podLister.ByIndex(podIPIndex, ip)
 | 
					
						
							| 
									
										
										
										
											2017-05-22 16:05:48 -04:00
										 |  |  | 	if err != nil {
 | 
					
						
							|  |  |  | 		return nil
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 	for _, o := range os {
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 		p, ok := o.(*object.Pod)
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 		if !ok {
 | 
					
						
							|  |  |  | 			continue
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | 		pods = append(pods, p)
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | 	return pods
 | 
					
						
							| 
									
										
										
										
											2017-05-22 16:05:48 -04:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | func (dns *dnsControl) SvcIndex(idx string) (svcs []*object.Service) {
 | 
					
						
							|  |  |  | 	os, err := dns.svcLister.ByIndex(svcNameNamespaceIndex, idx)
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 	if err != nil {
 | 
					
						
							|  |  |  | 		return nil
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | 	for _, o := range os {
 | 
					
						
							|  |  |  | 		s, ok := o.(*object.Service)
 | 
					
						
							|  |  |  | 		if !ok {
 | 
					
						
							|  |  |  | 			continue
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 		svcs = append(svcs, s)
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | 	return svcs
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | func (dns *dnsControl) SvcIndexReverse(ip string) (svcs []*object.Service) {
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 	os, err := dns.svcLister.ByIndex(svcIPIndex, ip)
 | 
					
						
							|  |  |  | 	if err != nil {
 | 
					
						
							|  |  |  | 		return nil
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for _, o := range os {
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 		s, ok := o.(*object.Service)
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 		if !ok {
 | 
					
						
							|  |  |  | 			continue
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | 		svcs = append(svcs, s)
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | 	return svcs
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | func (dns *dnsControl) EpIndex(idx string) (ep []*object.Endpoints) {
 | 
					
						
							|  |  |  | 	os, err := dns.epLister.ByIndex(epNameNamespaceIndex, idx)
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 	if err != nil {
 | 
					
						
							|  |  |  | 		return nil
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | 	for _, o := range os {
 | 
					
						
							|  |  |  | 		e, ok := o.(*object.Endpoints)
 | 
					
						
							|  |  |  | 		if !ok {
 | 
					
						
							|  |  |  | 			continue
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 		ep = append(ep, e)
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | 	return ep
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | func (dns *dnsControl) EpIndexReverse(ip string) (ep []*object.Endpoints) {
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 	os, err := dns.epLister.ByIndex(epIPIndex, ip)
 | 
					
						
							|  |  |  | 	if err != nil {
 | 
					
						
							|  |  |  | 		return nil
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	for _, o := range os {
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | 		e, ok := o.(*object.Endpoints)
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 		if !ok {
 | 
					
						
							|  |  |  | 			continue
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | 		ep = append(ep, e)
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | 	return ep
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 21:51:51 +00:00
										 |  |  | // GetNodeByName return the node by name. If nothing is found an error is
 | 
					
						
							|  |  |  | // returned. This query causes a roundtrip to the k8s API server, so use
 | 
					
						
							|  |  |  | // sparingly. Currently this is only used for Federation.
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | func (dns *dnsControl) GetNodeByName(name string) (*api.Node, error) {
 | 
					
						
							| 
									
										
										
										
											2018-01-03 19:11:28 +08:00
										 |  |  | 	v1node, err := dns.client.CoreV1().Nodes().Get(name, meta.GetOptions{})
 | 
					
						
							| 
									
										
										
										
											2018-09-22 16:54:06 +01:00
										 |  |  | 	return v1node, err
 | 
					
						
							| 
									
										
										
										
											2017-06-14 09:38:00 -04:00
										 |  |  | }
 | 
					
						
							| 
									
										
										
										
											2017-11-13 21:51:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-09 21:56:09 +01:00
										 |  |  | // GetNamespaceByName returns the namespace by name. If nothing is found an error is returned.
 | 
					
						
							| 
									
										
										
										
											2017-11-13 21:51:51 +00:00
										 |  |  | func (dns *dnsControl) GetNamespaceByName(name string) (*api.Namespace, error) {
 | 
					
						
							| 
									
										
										
										
											2018-02-15 14:21:54 -05:00
										 |  |  | 	os := dns.nsLister.List()
 | 
					
						
							|  |  |  | 	for _, o := range os {
 | 
					
						
							|  |  |  | 		ns, ok := o.(*api.Namespace)
 | 
					
						
							|  |  |  | 		if !ok {
 | 
					
						
							|  |  |  | 			continue
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:59:50 +01:00
										 |  |  | 		if name == ns.ObjectMeta.Name {
 | 
					
						
							| 
									
										
										
										
											2018-02-15 14:21:54 -05:00
										 |  |  | 			return ns, nil
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2017-11-13 21:51:51 +00:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2018-02-15 14:21:54 -05:00
										 |  |  | 	return nil, fmt.Errorf("namespace not found")
 | 
					
						
							| 
									
										
										
										
											2017-11-13 21:51:51 +00:00
										 |  |  | }
 | 
					
						
							| 
									
										
										
										
											2018-02-08 10:11:04 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (dns *dnsControl) Modified() int64 {
 | 
					
						
							|  |  |  | 	unix := atomic.LoadInt64(&dns.modified)
 | 
					
						
							|  |  |  | 	return unix
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // updateModified set dns.modified to the current time.
 | 
					
						
							|  |  |  | func (dns *dnsControl) updateModifed() {
 | 
					
						
							|  |  |  | 	unix := time.Now().Unix()
 | 
					
						
							|  |  |  | 	atomic.StoreInt64(&dns.modified, unix)
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-22 16:54:06 +01:00
										 |  |  | var errObj = errors.New("obj was not of the correct type")
 |