Skip to content

Commit

Permalink
cmd/observe: Add node name filter
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Payne <tom@isovalent.com>
  • Loading branch information
twpayne committed Nov 3, 2020
1 parent 428a16d commit a3c910f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/observe/observe.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ more.`,
"to-identity", ofilter,
"Show all flows terminating at an endpoint with the given security identity"))

observerCmd.Flags().Var(filterVar(
"node-names", ofilter,
`Show all flows which match the given node names (e.g. "k8s*", "test-cluster/*.company.com")`))

observerCmd.Flags().BoolVarP(
&jsonOutput, "json", "j", false, "Deprecated. Use '--output json' instead.",
)
Expand Down
7 changes: 7 additions & 0 deletions cmd/observe/observe_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func newObserveFilter() *observeFilter {
{"port", "from-port"},
{"identity", "to-identity"},
{"identity", "from-identity"},
{"node-name"},
},
}
}
Expand Down Expand Up @@ -431,6 +432,12 @@ func (of *observeFilter) set(f *filterTracker, name, val string, track bool) err
f.apply(func(f *pb.FlowFilter) {
f.DestinationIdentity = append(f.DestinationIdentity, identity)
})

// node name filters
case "node-name":
f.apply(func(f *pb.FlowFilter) {
f.NodeNames = append(f.NodeNames, val)
})
}

return nil
Expand Down
2 changes: 2 additions & 0 deletions cmd/observe/observe_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func TestFilterLeftRight(t *testing.T) {
"--not", "--http-status", "200",
"--http-method", "get",
"--http-path", "/page/\\d+",
"--node-name", "k8s*",
}))

require.NoError(t, handleArgs(f, false))
Expand All @@ -140,6 +141,7 @@ func TestFilterLeftRight(t *testing.T) {
Verdict: []pb.Verdict{pb.Verdict_DROPPED},
HttpMethod: []string{"get"},
HttpPath: []string{"/page/\\d+"},
NodeNames: []string{"k8s*"},
},
{
DestinationIp: []string{"1.2.3.4", "5.6.7.8"},
Expand Down
1 change: 1 addition & 0 deletions cmd/observe/observe_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func modifyTemplate(orig string, cmd *cobra.Command) string {
"port", "to-port", "from-port",
"type", "verdict", "http-status", "http-method", "http-path", "protocol",
"identity", "to-identity", "from-identity",
"node-names",
},
},
}
Expand Down

0 comments on commit a3c910f

Please sign in to comment.