-
Notifications
You must be signed in to change notification settings - Fork 325
/
namespace.go
41 lines (35 loc) · 947 Bytes
/
namespace.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
31
32
33
34
35
36
37
38
39
40
41
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package filters
import (
"context"
"github.com/cilium/tetragon/api/v1/tetragon"
v1 "github.com/cilium/tetragon/pkg/oldhubble/api/v1"
hubbleFilters "github.com/cilium/tetragon/pkg/oldhubble/filters"
)
func filterByNamespace(namespaces []string) hubbleFilters.FilterFunc {
return func(ev *v1.Event) bool {
process := GetProcess(ev)
if process == nil {
return false
}
for _, namespace := range namespaces {
if process.Pod == nil {
if namespace == "" {
return true
}
} else if namespace == process.Pod.Namespace {
return true
}
}
return false
}
}
type NamespaceFilter struct{}
func (f *NamespaceFilter) OnBuildFilter(_ context.Context, ff *tetragon.Filter) ([]hubbleFilters.FilterFunc, error) {
var fs []hubbleFilters.FilterFunc
if ff.Namespace != nil {
fs = append(fs, filterByNamespace(ff.Namespace))
}
return fs, nil
}