2016-06-06 12:49:53 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// Package kubernetes provides the kubernetes backend.  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								package  kubernetes  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  (  
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:40:58 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"errors" 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-30 15:54:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"fmt" 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-18 10:47:36 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"log" 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 09:48:11 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"strings" 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 12:49:53 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"time" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"github.com/miekg/coredns/middleware" 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 09:14:12 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/miekg/coredns/middleware/etcd/msg" 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-07 11:10:16 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/miekg/coredns/middleware/pkg/dnsutil" 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-30 15:54:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									dnsstrings  "github.com/miekg/coredns/middleware/pkg/strings" 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 12:49:53 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"github.com/miekg/coredns/middleware/proxy" 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-30 15:54:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/miekg/coredns/request" 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 12:49:53 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:40:58 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/miekg/dns" 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-05 15:43:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"k8s.io/client-go/1.5/kubernetes" 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-05 07:57:08 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"k8s.io/client-go/1.5/pkg/api" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									unversionedapi  "k8s.io/client-go/1.5/pkg/api/unversioned" 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-05 15:43:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"k8s.io/client-go/1.5/pkg/labels" 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-05 07:57:08 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"k8s.io/client-go/1.5/rest" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"k8s.io/client-go/1.5/tools/clientcmd" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									clientcmdapi  "k8s.io/client-go/1.5/tools/clientcmd/api" 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-05 18:19:51 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 09:14:12 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Kubernetes implements a middleware that connects to a Kubernetes cluster.  
						 
					
						
							
								
									
										
										
										
											2016-06-06 12:49:53 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								type  Kubernetes  struct  {  
						 
					
						
							
								
									
										
										
										
											2016-08-12 20:44:08 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Next           middleware . Handler 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Zones          [ ] string 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-14 19:31:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									primaryZone    int 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-12 20:44:08 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Proxy          proxy . Proxy  // Proxy for looking up names during the resolution process 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									APIEndpoint    string 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 18:07:06 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									APICertAuth    string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									APIClientCert  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									APIClientKey   string 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-12 20:44:08 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									APIConn        * dnsController 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ResyncPeriod   time . Duration 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Namespaces     [ ] string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									LabelSelector  * unversionedapi . LabelSelector 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-19 17:14:17 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Selector       * labels . Selector 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-11 16:23:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									PodMode        string 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 12:49:53 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-11 16:23:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  (  
						 
					
						
							
								
									
										
										
										
											2017-01-15 14:37:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									PodModeDisabled   =  "disabled"  // default. pod requests are ignored 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									PodModeInsecure   =  "insecure"  // ALL pod requests are answered without verfying they exist 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									DnsSchemaVersion  =  "1.0.0"     // https://github.com/kubernetes/dns/blob/master/docs/specification.md 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-11 16:23:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								type  endpoint  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									addr  api . EndpointAddress 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									port  api . EndpointPort 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  service  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									name       string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									namespace  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									addr       string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ports      [ ] api . ServicePort 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									endpoints  [ ] endpoint 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-11 16:23:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								type  pod  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									name       string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									namespace  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									addr       string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								type  recordRequest  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									port ,  protocol ,  endpoint ,  service ,  namespace ,  typeName ,  zone  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-11-11 16:56:15 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var  errNoItems  =  errors . New ( "no items found" )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								var  errNsNotExposed  =  errors . New ( "namespace is not exposed" )  
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var  errInvalidRequest  =  errors . New ( "invalid query name" )  
						 
					
						
							
								
									
										
										
										
											2016-11-10 16:24:06 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-10-30 15:54:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Services implements the ServiceBackend interface.  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( k  * Kubernetes )  Services ( state  request . Request ,  exact  bool ,  opt  middleware . Options )  ( [ ] msg . Service ,  [ ] msg . Service ,  error )  {  
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									r ,  e  :=  k . parseRequest ( state . Name ( ) ,  state . Type ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  e  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  nil ,  nil ,  e 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 14:37:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									switch  state . Type ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									case  "A" ,  "SRV" : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										s ,  e  :=  k . Records ( r ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  s ,  nil ,  e  // Haven't implemented debug queries yet. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									case  "TXT" : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										s ,  e  :=  k . recordsForTXT ( r ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  s ,  nil ,  e 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  nil ,  nil ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( k  * Kubernetes )  recordsForTXT ( r  recordRequest )  ( [ ] msg . Service ,  error )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									switch  r . typeName  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									case  "dns-version" : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										s  :=  msg . Service { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Text :  DnsSchemaVersion , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											TTL :   28800 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Key :   msg . Path ( r . typeName + "." + r . zone ,  "coredns" ) } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  [ ] msg . Service { s } ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  nil ,  nil 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-30 15:54:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-11-14 19:31:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// PrimaryZone will return the first non-reverse zone being handled by this middleware  
						 
					
						
							
								
									
										
										
										
											2016-12-02 17:50:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( k  * Kubernetes )  PrimaryZone ( )  string  {  
						 
					
						
							
								
									
										
										
										
											2016-11-14 19:31:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  k . Zones [ k . primaryZone ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-11-05 15:43:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Reverse implements the ServiceBackend interface.  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( k  * Kubernetes )  Reverse ( state  request . Request ,  exact  bool ,  opt  middleware . Options )  ( [ ] msg . Service ,  [ ] msg . Service ,  error )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ip  :=  dnsutil . ExtractAddressFromReverse ( state . Name ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ip  ==  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  nil ,  nil ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									records  :=  k . getServiceRecordForIP ( ip ,  state . Name ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  records ,  nil ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-10-30 15:54:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Lookup implements the ServiceBackend interface.  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( k  * Kubernetes )  Lookup ( state  request . Request ,  name  string ,  typ  uint16 )  ( * dns . Msg ,  error )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  k . Proxy . Lookup ( state ,  name ,  typ ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// IsNameError implements the ServiceBackend interface.  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( k  * Kubernetes )  IsNameError ( err  error )  bool  {  
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  err  ==  errNoItems  ||  err  ==  errNsNotExposed  ||  err  ==  errInvalidRequest 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-30 15:54:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Debug implements the ServiceBackend interface.  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( k  * Kubernetes )  Debug ( )  string  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  "debug" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-11-05 07:57:08 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( k  * Kubernetes )  getClientConfig ( )  ( * rest . Config ,  error )  {  
						 
					
						
							
								
									
										
										
										
											2016-08-05 18:19:51 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// For a custom api server or running outside a k8s cluster 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-08 14:30:04 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// set URL in env.KUBERNETES_MASTER or set endpoint in Corefile 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-05 18:19:51 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									loadingRules  :=  clientcmd . NewDefaultClientConfigLoadingRules ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									overrides  :=  & clientcmd . ConfigOverrides { } 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 18:07:06 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									clusterinfo  :=  clientcmdapi . Cluster { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									authinfo  :=  clientcmdapi . AuthInfo { } 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-22 23:15:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  len ( k . APIEndpoint )  >  0  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 18:07:06 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										clusterinfo . Server  =  k . APIEndpoint 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-19 17:04:35 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-05 07:57:08 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										cc ,  err  :=  rest . InClusterConfig ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-19 17:04:35 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  nil ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  cc ,  err 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 18:07:06 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  len ( k . APICertAuth )  >  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										clusterinfo . CertificateAuthority  =  k . APICertAuth 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-05 18:19:51 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 18:07:06 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  len ( k . APIClientCert )  >  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										authinfo . ClientCertificate  =  k . APIClientCert 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  len ( k . APIClientKey )  >  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										authinfo . ClientKey  =  k . APIClientKey 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									overrides . ClusterInfo  =  clusterinfo 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									overrides . AuthInfo  =  authinfo 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-05 18:19:51 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									clientConfig  :=  clientcmd . NewNonInteractiveDeferredLoadingClientConfig ( loadingRules ,  overrides ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 18:07:06 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  clientConfig . ClientConfig ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// InitKubeCache initializes a new Kubernetes cache.  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( k  * Kubernetes )  InitKubeCache ( )  error  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									config ,  err  :=  k . getClientConfig ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-05 18:19:51 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-11-05 07:57:08 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									kubeClient ,  err  :=  kubernetes . NewForConfig ( config ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-05 18:19:51 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-30 15:54:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  fmt . Errorf ( "Failed to create kubernetes notification controller: %v" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-05 18:19:51 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-30 15:54:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  k . LabelSelector  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-19 17:14:17 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										var  selector  labels . Selector 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-22 23:15:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										selector ,  err  =  unversionedapi . LabelSelectorAsSelector ( k . LabelSelector ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										k . Selector  =  & selector 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-19 17:14:17 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-30 15:54:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  fmt . Errorf ( "Unable to create Selector for LabelSelector '%s'.Error was: %s" ,  k . LabelSelector ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-19 17:14:17 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-30 15:54:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  k . LabelSelector  ==  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										log . Printf ( "[INFO] Kubernetes middleware configured without a label selector. No label-based filtering will be performed." ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-22 23:15:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										log . Printf ( "[INFO] Kubernetes middleware configured with the label selector '%s'. Only kubernetes objects matching this label selector will be exposed." ,  unversionedapi . FormatLabelSelector ( k . LabelSelector ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-12 20:44:08 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-30 15:54:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-22 23:15:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									k . APIConn  =  newdnsController ( kubeClient ,  k . ResyncPeriod ,  k . Selector ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-05 18:19:51 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( k  * Kubernetes )  parseRequest ( lowerCasedName ,  qtype  string )  ( r  recordRequest ,  err  error )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// 3 Possible cases 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									//   SRV Request: _port._protocol.service.namespace.type.zone 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									//   A Request (endpoint): endpoint.service.namespace.type.zone 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									//   A Request (service): service.namespace.type.zone 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 12:49:53 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// separate zone from rest of lowerCasedName 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  segs  [ ] string 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-22 23:15:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  z  :=  range  k . Zones  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  dns . IsSubDomain ( z ,  lowerCasedName )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											r . zone  =  z 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:40:58 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											segs  =  dns . SplitDomainName ( lowerCasedName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											segs  =  segs [ : len ( segs ) - dns . CountLabel ( r . zone ) ] 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:40:58 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											break 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  r . zone  ==  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  r ,  errors . New ( "zone not found" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:40:58 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									offset  :=  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  len ( segs )  ==  5  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// This is a SRV style request, get first two elements as port and 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// protocol, stripping leading underscores if present. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  segs [ 0 ] [ 0 ]  ==  '_'  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											r . port  =  segs [ 0 ] [ 1 : ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											r . port  =  segs [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ! symbolContainsWildcard ( r . port )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  r ,  errors . New ( "srv port must start with an underscore or be a wildcard" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  segs [ 1 ] [ 0 ]  ==  '_'  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											r . protocol  =  segs [ 1 ] [ 1 : ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  r . protocol  !=  "tcp"  &&  r . protocol  !=  "udp"  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  r ,  errors . New ( "invalid srv protocol: "  +  r . protocol ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											r . protocol  =  segs [ 1 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ! symbolContainsWildcard ( r . protocol )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  r ,  errors . New ( "srv protocol must start with an underscore or be a wildcard" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										offset  =  2 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  if  len ( segs )  ==  4  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// This is an endpoint A style request. Get first element as endpoint. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										r . endpoint  =  segs [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										offset  =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 12:49:53 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// SRV requests require a port and protocol 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  qtype  ==  "SRV"  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  r . port  ==  ""  ||  r . protocol  ==  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  r ,  errors . New ( "invalid srv request" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// A requests cannot have port/protocol 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  qtype  ==  "A"  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  r . port  !=  ""  &&  r . protocol  !=  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  r ,  errors . New ( "invalid a request" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  len ( segs )  ==  ( offset  +  3 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										r . service  =  segs [ offset ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										r . namespace  =  segs [ offset + 1 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										r . typeName  =  segs [ offset + 2 ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  r ,  nil 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 14:37:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  len ( segs )  ==  1  &&  qtype  ==  "TXT"  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										r . typeName  =  segs [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  r ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  r ,  errors . New ( "invalid request" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-10-30 15:54:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Records looks up services in kubernetes. If exact is true, it will lookup  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// just this name. This is used when find matches when completing SRV lookups  
						 
					
						
							
								
									
										
										
										
											2016-06-06 12:49:53 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// for instance.  
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( k  * Kubernetes )  Records ( r  recordRequest )  ( [ ] msg . Service ,  error )  {  
						 
					
						
							
								
									
										
										
										
											2016-07-14 14:50:14 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Abort if the namespace does not contain a wildcard, and namespace is not published per CoreFile 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Case where namespace contains a wildcard is handled in Get(...) method. 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! symbolContainsWildcard ( r . namespace ) )  &&  ( len ( k . Namespaces )  >  0 )  &&  ( ! dnsstrings . StringInSlice ( r . namespace ,  k . Namespaces ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-11 16:56:15 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  nil ,  errNsNotExposed 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:40:58 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 12:49:53 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									services ,  pods ,  err  :=  k . Get ( r ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:40:58 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  nil ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-11 16:23:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  len ( services )  ==  0  &&  len ( pods )  ==  0  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:40:58 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Did not find item in k8s 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-11 16:56:15 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  nil ,  errNoItems 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:40:58 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 12:49:53 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									records  :=  k . getRecordsForK8sItems ( services ,  pods ,  r . zone ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:40:58 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  records ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2016-06-06 12:49:53 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  endpointHostname ( addr  api . EndpointAddress )  string  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  addr . Hostname  !=  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  strings . ToLower ( addr . Hostname ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  strings . Contains ( addr . IP ,  "." )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  strings . Replace ( addr . IP ,  "." ,  "-" ,  - 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  strings . Contains ( addr . IP ,  ":" )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  strings . ToLower ( strings . Replace ( addr . IP ,  ":" ,  "-" ,  - 1 ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  "" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-11 16:23:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( k  * Kubernetes )  getRecordsForK8sItems ( services  [ ] service ,  pods  [ ] pod ,  zone  string )  [ ] msg . Service  {  
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:40:58 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  records  [ ] msg . Service 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 12:49:53 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-11 16:23:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  svc  :=  range  services  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										key  :=  svc . name  +  "."  +  svc . namespace  +  ".svc."  +  zone 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  svc . addr  ==  api . ClusterIPNone  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// This is a headless service, create records for each endpoint 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											for  _ ,  ep  :=  range  svc . endpoints  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												ephostname  :=  endpointHostname ( ep . addr ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												s  :=  msg . Service { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													Key :   msg . Path ( strings . ToLower ( ephostname + "." + key ) ,  "coredns" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													Host :  ep . addr . IP ,  Port :  int ( ep . port . Port ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-02 17:50:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												records  =  append ( records ,  s ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-12-02 17:50:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// Create records for each exposed port... 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											for  _ ,  p  :=  range  svc . ports  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												s  :=  msg . Service { Key :  msg . Path ( strings . ToLower ( key ) ,  "coredns" ) ,  Host :  svc . addr ,  Port :  int ( p . Port ) } 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-02 17:50:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												records  =  append ( records ,  s ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:40:58 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 12:49:53 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-11 16:23:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  p  :=  range  pods  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										key  :=  p . name  +  "."  +  p . namespace  +  ".pod."  +  zone 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										s  :=  msg . Service { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Key :   msg . Path ( strings . ToLower ( key ) ,  "coredns" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Host :  p . addr , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										records  =  append ( records ,  s ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-07 01:40:58 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  records 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 12:49:53 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-11 16:23:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ipFromPodName ( podname  string )  string  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  strings . Count ( podname ,  "-" )  ==  3  &&  ! strings . Contains ( podname ,  "--" )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  strings . Replace ( podname ,  "-" ,  "." ,  - 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  strings . Replace ( podname ,  "-" ,  ":" ,  - 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( k  * Kubernetes )  findPods ( namespace ,  podname  string )  ( pods  [ ] pod ,  err  error )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  k . PodMode  ==  PodModeDisabled  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-12 11:57:00 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  pods ,  errors . New ( "pod records disabled" ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-11 16:23:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  ip  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  strings . Count ( podname ,  "-" )  ==  3  &&  ! strings . Contains ( podname ,  "--" )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ip  =  strings . Replace ( podname ,  "-" ,  "." ,  - 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ip  =  strings . Replace ( podname ,  "-" ,  ":" ,  - 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  k . PodMode  ==  PodModeInsecure  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										s  :=  pod { name :  podname ,  namespace :  namespace ,  addr :  ip } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										pods  =  append ( pods ,  s ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  pods ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// TODO: implement cache verified pod responses 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  pods ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Get retrieves matching data from the cache.  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( k  * Kubernetes )  Get ( r  recordRequest )  ( services  [ ] service ,  pods  [ ] pod ,  err  error )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									switch  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									case  r . typeName  ==  "pod" : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										pods ,  err  =  k . findPods ( r . namespace ,  r . service ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  nil ,  pods ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										services ,  err  =  k . findServices ( r ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  services ,  nil ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( k  * Kubernetes )  findServices ( r  recordRequest )  ( [ ] service ,  error )  {  
						 
					
						
							
								
									
										
										
										
											2016-10-12 12:46:35 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									serviceList  :=  k . APIConn . ServiceList ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 12:49:53 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  resultItems  [ ] service 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-14 14:50:14 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									nsWildcard  :=  symbolContainsWildcard ( r . namespace ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									serviceWildcard  :=  symbolContainsWildcard ( r . service ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									portWildcard  :=  symbolContainsWildcard ( r . port )  ||  r . port  ==  "" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									protocolWildcard  :=  symbolContainsWildcard ( r . protocol )  ||  r . protocol  ==  "" 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  svc  :=  range  serviceList  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ! ( symbolMatches ( r . namespace ,  svc . Namespace ,  nsWildcard )  &&  symbolMatches ( r . service ,  svc . Name ,  serviceWildcard ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// If namespace has a wildcard, filter results against Corefile namespace list. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// (Namespaces without a wildcard were filtered before the call to this function.) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  nsWildcard  &&  ( len ( k . Namespaces )  >  0 )  &&  ( ! dnsstrings . StringInSlice ( svc . Namespace ,  k . Namespaces ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										s  :=  service { name :  svc . Name ,  namespace :  svc . Namespace ,  addr :  svc . Spec . ClusterIP } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  s . addr  !=  api . ClusterIPNone  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											for  _ ,  p  :=  range  svc . Spec . Ports  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if  ! ( symbolMatches ( r . port ,  strings . ToLower ( p . Name ) ,  portWildcard )  &&  symbolMatches ( r . protocol ,  strings . ToLower ( string ( p . Protocol ) ) ,  protocolWildcard ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												s . ports  =  append ( s . ports ,  p ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											resultItems  =  append ( resultItems ,  s ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Headless service 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										endpointsList ,  err  :=  k . APIConn . epLister . List ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  _ ,  ep  :=  range  endpointsList . Items  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ep . ObjectMeta . Name  !=  svc . Name  ||  ep . ObjectMeta . Namespace  !=  svc . Namespace  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-14 14:50:14 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											for  _ ,  eps  :=  range  ep . Subsets  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												for  _ ,  addr  :=  range  eps . Addresses  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													for  _ ,  p  :=  range  eps . Ports  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														ephostname  :=  endpointHostname ( addr ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														if  r . endpoint  !=  ""  &&  r . endpoint  !=  ephostname  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														if  ! ( symbolMatches ( r . port ,  strings . ToLower ( p . Name ) ,  portWildcard )  &&  symbolMatches ( r . protocol ,  strings . ToLower ( string ( p . Protocol ) ) ,  protocolWildcard ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														s . endpoints  =  append ( s . endpoints ,  endpoint { addr :  addr ,  port :  p } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-14 14:50:14 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										resultItems  =  append ( resultItems ,  s ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-14 14:50:14 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  resultItems ,  nil 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 12:49:53 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  symbolMatches ( queryString ,  candidateString  string ,  wildcard  bool )  bool  {  
						 
					
						
							
								
									
										
										
										
											2017-01-15 03:12:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  wildcard  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  true 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  queryString  ==  candidateString 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-14 14:50:14 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// getServiceRecordForIP: Gets a service record with a cluster ip matching the ip argument  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// If a service cluster ip does not match, it checks all endpoints  
						 
					
						
							
								
									
										
										
										
											2016-08-22 23:15:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( k  * Kubernetes )  getServiceRecordForIP ( ip ,  name  string )  [ ] msg . Service  {  
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// First check services with cluster ips 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 10:13:02 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									svcList ,  err  :=  k . APIConn . svcLister . List ( labels . Everything ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-05 18:19:51 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  nil 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 12:49:53 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 10:13:02 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  service  :=  range  svcList  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ! dnsstrings . StringInSlice ( service . Namespace ,  k . Namespaces )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-05 18:19:51 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  service . Spec . ClusterIP  ==  ip  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 10:09:59 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											domain  :=  service . Name  +  "."  +  service . Namespace  +  ".svc."  +  k . PrimaryZone ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  [ ] msg . Service { msg . Service { Host :  domain } } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// If no cluster ips match, search endpoints 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									epList ,  err  :=  k . APIConn . epLister . List ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  ep  :=  range  epList . Items  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ! dnsstrings . StringInSlice ( ep . ObjectMeta . Namespace ,  k . Namespaces )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  _ ,  eps  :=  range  ep . Subsets  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											for  _ ,  addr  :=  range  eps . Addresses  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  addr . IP  ==  ip  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													domain  :=  endpointHostname ( addr )  +  "."  +  ep . ObjectMeta . Name  +  "."  +  ep . ObjectMeta . Namespace  +  ".svc."  +  k . PrimaryZone ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													return  [ ] msg . Service { msg . Service { Host :  domain } } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-05 18:19:51 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 12:49:53 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-05 18:19:51 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  nil 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-06 12:49:53 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 09:48:11 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// symbolContainsWildcard checks whether symbol contains a wildcard value  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  symbolContainsWildcard ( symbol  string )  bool  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  ( strings . Contains ( symbol ,  "*" )  ||  ( symbol  ==  "any" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}