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
make kubectl cp resume on transfer error #104792
Conversation
34df723
to
d8b5e68
Compare
}, | ||
|
||
// TODO: Improve error messages by first testing if 'tar' is present in the container? | ||
Command: []string{"tar", "cf", "-", src.File}, | ||
Command: []string{"sh", "-c", fmt.Sprintf("tar cf - %s | tail -c+%d", t.src.File, n)}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how related is to this, but Ben and I had to spend a lot of time to make it work flawlessly, to stream a tar over a network pipe, check if you can find something useful for this https://github.com/kubernetes-sigs/kind/blob/b6bc112522651d98c81823df56b7afa511459a3b/pkg/cluster/internal/logs/logs.go#L39-L60
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah nice trick the shell invocation to have access to pipes...
I'm using tail
to skip the first n bytes of the archive when resuming, however the best one is the pattern where I use a reader of a reader to catch errors and keep track of the transferred data to reconnect without untarAll
noticing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is only valid if the source has not changed during the re connection, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, in this respect I don't improve on current implementation - however if your use case is to retrieve GBs of backups, usability is much higher
I might add a flag to set a max retry, but for the moment I'm waiting for some feedback on the issue with a prebuilt binary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For backwards compatibility and when not using retries (the proposed default, above) please use only tar, since tail isn't required in that case.
/assign @deads2k |
Hey @matthyx. Retrying seems to work perfectly, though it fails after fetching 2362411520 bytes with error |
/assign @soltysh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks mostly good, please address the bits I've mentioned and ping me on slack to get it included in 1.23.
@@ -155,6 +156,7 @@ func NewCmdCp(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.C | |||
} | |||
cmdutil.AddContainerVarFlags(cmd, &o.Container, o.Container) | |||
cmd.Flags().BoolVarP(&o.NoPreserve, "no-preserve", "", false, "The copied file/directory's ownership and permissions will not be preserved in the container") | |||
cmd.Flags().IntVarP(&o.MaxTries, "retries", "t", 20, "Set number of retries to complete a copy operation from a container. Specify 0 to disable or any negative value for infinite retrying. The default is 20.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer this to be opt-in for starters, so default to be 0, and don't use -t
as the shorthand, since that's being used elsewhere as shorthand for --tty
so that might be confusing here a bit.
}, | ||
|
||
// TODO: Improve error messages by first testing if 'tar' is present in the container? | ||
Command: []string{"tar", "cf", "-", src.File}, | ||
Command: []string{"sh", "-c", fmt.Sprintf("tar cf - %s | tail -c+%d", t.src.File, n)}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For backwards compatibility and when not using retries (the proposed default, above) please use only tar, since tail isn't required in that case.
/triage accepted |
Thanks @soltysh updated the PR accordingly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: matthyx, soltysh The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind feature
What this PR does / why we need it:
Allows
kubectl cp
transfers to continue despite network errors.Which issue(s) this PR fixes:
Fixes #60140
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: