diff --git a/go.mod b/go.mod index eddd34f39..dec4e7d3c 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.25.0 require ( github.com/Masterminds/sprig/v3 v3.3.0 - github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2 github.com/evanphx/json-patch v5.9.11+incompatible github.com/gogo/protobuf v1.3.2 github.com/json-iterator/go v1.1.12 diff --git a/go.sum b/go.sum index 86e85a7d3..dd8e68b5a 100644 --- a/go.sum +++ b/go.sum @@ -16,8 +16,6 @@ github.com/PuerkitoBio/purell v1.2.1 h1:QsZ4TjvwiMpat6gBCBxEQI0rcS9ehtkKtSpiUnd9 github.com/PuerkitoBio/purell v1.2.1/go.mod h1:ZwHcC/82TOaovDi//J/804umJFFmbOHPngi8iYYv/Eo= github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI= github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g= -github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2 h1:7Ip0wMmLHLRJdrloDxZfhMm0xrLXZS8+COSu2bXmEQs= -github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= diff --git a/pkg/restic/commands.go b/pkg/restic/commands.go index 0d54e5fa5..cb5ca5d07 100644 --- a/pkg/restic/commands.go +++ b/pkg/restic/commands.go @@ -17,6 +17,7 @@ limitations under the License. package restic import ( + "bytes" "encoding/json" "errors" "fmt" @@ -30,7 +31,6 @@ import ( "stash.appscode.dev/apimachinery/apis/stash/v1alpha1" - "github.com/armon/circbuf" "k8s.io/klog/v2" storage "kmodules.xyz/objectstore-api/api/v1" ) @@ -464,11 +464,9 @@ func (w *ResticWrapper) appendCaCertFlag(args []any) []any { func (w *ResticWrapper) run(commands ...Command) ([]byte, error) { // write std errors into os.Stderr and buffer - errBuff, err := circbuf.NewBuffer(256) - if err != nil { - return nil, err - } - w.sh.Stderr = io.MultiWriter(os.Stderr, errBuff) + var err error + var errBuff bytes.Buffer + w.sh.Stderr = io.MultiWriter(os.Stderr, &errBuff) for _, cmd := range commands { if cmd.Name == ResticCMD { diff --git a/pkg/restic/retry.go b/pkg/restic/retry.go index 9b9e40f85..e5f4722b8 100644 --- a/pkg/restic/retry.go +++ b/pkg/restic/retry.go @@ -50,7 +50,6 @@ func NewRetryConfig() *RetryConfig { return false } combined := strings.ToLower(err.Error() + " " + output) - klog.Infoln("Combined output: " + combined) for _, pattern := range retryablePatterns { if strings.Contains(combined, strings.ToLower(pattern)) { return true @@ -64,7 +63,7 @@ func NewRetryConfig() *RetryConfig { func (rc *RetryConfig) RunWithRetry(ctx context.Context, execFunc func() ([]byte, error)) ([]byte, error) { var output []byte var lastErr error - attempts := 0 + attempts := 1 err := wait.PollUntilContextCancel( ctx, @@ -72,24 +71,23 @@ func (rc *RetryConfig) RunWithRetry(ctx context.Context, execFunc func() ([]byte true, // Run immediately on first call func(ctx context.Context) (bool, error) { // Stop if max retries reached - if attempts >= rc.MaxRetries { + if attempts > rc.MaxRetries { return false, fmt.Errorf("max retries reached") } output, lastErr = execFunc() + klog.Infof("Attempt #%d: retrying in %v", attempts, rc.Delay) + klog.Infof("Attempt #%d error: %v", attempts, lastErr) + klog.Infof("Attempt #%d output: %s", attempts, string(output)) + if !rc.ShouldRetry(lastErr, string(output)) { return true, nil } - klog.Infoln("Retrying command after error", - "attempt", attempts, - "maxRetries", rc.MaxRetries, - "error", fmt.Sprintf("%s %s", lastErr, string(output))) attempts++ return false, nil }, ) if err != nil { - return nil, fmt.Errorf("failed after %d attempts: %w", attempts, lastErr) + return output, fmt.Errorf("failed after %d attempts: %w", attempts, lastErr) } - return output, lastErr } diff --git a/vendor/github.com/armon/circbuf/.gitignore b/vendor/github.com/armon/circbuf/.gitignore deleted file mode 100644 index 00268614f..000000000 --- a/vendor/github.com/armon/circbuf/.gitignore +++ /dev/null @@ -1,22 +0,0 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe diff --git a/vendor/github.com/armon/circbuf/LICENSE b/vendor/github.com/armon/circbuf/LICENSE deleted file mode 100644 index 106569e54..000000000 --- a/vendor/github.com/armon/circbuf/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2013 Armon Dadgar - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/github.com/armon/circbuf/README.md b/vendor/github.com/armon/circbuf/README.md deleted file mode 100644 index f2e356b8d..000000000 --- a/vendor/github.com/armon/circbuf/README.md +++ /dev/null @@ -1,28 +0,0 @@ -circbuf -======= - -This repository provides the `circbuf` package. This provides a `Buffer` object -which is a circular (or ring) buffer. It has a fixed size, but can be written -to infinitely. Only the last `size` bytes are ever retained. The buffer implements -the `io.Writer` interface. - -Documentation -============= - -Full documentation can be found on [Godoc](http://godoc.org/github.com/armon/circbuf) - -Usage -===== - -The `circbuf` package is very easy to use: - -```go -buf, _ := NewBuffer(6) -buf.Write([]byte("hello world")) - -if string(buf.Bytes()) != " world" { - panic("should only have last 6 bytes!") -} - -``` - diff --git a/vendor/github.com/armon/circbuf/circbuf.go b/vendor/github.com/armon/circbuf/circbuf.go deleted file mode 100644 index de3cb94a3..000000000 --- a/vendor/github.com/armon/circbuf/circbuf.go +++ /dev/null @@ -1,92 +0,0 @@ -package circbuf - -import ( - "fmt" -) - -// Buffer implements a circular buffer. It is a fixed size, -// and new writes overwrite older data, such that for a buffer -// of size N, for any amount of writes, only the last N bytes -// are retained. -type Buffer struct { - data []byte - size int64 - writeCursor int64 - written int64 -} - -// NewBuffer creates a new buffer of a given size. The size -// must be greater than 0. -func NewBuffer(size int64) (*Buffer, error) { - if size <= 0 { - return nil, fmt.Errorf("Size must be positive") - } - - b := &Buffer{ - size: size, - data: make([]byte, size), - } - return b, nil -} - -// Write writes up to len(buf) bytes to the internal ring, -// overriding older data if necessary. -func (b *Buffer) Write(buf []byte) (int, error) { - // Account for total bytes written - n := len(buf) - b.written += int64(n) - - // If the buffer is larger than ours, then we only care - // about the last size bytes anyways - if int64(n) > b.size { - buf = buf[int64(n)-b.size:] - } - - // Copy in place - remain := b.size - b.writeCursor - copy(b.data[b.writeCursor:], buf) - if int64(len(buf)) > remain { - copy(b.data, buf[remain:]) - } - - // Update location of the cursor - b.writeCursor = ((b.writeCursor + int64(len(buf))) % b.size) - return n, nil -} - -// Size returns the size of the buffer -func (b *Buffer) Size() int64 { - return b.size -} - -// TotalWritten provides the total number of bytes written -func (b *Buffer) TotalWritten() int64 { - return b.written -} - -// Bytes provides a slice of the bytes written. This -// slice should not be written to. -func (b *Buffer) Bytes() []byte { - switch { - case b.written >= b.size && b.writeCursor == 0: - return b.data - case b.written > b.size: - out := make([]byte, b.size) - copy(out, b.data[b.writeCursor:]) - copy(out[b.size-b.writeCursor:], b.data[:b.writeCursor]) - return out - default: - return b.data[:b.writeCursor] - } -} - -// Reset resets the buffer so it has no content. -func (b *Buffer) Reset() { - b.writeCursor = 0 - b.written = 0 -} - -// String returns the contents of the buffer as a string -func (b *Buffer) String() string { - return string(b.Bytes()) -} diff --git a/vendor/modules.txt b/vendor/modules.txt index 7499b3952..f7c617fe1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -26,9 +26,6 @@ github.com/PuerkitoBio/purell # github.com/antlr4-go/antlr/v4 v4.13.0 ## explicit; go 1.20 github.com/antlr4-go/antlr/v4 -# github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2 -## explicit -github.com/armon/circbuf # github.com/beorn7/perks v1.0.1 ## explicit; go 1.11 github.com/beorn7/perks/quantile