Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support antctl command for packetcapture #6884

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hangyan
Copy link
Member

@hangyan hangyan commented Dec 24, 2024

TODO items:

after #3659 , the CodeQL alert should be fixed and UT coverage will also be improved.

pkg/antctl/raw/packetcapture/cp.go Fixed Show resolved Hide resolved
@hangyan hangyan force-pushed the topic/yhang/packetcapture-antctl branch from 4a616d6 to bf4cb68 Compare January 14, 2025 09:03
@hangyan hangyan changed the title [WIP] Support antctl command for packetcapture Support antctl command for packetcapture Jan 14, 2025
@hangyan
Copy link
Member Author

hangyan commented Feb 6, 2025

cc @antoninbas Can you help review this? also maybe merge #3659 first

cc @luolanzone

@hangyan hangyan force-pushed the topic/yhang/packetcapture-antctl branch from 676981f to b27b72b Compare February 6, 2025 10:21
@hangyan hangyan force-pushed the topic/yhang/packetcapture-antctl branch from b27b72b to 43a9451 Compare February 7, 2025 10:54
Command.Flags().StringVarP(&option.flow, "flow", "f", "", "specify the flow (packet headers) of the PacketCapture , including tcp_src, tcp_dst, udp_src, udp_dst")
Command.Flags().BoolVarP(&option.nowait, "nowait", "", false, "if set, command returns without retrieving results")
Command.Flags().StringVarP(&option.outputDir, "output-dir", "o", ".", "save the packets file to the target directory")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should let users configure a timeout as well. IIRC, when the timeout expires we still generate a pcap with the packets captured so far, even if the target packet number has not been reached.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a global timeout flag, i think that should work too?

pkg/antctl/raw/packetcapture/command.go Outdated Show resolved Hide resolved
}

func packetCaptureRunE(cmd *cobra.Command, args []string) error {
option.timeout, _ = cmd.Flags().GetDuration("timeout")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason why the timeout flag is not defined alongside the other flags?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

antctl has a global timeout flag which apply to all sub-command, should we reuse that instead define a new one?

pkg/antctl/raw/packetcapture/command.go Show resolved Hide resolved
restInterface rest.Interface
}

func (p *podFile) CopyFromPod(ctx context.Context, namespace, name, containerName, srcPath, dstDir string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have ExecInPod defined in pkg/antctl/raw/check/. Can we unify a bit?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will try.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

pkg/antctl/raw/packetcapture/command.go Outdated Show resolved Hide resolved
pkg/antctl/raw/packetcapture/command.go Outdated Show resolved Hide resolved
pkg/antctl/raw/packetcapture/command.go Outdated Show resolved Hide resolved
pkg/antctl/raw/packetcapture/command.go Show resolved Hide resolved
pkg/antctl/raw/packetcapture/command.go Show resolved Hide resolved
pkg/antctl/raw/packetcapture/command.go Show resolved Hide resolved
pkg/antctl/raw/packetcapture/command.go Outdated Show resolved Hide resolved
`)

func init() {
Command = &cobra.Command{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the antctl document to include this new command.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do.

pkg/antctl/raw/packetcapture/command.go Outdated Show resolved Hide resolved
pkg/antctl/raw/packetcapture/command.go Outdated Show resolved Hide resolved
pkg/antctl/raw/packetcapture/command.go Outdated Show resolved Hide resolved
pkg/antctl/raw/packetcapture/command.go Outdated Show resolved Hide resolved
pkg/antctl/raw/packetcapture/command.go Outdated Show resolved Hide resolved
pkg/antctl/raw/packetcapture/command.go Outdated Show resolved Hide resolved
pkg/antctl/raw/packetcapture/command_test.go Outdated Show resolved Hide resolved
@luolanzone luolanzone added this to the Antrea v2.4 release milestone Feb 8, 2025
@luolanzone
Copy link
Contributor

Please fix the antctl e2e test failures: https://github.com/antrea-io/antrea/actions/runs/13198383877?pr=6884

Co-authored-by: Lan <[email protected]>
Co-authored-by: Antonin Bas <[email protected]>
@luolanzone
Copy link
Contributor

@hangyan there are lots of failures in github checks, please check and fix them.

@hangyan hangyan force-pushed the topic/yhang/packetcapture-antctl branch from e1ba1b2 to 3436bfe Compare February 11, 2025 10:19
@hangyan
Copy link
Member Author

hangyan commented Feb 12, 2025

Please fix the antctl e2e test failures: https://github.com/antrea-io/antrea/actions/runs/13198383877?pr=6884

I disable the flag to run packetcapture sub-command in agentMode but controllerMode will still fail. One must be chosen, or this sub-command wont be registered to the rootCmd. However, seems packetcapture doens't make much sense in agentMode or controllerMode(controllerMode also contains outside of cluster case I think, but the e2e will check the command in controller pod).

The tests expect run antctl packetcapture to be successful. the first error comes from packet number should be larger than 0, that's the default value and it will cause error. Even we set with a valid default value, no src/dest endpoint ( i think Traceflow support this?), or packetcapture is not enabled , the command will still fail.

Can we make an exception in the test-case or we need to provide some sane defaults for it to working in the controllerMode?

cc @luolanzone @antoninbas

Signed-off-by: Hang Yan <[email protected]>
@hangyan hangyan force-pushed the topic/yhang/packetcapture-antctl branch from 5ac92d9 to e44de62 Compare February 12, 2025 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants