From a3c910fb00705dfd2e81eb133111aa9dac9a39fb Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Fri, 30 Oct 2020 16:02:26 +0000 Subject: [PATCH] cmd/observe: Add node name filter Signed-off-by: Tom Payne --- cmd/observe/observe.go | 4 ++++ cmd/observe/observe_filter.go | 7 +++++++ cmd/observe/observe_filter_test.go | 2 ++ cmd/observe/observe_usage.go | 1 + 4 files changed, 14 insertions(+) diff --git a/cmd/observe/observe.go b/cmd/observe/observe.go index 67104d7c7..1ac078189 100644 --- a/cmd/observe/observe.go +++ b/cmd/observe/observe.go @@ -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.", ) diff --git a/cmd/observe/observe_filter.go b/cmd/observe/observe_filter.go index cf17851e7..4db83c6c0 100644 --- a/cmd/observe/observe_filter.go +++ b/cmd/observe/observe_filter.go @@ -126,6 +126,7 @@ func newObserveFilter() *observeFilter { {"port", "from-port"}, {"identity", "to-identity"}, {"identity", "from-identity"}, + {"node-name"}, }, } } @@ -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 diff --git a/cmd/observe/observe_filter_test.go b/cmd/observe/observe_filter_test.go index 7a5fc69b1..5bb36d3bb 100644 --- a/cmd/observe/observe_filter_test.go +++ b/cmd/observe/observe_filter_test.go @@ -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)) @@ -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"}, diff --git a/cmd/observe/observe_usage.go b/cmd/observe/observe_usage.go index 54b9f4370..2a46342a8 100644 --- a/cmd/observe/observe_usage.go +++ b/cmd/observe/observe_usage.go @@ -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", }, }, }