mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-03 18:53:13 -05:00 
			
		
		
		
	* Fix for #2842, instead of returning the first Pod, return the one which is Running * a more memory efficient version of the fix, string -> bool * fix with no extra fields in struct, return nil at Pod conversion if Pod is not Running * let Kuberneretes filter for Running Pods using FieldSelector * filter for Pods that are Running and Pending (implicit)
		
			
				
	
	
		
			53 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package kubernetes
 | 
						|
 | 
						|
import (
 | 
						|
	meta "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						|
	"k8s.io/apimachinery/pkg/labels"
 | 
						|
	"k8s.io/apimachinery/pkg/watch"
 | 
						|
	"k8s.io/client-go/kubernetes"
 | 
						|
)
 | 
						|
 | 
						|
func serviceWatchFunc(c kubernetes.Interface, ns string, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) {
 | 
						|
	return func(options meta.ListOptions) (watch.Interface, error) {
 | 
						|
		if s != nil {
 | 
						|
			options.LabelSelector = s.String()
 | 
						|
		}
 | 
						|
		w, err := c.CoreV1().Services(ns).Watch(options)
 | 
						|
		return w, err
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
func podWatchFunc(c kubernetes.Interface, ns string, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) {
 | 
						|
	return func(options meta.ListOptions) (watch.Interface, error) {
 | 
						|
		if s != nil {
 | 
						|
			options.LabelSelector = s.String()
 | 
						|
		}
 | 
						|
		if len(options.FieldSelector) > 0 {
 | 
						|
			options.FieldSelector = options.FieldSelector + ","
 | 
						|
		}
 | 
						|
		options.FieldSelector = options.FieldSelector + "status.phase!=Succeeded,status.phase!=Failed,status.phase!=Unknown"
 | 
						|
		w, err := c.CoreV1().Pods(ns).Watch(options)
 | 
						|
		return w, err
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
func endpointsWatchFunc(c kubernetes.Interface, ns string, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) {
 | 
						|
	return func(options meta.ListOptions) (watch.Interface, error) {
 | 
						|
		if s != nil {
 | 
						|
			options.LabelSelector = s.String()
 | 
						|
		}
 | 
						|
		w, err := c.CoreV1().Endpoints(ns).Watch(options)
 | 
						|
		return w, err
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
func namespaceWatchFunc(c kubernetes.Interface, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) {
 | 
						|
	return func(options meta.ListOptions) (watch.Interface, error) {
 | 
						|
		if s != nil {
 | 
						|
			options.LabelSelector = s.String()
 | 
						|
		}
 | 
						|
		w, err := c.CoreV1().Namespaces().Watch(options)
 | 
						|
		return w, err
 | 
						|
	}
 | 
						|
}
 |