Skip to content

Commit

Permalink
Watch only pods in state Running and Unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
jbartosik committed Dec 4, 2020
1 parent b201c8d commit 84fb751
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,14 @@ func watchEvictionEvents(evictedEventChan <-chan watch.Event, observer oom.Obser

// Creates clients watching pods: PodLister (listing only not terminated pods).
func newPodClients(kubeClient kube_client.Interface, resourceEventHandler cache.ResourceEventHandler, namespace string) v1lister.PodLister {
selector := fields.ParseSelectorOrDie("status.phase!=" + string(apiv1.PodPending))
// We are interested in pods which are Running or Unknown (in case the pod is
// running but there are some transient errors we don't want to delete it from
// our model).
// We don't want to watch Pending, Succeeded, or Failed failed pods because we
// know they're not generating any usage.
// Filter
statusFilter := fmt.Sprintf("status.phase!=%s,status.phase!=%s,status.phase!=%s", apiv1.PodPending, apiv1.PodSucceeded, apiv1.PodFailed)
selector := fields.ParseSelectorOrDie(statusFilter)
podListWatch := cache.NewListWatchFromClient(kubeClient.CoreV1().RESTClient(), "pods", namespace, selector)
indexer, controller := cache.NewIndexerInformer(
podListWatch,
Expand Down

0 comments on commit 84fb751

Please sign in to comment.