Skip to content

Commit a575096

Browse files
committed
update
Signed-off-by: Hang Yan <[email protected]>
1 parent 18cc669 commit a575096

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

pkg/antctl/antctl.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,8 @@ $ antctl get podmulticaststats pod -n namespace`,
753753
},
754754
{
755755
cobraCommand: packetcapture.Command,
756-
supportAgent: true,
757-
supportController: true,
756+
supportAgent: false,
757+
supportController: false,
758758
},
759759
{
760760
cobraCommand: proxy.Command,

pkg/antctl/raw/packetcapture/command.go

+22-20
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,20 @@ func getPodFile(cmd *cobra.Command) (PodFileCopy, error) {
137137
}, nil
138138
}
139139

140+
func getPCName(src, dest string) string {
141+
replace := func(s string) string {
142+
return strings.ReplaceAll(s, "/", "-")
143+
}
144+
prefix := fmt.Sprintf("%s-%s", replace(src), replace(dest))
145+
if option.nowait {
146+
return prefix
147+
}
148+
return fmt.Sprintf("%s-%s", prefix, rand.String(8))
149+
}
150+
140151
func packetCaptureRunE(cmd *cobra.Command, args []string) error {
141152
option.timeout, _ = cmd.Flags().GetDuration("timeout")
142-
if option.timeout > time.Hour {
153+
if option.timeout > 300*time.Second {
143154
return errors.New("timeout cannot be longer than 1 hour")
144155
}
145156
if option.timeout == 0 {
@@ -157,7 +168,7 @@ func packetCaptureRunE(cmd *cobra.Command, args []string) error {
157168
if err != nil {
158169
return fmt.Errorf("error when constructing a PacketCapture CR: %w", err)
159170
}
160-
createCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
171+
createCtx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second)
161172
defer cancel()
162173

163174
if _, err := antreaClient.CrdV1alpha1().PacketCaptures().Create(createCtx, pc, metav1.CreateOptions{}); err != nil {
@@ -204,14 +215,16 @@ func packetCaptureRunE(cmd *cobra.Command, args []string) error {
204215
splits := strings.Split(latestPC.Status.FilePath, ":")
205216
fileName := filepath.Base(splits[1])
206217
copier, _ := getCopier(cmd)
207-
err = copier.CopyFromPod(context.TODO(), env.GetAntreaNamespace(), splits[0], "antrea-agent", splits[1], option.outputDir)
208-
if err == nil {
209-
fmt.Fprintf(cmd.OutOrStdout(), "Captured packets file: %s\n", filepath.Join(option.outputDir, fileName))
218+
if err := copier.CopyFromPod(context.TODO(), env.GetAntreaNamespace(), splits[0], "antrea-agent", splits[1], option.outputDir); err == nil {
219+
return err
210220
}
211-
return err
221+
fmt.Fprintf(cmd.OutOrStdout(), "Captured packets file: %s\n", filepath.Join(option.outputDir, fileName))
222+
return nil
212223
}
213224

214-
func parseEndpoint(endpoint string) (pod *v1alpha1.PodReference, ip *string) {
225+
func parseEndpoint(endpoint string) (*v1alpha1.PodReference, *string) {
226+
var pod *v1alpha1.PodReference
227+
var ip *string
215228
parsedIP := net.ParseIP(endpoint)
216229
if parsedIP != nil && parsedIP.To4() != nil {
217230
ip = ptr.To(parsedIP.String())
@@ -229,23 +242,12 @@ func parseEndpoint(endpoint string) (pod *v1alpha1.PodReference, ip *string) {
229242
}
230243
}
231244
}
232-
return
233-
}
234-
235-
func getPCName(src, dest string) string {
236-
replace := func(s string) string {
237-
return strings.ReplaceAll(s, "/", "-")
238-
}
239-
prefix := fmt.Sprintf("%s-%s", replace(src), replace(dest))
240-
if option.nowait {
241-
return prefix
242-
}
243-
return fmt.Sprintf("%s-%s", prefix, rand.String(8))
245+
return pod, ip
244246
}
245247

246248
func parseFlow() (*v1alpha1.Packet, error) {
247249
trimFlow := strings.ReplaceAll(option.flow, " ", "")
248-
fields, err := getFlowFields(cleanFlow)
250+
fields, err := getFlowFields(trimFlow)
249251
if err != nil {
250252
return nil, fmt.Errorf("error when parsing the flow: %w", err)
251253
}

0 commit comments

Comments
 (0)