Merge branch 'master' into upcoming-su
This commit is contained in:
commit
e662a0ee91
|
|
@ -146,10 +146,11 @@ func run(_ <-chan struct{}) {
|
|||
if err != nil {
|
||||
glog.Fatalf("Failed to create predicate checker: %v", err)
|
||||
}
|
||||
unschedulablePodLister := kube_util.NewUnschedulablePodLister(kubeClient, apiv1.NamespaceAll)
|
||||
scheduledPodLister := kube_util.NewScheduledPodLister(kubeClient)
|
||||
readyNodeLister := kube_util.NewReadyNodeLister(kubeClient)
|
||||
allNodeLister := kube_util.NewAllNodeLister(kubeClient)
|
||||
stopchannel := make(chan struct{})
|
||||
unschedulablePodLister := kube_util.NewUnschedulablePodLister(kubeClient, stopchannel)
|
||||
scheduledPodLister := kube_util.NewScheduledPodLister(kubeClient, stopchannel)
|
||||
readyNodeLister := kube_util.NewReadyNodeLister(kubeClient, stopchannel)
|
||||
allNodeLister := kube_util.NewAllNodeLister(kubeClient, stopchannel)
|
||||
|
||||
lastScaleUpTime := time.Now()
|
||||
lastScaleDownFailedTrial := time.Now()
|
||||
|
|
|
|||
|
|
@ -48,7 +48,12 @@ func (unschedulablePodLister *UnschedulablePodLister) List() ([]*apiv1.Pod, erro
|
|||
}
|
||||
|
||||
// NewUnschedulablePodLister returns a lister providing pods that failed to be scheduled.
|
||||
func NewUnschedulablePodLister(kubeClient client.Interface, namespace string) *UnschedulablePodLister {
|
||||
func NewUnschedulablePodLister(kubeClient client.Interface, stopchannel <-chan struct{}) *UnschedulablePodLister {
|
||||
return NewUnschedulablePodInNamespaceLister(kubeClient, apiv1.NamespaceAll, stopchannel)
|
||||
}
|
||||
|
||||
// NewUnschedulablePodInNamespaceLister returns a lister providing pods that failed to be scheduled in the given namespace.
|
||||
func NewUnschedulablePodInNamespaceLister(kubeClient client.Interface, namespace string, stopchannel <-chan struct{}) *UnschedulablePodLister {
|
||||
// watch unscheduled pods
|
||||
selector := fields.ParseSelectorOrDie("spec.nodeName==" + "" + ",status.phase!=" +
|
||||
string(apiv1.PodSucceeded) + ",status.phase!=" + string(apiv1.PodFailed))
|
||||
|
|
@ -56,8 +61,7 @@ func NewUnschedulablePodLister(kubeClient client.Interface, namespace string) *U
|
|||
store := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
|
||||
podLister := &cache.StoreToPodLister{store}
|
||||
podReflector := cache.NewReflector(podListWatch, &apiv1.Pod{}, store, time.Hour)
|
||||
podReflector.Run()
|
||||
|
||||
podReflector.RunUntil(stopchannel)
|
||||
return &UnschedulablePodLister{
|
||||
podLister: podLister,
|
||||
}
|
||||
|
|
@ -74,7 +78,7 @@ func (lister *ScheduledPodLister) List() ([]*apiv1.Pod, error) {
|
|||
}
|
||||
|
||||
// NewScheduledPodLister builds ScheduledPodLister
|
||||
func NewScheduledPodLister(kubeClient client.Interface) *ScheduledPodLister {
|
||||
func NewScheduledPodLister(kubeClient client.Interface, stopchannel <-chan struct{}) *ScheduledPodLister {
|
||||
// watch unscheduled pods
|
||||
selector := fields.ParseSelectorOrDie("spec.nodeName!=" + "" + ",status.phase!=" +
|
||||
string(apiv1.PodSucceeded) + ",status.phase!=" + string(apiv1.PodFailed))
|
||||
|
|
@ -82,7 +86,7 @@ func NewScheduledPodLister(kubeClient client.Interface) *ScheduledPodLister {
|
|||
store := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
|
||||
podLister := &cache.StoreToPodLister{store}
|
||||
podReflector := cache.NewReflector(podListWatch, &apiv1.Pod{}, store, time.Hour)
|
||||
podReflector.Run()
|
||||
podReflector.RunUntil(stopchannel)
|
||||
|
||||
return &ScheduledPodLister{
|
||||
podLister: podLister,
|
||||
|
|
@ -113,11 +117,11 @@ func (readyNodeLister *ReadyNodeLister) List() ([]*apiv1.Node, error) {
|
|||
}
|
||||
|
||||
// NewReadyNodeLister builds a node lister.
|
||||
func NewReadyNodeLister(kubeClient client.Interface) *ReadyNodeLister {
|
||||
func NewReadyNodeLister(kubeClient client.Interface, stopChannel <-chan struct{}) *ReadyNodeLister {
|
||||
listWatcher := cache.NewListWatchFromClient(kubeClient.Core().RESTClient(), "nodes", apiv1.NamespaceAll, fields.Everything())
|
||||
nodeLister := &cache.StoreToNodeLister{Store: cache.NewStore(cache.MetaNamespaceKeyFunc)}
|
||||
reflector := cache.NewReflector(listWatcher, &apiv1.Node{}, nodeLister.Store, time.Hour)
|
||||
reflector.Run()
|
||||
reflector.RunUntil(stopChannel)
|
||||
return &ReadyNodeLister{
|
||||
nodeLister: nodeLister,
|
||||
}
|
||||
|
|
@ -142,11 +146,11 @@ func (allNodeLister *AllNodeLister) List() ([]*apiv1.Node, error) {
|
|||
}
|
||||
|
||||
// NewAllNodeLister builds a node lister that returns all nodes (ready and unready)
|
||||
func NewAllNodeLister(kubeClient client.Interface) *AllNodeLister {
|
||||
func NewAllNodeLister(kubeClient client.Interface, stopchannel <-chan struct{}) *AllNodeLister {
|
||||
listWatcher := cache.NewListWatchFromClient(kubeClient.Core().RESTClient(), "nodes", apiv1.NamespaceAll, fields.Everything())
|
||||
nodeLister := &cache.StoreToNodeLister{Store: cache.NewStore(cache.MetaNamespaceKeyFunc)}
|
||||
reflector := cache.NewReflector(listWatcher, &apiv1.Node{}, nodeLister.Store, time.Hour)
|
||||
reflector.Run()
|
||||
reflector.RunUntil(stopchannel)
|
||||
return &AllNodeLister{
|
||||
nodeLister: nodeLister,
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue