Skip to content

Commit

Permalink
Don't set --last if --input-file is specified
Browse files Browse the repository at this point in the history
Don't set --last to 20 if --input-file flag is specified to preserve the
previous default behavior of processing all the flows from stdin.

Signed-off-by: Michi Mutsuzaki <michi@isovalent.com>
  • Loading branch information
michi-covalent authored and chancez committed Jul 26, 2023
1 parent 4c9421a commit e6cd049
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/observe/flows.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ func getFlowsRequest(ofilter *flowFilter, allowlist []string, denylist []string)
case selectorOpts.all:
// all is an alias for last=uint64_max
selectorOpts.last = ^uint64(0)
case selectorOpts.last == 0 && !selectorOpts.follow:
case selectorOpts.last == 0 && !selectorOpts.follow && otherOpts.inputFile == "":
// no specific parameters were provided, just a vanilla
// `hubble observe` in non-follow mode
selectorOpts.last = defaults.FlowPrintCount
Expand Down
15 changes: 15 additions & 0 deletions cmd/observe/flows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,18 @@ func Test_getFlowsRequest_ExperimentalFieldMask_non_json_output(t *testing.T) {
err := handleFlowArgs(os.Stdout, filter, false)
assert.ErrorContains(t, err, "not compatible")
}

func Test_getFlowsRequestWithInputFile(t *testing.T) {
// Don't set the number flag in GetFlowsRequest by default if --input-file is specified
selectorOpts.last = 0
otherOpts.inputFile = "myfile"
req, err := getFlowsRequest(newFlowFilter(), nil, nil)
assert.NoError(t, err)
assert.Equal(t, uint64(0), req.Number)

// .. but you can explicitly specify --last flag
selectorOpts.last = 42
req, err = getFlowsRequest(newFlowFilter(), nil, nil)
assert.NoError(t, err)
assert.Equal(t, uint64(42), req.Number)
}

0 comments on commit e6cd049

Please sign in to comment.