Skip to content

Commit

Permalink
Merge pull request #108748 from atiratree/kube-107333-fix-cp-retries
Browse files Browse the repository at this point in the history
resume kubectl cp with tail when --retries is negative
  • Loading branch information
k8s-ci-robot committed Mar 28, 2022
2 parents 4d45ae5 + a81f674 commit 6c67869
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions staging/src/k8s.io/kubectl/pkg/cmd/cp/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func (t *TarPipe) initReadFrom(n uint64) {
Command: []string{"tar", "cf", "-", t.src.File.String()},
Executor: &exec.DefaultRemoteExecutor{},
}
if t.o.MaxTries > 0 {
if t.o.MaxTries != 0 {
options.Command = []string{"sh", "-c", fmt.Sprintf("tar cf - %s | tail -c+%d", t.src.File, n)}
}

Expand All @@ -387,10 +387,10 @@ func (t *TarPipe) Read(p []byte) (n int, err error) {
n, err = t.reader.Read(p)
if err != nil {
if t.o.MaxTries < 0 || t.retries < t.o.MaxTries {
t.retries++
fmt.Printf("Resuming copy at %d bytes, retry %d/%d\n", t.bytesRead, t.retries, t.o.MaxTries)
t.initReadFrom(t.bytesRead + 1)
err = nil
t.retries++
} else {
fmt.Printf("Dropping out copy after %d retries\n", t.retries)
}
Expand Down

0 comments on commit 6c67869

Please sign in to comment.