mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-03-10 09:29:30 +00:00
Several packages are only used while running the e2e suite. These packages are less important to update, as the they can not influence the final executable that is part of the Ceph-CSI container-image. By moving these dependencies out of the main Ceph-CSI go.mod, it is easier to identify if a reported CVE affects Ceph-CSI, or only the testing (like most of the Kubernetes CVEs). Signed-off-by: Niels de Vos <ndevos@ibm.com>
39 lines
724 B
Go
39 lines
724 B
Go
package backoff
|
|
|
|
import "time"
|
|
|
|
/*
|
|
WithMaxRetries creates a wrapper around another BackOff, which will
|
|
return Stop if NextBackOff() has been called too many times since
|
|
the last time Reset() was called
|
|
|
|
Note: Implementation is not thread-safe.
|
|
*/
|
|
func WithMaxRetries(b BackOff, max uint64) BackOff {
|
|
return &backOffTries{delegate: b, maxTries: max}
|
|
}
|
|
|
|
type backOffTries struct {
|
|
delegate BackOff
|
|
maxTries uint64
|
|
numTries uint64
|
|
}
|
|
|
|
func (b *backOffTries) NextBackOff() time.Duration {
|
|
if b.maxTries == 0 {
|
|
return Stop
|
|
}
|
|
if b.maxTries > 0 {
|
|
if b.maxTries <= b.numTries {
|
|
return Stop
|
|
}
|
|
b.numTries++
|
|
}
|
|
return b.delegate.NextBackOff()
|
|
}
|
|
|
|
func (b *backOffTries) Reset() {
|
|
b.numTries = 0
|
|
b.delegate.Reset()
|
|
}
|