Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions pkg/operator/terminationobserver/termination_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func NewTerminationObserver(
apiServerTerminationTime: map[string]time.Time{},
}

kubeInformersForTargetNamespace.Core().V1().Pods().Informer().AddEventHandler(c.eventHandler())
kubeInformersForTargetNamespace.Core().V1().Pods().Informer().AddEventHandler(c.podEventHandler())
kubeInformersForTargetNamespace.Core().V1().Events().Informer().AddEventHandler(c.terminationEventRecorder())

c.cachesToSync = append(c.cachesToSync, kubeInformersForTargetNamespace.Core().V1().Pods().Informer().HasSynced)
Expand Down Expand Up @@ -242,10 +242,31 @@ func (c *TerminationObserver) terminationEventRecorder() cache.ResourceEventHand
}
}

func (c *TerminationObserver) eventHandler() cache.ResourceEventHandler {
func (c *TerminationObserver) podEventHandler() cache.ResourceEventHandler {
return cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) { c.queue.Add(controllerWorkQueueKey) },
UpdateFunc: func(old, new interface{}) { c.queue.Add(controllerWorkQueueKey) },
DeleteFunc: func(obj interface{}) { c.queue.Add(controllerWorkQueueKey) },
AddFunc: func(obj interface{}) {
pod, ok := obj.(*corev1.Pod)
if !ok {
utilruntime.HandleError(fmt.Errorf("expected v1.Pod, got %T", obj))
return
}
app, ok := pod.Labels["app"]
if ok && app == "openshift-kube-apiserver" {
c.queue.Add(fmt.Sprintf("pod create %s", pod.Name))
}
},
// no need to trigger termination controller on pod update
UpdateFunc: func(old, new interface{}) {},
DeleteFunc: func(obj interface{}) {
pod, ok := obj.(*corev1.Pod)
if !ok {
utilruntime.HandleError(fmt.Errorf("expected v1.Pod, got %T", obj))
return
}
app, ok := pod.Labels["app"]
if ok && app == "openshift-kube-apiserver" {
c.queue.Add(fmt.Sprintf("pod delete %s", pod.Name))
}
},
}
}