This allows users who have a shared informer that is *not* filtering on node name to supply a filter for event handlers to ensure events do not fire for pods not scheduled to the node. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
31 lines
914 B
Go
31 lines
914 B
Go
package nodeutil
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/virtual-kubelet/virtual-kubelet/node"
|
|
v1 "k8s.io/api/core/v1"
|
|
)
|
|
|
|
// FilterPodsForNodeName creates an event filter function that filters pod events such that pod.Sepc.NodeName matches the provided name
|
|
// Use the return value of this as the PodEventFilterFunc in PodControllerConfig
|
|
func FilterPodsForNodeName(name string) node.PodEventFilterFunc {
|
|
return func(_ context.Context, p *v1.Pod) bool {
|
|
return p.Spec.NodeName == name
|
|
}
|
|
}
|
|
|
|
// PodFilters turns a list of pod filters into a single filter.
|
|
// When run, each item in the list is itterated in order until the first `true` result.
|
|
// If nothing returns true, the filter is false.
|
|
func PodFilters(filters ...node.PodEventFilterFunc) node.PodEventFilterFunc {
|
|
return func(ctx context.Context, p *v1.Pod) bool {
|
|
for _, f := range filters {
|
|
if f(ctx, p) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
}
|