Skip to content

Commit 46323b4

Browse files
committed
tetra: add namespace-regex flag to getevents
This adds a new flag to the tetra CLI so users can test the namespace regex filter directly from the command line. Example: ``` tetra getevents --namespace-regex 'prod-.*' cat events.json | tetra getevents --namespace-regex 'prod-.*' -o compact ``` Signed-off-by: Aritra Dey <[email protected]>
1 parent 761674d commit 46323b4

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

cmd/tetra/getevents/getevents.go

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,28 @@ import (
2323
)
2424

2525
type Opts struct {
26-
Output string
27-
Color string
28-
IncludeFields []string
29-
EventTypes []string
30-
ExcludeFields []string
31-
Namespaces []string
32-
Namespace []string // deprecated: use Namespaces
33-
Processes []string
34-
Process []string // deprecated: use Processes
35-
Pods []string
36-
Pod []string // deprecated: use Pods
37-
Containers []string
38-
Host bool
39-
Timestamps bool
40-
TTYEncode string
41-
StackTraces bool
42-
ImaHash bool
43-
PolicyNames []string
44-
CelExpression []string
45-
Reconnect bool
46-
ReconnectWait time.Duration
26+
Output string
27+
Color string
28+
IncludeFields []string
29+
EventTypes []string
30+
ExcludeFields []string
31+
Namespaces []string
32+
Namespace []string // deprecated: use Namespaces
33+
Processes []string
34+
Process []string // deprecated: use Processes
35+
Pods []string
36+
Pod []string // deprecated: use Pods
37+
Containers []string
38+
Host bool
39+
Timestamps bool
40+
TTYEncode string
41+
StackTraces bool
42+
ImaHash bool
43+
PolicyNames []string
44+
NamespaceRegex []string
45+
CelExpression []string
46+
Reconnect bool
47+
ReconnectWait time.Duration
4748
}
4849

4950
var Options Opts
@@ -95,6 +96,9 @@ var GetFilter = func() *tetragon.Filter {
9596
if len(Options.PolicyNames) > 0 {
9697
filter.PolicyNames = Options.PolicyNames
9798
}
99+
if len(Options.NamespaceRegex) > 0 {
100+
filter.NamespaceRegex = Options.NamespaceRegex
101+
}
98102
if len(Options.CelExpression) > 0 {
99103
filter.CelExpression = Options.CelExpression
100104
}
@@ -257,6 +261,7 @@ redirection of events to the stdin. Examples:
257261
flags.BoolVar(&Options.StackTraces, "stack-traces", true, "Include stack traces in compact output")
258262
flags.BoolVar(&Options.ImaHash, "ima-hash", true, "Include ima hashes in compact output")
259263
flags.StringSliceVar(&Options.PolicyNames, "policy-names", nil, "Get events by tracing policy names")
264+
flags.StringSliceVar(&Options.NamespaceRegex, "namespace-regex", nil, "Get events by namespace name regex")
260265
flags.StringSliceVar(&Options.CelExpression, "cel-expression", nil, "Get events satisfying the CEL expression")
261266
flags.BoolVar(&Options.Reconnect, "reconnect", false, "Keep trying to connect even if an error occurred")
262267
flags.DurationVar(&Options.ReconnectWait, "reconnect-wait", 2*time.Second, "wait time before attempting to reconnect")

0 commit comments

Comments
 (0)