/
filter.go
30 lines (26 loc) · 914 Bytes
/
filter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
}
}