mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-03 18:53:13 -05:00 
			
		
		
		
	* fix external ns records * use k8s service name for ns record * update test, add func comment * expand nsAddrs() test cases * support local ipv6 ip * use less confusing pod ip in test
		
			
				
	
	
		
			46 lines
		
	
	
		
			858 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			858 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package kubernetes
 | 
						|
 | 
						|
import (
 | 
						|
	"net"
 | 
						|
)
 | 
						|
 | 
						|
func localPodIP() net.IP {
 | 
						|
	addrs, err := net.InterfaceAddrs()
 | 
						|
	if err != nil {
 | 
						|
		return nil
 | 
						|
	}
 | 
						|
 | 
						|
	for _, addr := range addrs {
 | 
						|
		ip, _, _ := net.ParseCIDR(addr.String())
 | 
						|
		ip4 := ip.To4()
 | 
						|
		if ip4 != nil && !ip4.IsLoopback() {
 | 
						|
			return ip4
 | 
						|
		}
 | 
						|
		ip6 := ip.To16()
 | 
						|
		if ip6 != nil && !ip6.IsLoopback() {
 | 
						|
			return ip6
 | 
						|
		}
 | 
						|
	}
 | 
						|
	return nil
 | 
						|
}
 | 
						|
 | 
						|
// LocalNodeName is exclusively used in federation plugin, will be deprecated later.
 | 
						|
func (k *Kubernetes) LocalNodeName() string {
 | 
						|
	localIP := k.interfaceAddrsFunc()
 | 
						|
	if localIP == nil {
 | 
						|
		return ""
 | 
						|
	}
 | 
						|
 | 
						|
	// Find endpoint matching localIP
 | 
						|
	for _, ep := range k.APIConn.EpIndexReverse(localIP.String()) {
 | 
						|
		for _, eps := range ep.Subsets {
 | 
						|
			for _, addr := range eps.Addresses {
 | 
						|
				if localIP.Equal(net.ParseIP(addr.IP)) {
 | 
						|
					return addr.NodeName
 | 
						|
				}
 | 
						|
			}
 | 
						|
		}
 | 
						|
	}
 | 
						|
	return ""
 | 
						|
}
 |