Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Lan <luola@vmware.com>
Co-authored-by: Antonin Bas <antonin.bas@gmail.com>
  • Loading branch information
3 people authored Feb 11, 2025
1 parent 43a9451 commit 18cc669
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions pkg/antctl/raw/packetcapture/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ func init() {
Command = &cobra.Command{
Use: "packetcapture",
Short: "Start capture packets",
Long: "Start capture packets on the target flow.",
Long: "Start capturing packets on the target flow",
Aliases: []string{"pc", "packetcaptures"},
Example: packetCaptureExample,
RunE: packetCaptureRunE,
}

Command.Flags().StringVarP(&option.source, "source", "S", "", "source of the the PacketCapture: Namespace/Pod, Pod, or IP")
Command.Flags().StringVarP(&option.dest, "destination", "D", "", "destination of the PacketCapture: Namespace/Pod, Pod, or IP")
Command.Flags().Int32VarP(&option.number, "number", "n", 0, "target packets number")
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().Int32VarP(&option.number, "number", "n", 0, "target number of packets to capture, the capture will stop when it is reached")
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")
}
Expand Down Expand Up @@ -155,7 +155,7 @@ func packetCaptureRunE(cmd *cobra.Command, args []string) error {
}
pc, err := newPacketCapture()
if err != nil {
return fmt.Errorf("error when filling up PacketCapture config: %w", err)
return fmt.Errorf("error when constructing a PacketCapture CR: %w", err)
}
createCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
Expand All @@ -172,7 +172,7 @@ func packetCaptureRunE(cmd *cobra.Command, args []string) error {
}()

if option.nowait {
fmt.Fprintf(cmd.OutOrStdout(), "PacketCapture Name: %s\n", pc.Name)
fmt.Fprintf(cmd.OutOrStdout(), "PacketCapture Name: %s\n", pc.Name)
return nil
}

Expand All @@ -193,7 +193,7 @@ func packetCaptureRunE(cmd *cobra.Command, args []string) error {
})

if wait.Interrupted(err) {
err = errors.New("timeout waiting for PacketCapture done")
err = errors.New("timeout while waiting for PacketCapture to complete")
if latestPC == nil {
return err
}
Expand All @@ -206,7 +206,7 @@ func packetCaptureRunE(cmd *cobra.Command, args []string) error {
copier, _ := getCopier(cmd)
err = copier.CopyFromPod(context.TODO(), env.GetAntreaNamespace(), splits[0], "antrea-agent", splits[1], option.outputDir)
if err == nil {
fmt.Fprintf(cmd.OutOrStdout(), "Packet File: %s\n", filepath.Join(option.outputDir, fileName))
fmt.Fprintf(cmd.OutOrStdout(), "Captured packets file: %s\n", filepath.Join(option.outputDir, fileName))
}
return err
}
Expand Down Expand Up @@ -244,7 +244,7 @@ func getPCName(src, dest string) string {
}

func parseFlow() (*v1alpha1.Packet, error) {
cleanFlow := strings.ReplaceAll(option.flow, " ", "")
trimFlow := strings.ReplaceAll(option.flow, " ", "")

Check failure on line 247 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / golicense

declared and not used: trimFlow

Check failure on line 247 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Build Antrea Windows binaries

declared and not used: trimFlow

Check failure on line 247 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Build Antrea and antctl binaries

declared and not used: trimFlow

Check failure on line 247 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (macos-latest)

declared and not used: trimFlow

Check failure on line 247 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (macos-latest)

declared and not used: trimFlow

Check failure on line 247 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (ubuntu-latest)

declared and not used: trimFlow

Check failure on line 247 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (ubuntu-latest)

declared and not used: trimFlow

Check failure on line 247 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Go benchmark test

declared and not used: trimFlow

Check failure on line 247 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Unit test (ubuntu-latest)

declared and not used: trimFlow

Check failure on line 247 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Analyze on Linux (go)

declared and not used: trimFlow

Check failure on line 247 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Unit test (windows-2022)

declared and not used: trimFlow

Check failure on line 247 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Analyze on Windows (go)

declared and not used: trimFlow
fields, err := getFlowFields(cleanFlow)

Check failure on line 248 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / golicense

undefined: cleanFlow

Check failure on line 248 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Build Antrea Windows binaries

undefined: cleanFlow

Check failure on line 248 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Build Antrea and antctl binaries

undefined: cleanFlow

Check failure on line 248 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (macos-latest)

undefined: cleanFlow) (typecheck)

Check failure on line 248 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (macos-latest)

undefined: cleanFlow (typecheck)

Check failure on line 248 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (ubuntu-latest)

undefined: cleanFlow) (typecheck)

Check failure on line 248 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (ubuntu-latest)

undefined: cleanFlow (typecheck)

Check failure on line 248 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Go benchmark test

undefined: cleanFlow

Check failure on line 248 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Unit test (ubuntu-latest)

undefined: cleanFlow

Check failure on line 248 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Analyze on Linux (go)

undefined: cleanFlow

Check failure on line 248 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Unit test (windows-2022)

undefined: cleanFlow

Check failure on line 248 in pkg/antctl/raw/packetcapture/command.go

View workflow job for this annotation

GitHub Actions / Analyze on Windows (go)

undefined: cleanFlow
if err != nil {
return nil, fmt.Errorf("error when parsing the flow: %w", err)
Expand Down Expand Up @@ -272,7 +272,7 @@ func parseFlow() (*v1alpha1.Packet, error) {
pkt.TransportHeader.UDP.SrcPort = ptr.To(int32(r))
}
if r, ok := fields["udp_dst"]; ok {
if pkt.TransportHeader.UDP != nil {
if pkt.TransportHeader.UDP == nil {
pkt.TransportHeader.UDP = new(v1alpha1.UDPHeader)
}
pkt.TransportHeader.UDP.DstPort = ptr.To(int32(r))
Expand Down
2 changes: 1 addition & 1 deletion pkg/antctl/raw/packetcapture/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestRun(t *testing.T) {
name: "pod-2-pod",
src: srcPod,
dst: dstPod,
flow: "tcp,tcp_src=500060,tcp_dst=80",
flow: "tcp,tcp_src=50060,tcp_dst=80",
},
{
name: "pod-2-ip",
Expand Down

0 comments on commit 18cc669

Please sign in to comment.