Skip to content

calicovppctl: improve capture file transfer robustness#869

Merged
sknat merged 1 commit intomasterfrom
abasu-fix-copy-fail
Jan 30, 2026
Merged

calicovppctl: improve capture file transfer robustness#869
sknat merged 1 commit intomasterfrom
abasu-fix-copy-fail

Conversation

@aritrbas
Copy link
Collaborator

@aritrbas aritrbas commented Jan 28, 2026

Summary

This PR improves the robustness of capture file downloads in calicovppctl for trace, pcap, and dispatch commands.

Problem

Large capture file downloads using kubectl cp were unreliable, often failing mid-transfer with generic errors forcing users to rerun entire captures when the transfer failed.

Changes

1. Use Kubernetes Go Client API Instead of Shell Exec

Replace exec.Command(kubectl ...) with the native Kubernetes Go client API (k8s.io/client-go/tools/remotecommand). This provides better error handling with structured errors through direct integration with the existing Kubernetes client.

2. Retry Logic for File Transfer

Add retry mechanism (3 attempts) for file transfers. This handles transient network issues that commonly cause failures with large capture files.

3. Graceful Failure with Manual Recovery

When file transfer fails after all 3 retry attempts:

  • Remote capture files are preserved (not cleaned up)
  • Clear instructions are printed showing how to manually retrieve the file
  • User is directed to use calicovppctl capture clear for cleanup after manual retrieval

4. Pre-existing File Cleanup

Before starting a new capture, any pre-existing capture file is removed. This ensures fresh captures without stale data and prevents accidental appending to pre-existing capture files.

5. Enhanced capture clear Command

The capture clear command now also removes remote capture files:

  • /tmp/trace.txt and /tmp/trace.txt.gz
  • /tmp/trace.pcap and /tmp/trace.pcap.gz
  • /tmp/dispatch.pcap and /tmp/dispatch.pcap.gz

@aritrbas aritrbas self-assigned this Jan 28, 2026
Copy link
Collaborator

@sknat sknat left a comment

Choose a reason for hiding this comment

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

Good catch, thanks for taking a stab at it !
A few comments inline

@aritrbas aritrbas force-pushed the abasu-fix-copy-fail branch from 92f6100 to 97a2b74 Compare January 30, 2026 02:07
Replace kubectl exec shell command with Kubernetes Go client API
(remotecommand) for streaming capture files. This improves error
handling and avoids shell-related issues.

Key changes:
- Use k8s.io/client-go/tools/remotecommand for file streaming instead
  of exec.Command with kubectl
- Add retry logic (3 attempts) for file transfer to handle transient
  network issues
- On transfer failure, print manual recovery instructions and preserve
  remote files for manual retrieval
- Clean up pre-existing capture files before starting new captures to
  prevent stale capture data
- Extend 'capture clear' command to also remove remote capture files
  (/tmp/trace.txt, /tmp/trace.pcap, /tmp/dispatch.pcap and .gz variants)

Signed-off-by: Aritra Basu <aritrbas@cisco.com>
@aritrbas aritrbas force-pushed the abasu-fix-copy-fail branch from 97a2b74 to f9be920 Compare January 30, 2026 02:37
@aritrbas aritrbas changed the title calicovppctl: avoid kubectl cp for large capture downloads by streaming remote gz calicovppctl: improve capture file transfer robustness Jan 30, 2026
Copy link
Collaborator

@sknat sknat left a comment

Choose a reason for hiding this comment

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

Awesome ! Many thanks 😄

@sknat sknat merged commit 7697aae into master Jan 30, 2026
5 checks passed
@sknat sknat deleted the abasu-fix-copy-fail branch January 30, 2026 16:49
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.

2 participants