Skip to content

Commit 18cc669

Browse files
hangyanluolanzoneantoninbas
authored
Apply suggestions from code review
Co-authored-by: Lan <[email protected]> Co-authored-by: Antonin Bas <[email protected]>
1 parent 43a9451 commit 18cc669

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

pkg/antctl/raw/packetcapture/command.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@ func init() {
7373
Command = &cobra.Command{
7474
Use: "packetcapture",
7575
Short: "Start capture packets",
76-
Long: "Start capture packets on the target flow.",
76+
Long: "Start capturing packets on the target flow",
7777
Aliases: []string{"pc", "packetcaptures"},
7878
Example: packetCaptureExample,
7979
RunE: packetCaptureRunE,
8080
}
8181

8282
Command.Flags().StringVarP(&option.source, "source", "S", "", "source of the the PacketCapture: Namespace/Pod, Pod, or IP")
8383
Command.Flags().StringVarP(&option.dest, "destination", "D", "", "destination of the PacketCapture: Namespace/Pod, Pod, or IP")
84-
Command.Flags().Int32VarP(&option.number, "number", "n", 0, "target packets number")
85-
Command.Flags().StringVarP(&option.flow, "flow", "f", "", "specify the flow (packet headers) of the PacketCapture , including tcp_src, tcp_dst, udp_src, udp_dst")
84+
Command.Flags().Int32VarP(&option.number, "number", "n", 0, "target number of packets to capture, the capture will stop when it is reached")
85+
Command.Flags().StringVarP(&option.flow, "flow", "f", "", "specify the flow (packet headers) of the PacketCapture, including tcp_src, tcp_dst, udp_src, udp_dst")
8686
Command.Flags().BoolVarP(&option.nowait, "nowait", "", false, "if set, command returns without retrieving results")
8787
Command.Flags().StringVarP(&option.outputDir, "output-dir", "o", ".", "save the packets file to the target directory")
8888
}
@@ -155,7 +155,7 @@ func packetCaptureRunE(cmd *cobra.Command, args []string) error {
155155
}
156156
pc, err := newPacketCapture()
157157
if err != nil {
158-
return fmt.Errorf("error when filling up PacketCapture config: %w", err)
158+
return fmt.Errorf("error when constructing a PacketCapture CR: %w", err)
159159
}
160160
createCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
161161
defer cancel()
@@ -172,7 +172,7 @@ func packetCaptureRunE(cmd *cobra.Command, args []string) error {
172172
}()
173173

174174
if option.nowait {
175-
fmt.Fprintf(cmd.OutOrStdout(), "PacketCapture Name: %s\n", pc.Name)
175+
fmt.Fprintf(cmd.OutOrStdout(), "PacketCapture Name: %s\n", pc.Name)
176176
return nil
177177
}
178178

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

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

246246
func parseFlow() (*v1alpha1.Packet, error) {
247-
cleanFlow := strings.ReplaceAll(option.flow, " ", "")
247+
trimFlow := strings.ReplaceAll(option.flow, " ", "")
248248
fields, err := getFlowFields(cleanFlow)
249249
if err != nil {
250250
return nil, fmt.Errorf("error when parsing the flow: %w", err)
@@ -272,7 +272,7 @@ func parseFlow() (*v1alpha1.Packet, error) {
272272
pkt.TransportHeader.UDP.SrcPort = ptr.To(int32(r))
273273
}
274274
if r, ok := fields["udp_dst"]; ok {
275-
if pkt.TransportHeader.UDP != nil {
275+
if pkt.TransportHeader.UDP == nil {
276276
pkt.TransportHeader.UDP = new(v1alpha1.UDPHeader)
277277
}
278278
pkt.TransportHeader.UDP.DstPort = ptr.To(int32(r))

pkg/antctl/raw/packetcapture/command_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestRun(t *testing.T) {
9696
name: "pod-2-pod",
9797
src: srcPod,
9898
dst: dstPod,
99-
flow: "tcp,tcp_src=500060,tcp_dst=80",
99+
flow: "tcp,tcp_src=50060,tcp_dst=80",
100100
},
101101
{
102102
name: "pod-2-ip",

0 commit comments

Comments
 (0)