mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-08 10:29:25 +00:00
client-go/rest: backoff with context support
The BackoffManager interface sleeps without considering the caller's context, i.e. cancellation is not supported. This alone is reason enough to deprecate it and to replace it with an interface that supports a context parameter. The other reason is that contextual logging needs that parameter. Kubernetes-commit: b15a1943d51adfb8c5e0185d58d25e038c3d6ade
This commit is contained in:
committed by
Kubernetes Publisher
parent
2b2015d460
commit
7aa9904196
@@ -106,7 +106,7 @@ type Request struct {
|
||||
warningHandler WarningHandlerWithContext
|
||||
|
||||
rateLimiter flowcontrol.RateLimiter
|
||||
backoff BackoffManager
|
||||
backoff BackoffManagerWithContext
|
||||
timeout time.Duration
|
||||
maxRetries int
|
||||
|
||||
@@ -136,7 +136,7 @@ type Request struct {
|
||||
|
||||
// NewRequest creates a new request helper object for accessing runtime.Objects on a server.
|
||||
func NewRequest(c *RESTClient) *Request {
|
||||
var backoff BackoffManager
|
||||
var backoff BackoffManagerWithContext
|
||||
if c.createBackoffMgr != nil {
|
||||
backoff = c.createBackoffMgr()
|
||||
}
|
||||
@@ -259,13 +259,27 @@ func (r *Request) Resource(resource string) *Request {
|
||||
}
|
||||
|
||||
// BackOff sets the request's backoff manager to the one specified,
|
||||
// or defaults to the stub implementation if nil is provided
|
||||
// or defaults to the stub implementation if nil is provided.
|
||||
//
|
||||
// Deprecated: BackoffManager.Sleep ignores the caller's context. Use BackOffWithContext and BackoffManagerWithContext instead.
|
||||
func (r *Request) BackOff(manager BackoffManager) *Request {
|
||||
if manager == nil {
|
||||
r.backoff = &NoBackoff{}
|
||||
return r
|
||||
}
|
||||
|
||||
r.backoff = &backoffManagerNopContext{BackoffManager: manager}
|
||||
return r
|
||||
}
|
||||
|
||||
// BackOffWithContext sets the request's backoff manager to the one specified,
|
||||
// or defaults to the stub implementation if nil is provided.
|
||||
func (r *Request) BackOffWithContext(manager BackoffManagerWithContext) *Request {
|
||||
if manager == nil {
|
||||
r.backoff = &NoBackoff{}
|
||||
return r
|
||||
}
|
||||
|
||||
r.backoff = manager
|
||||
return r
|
||||
}
|
||||
|
Reference in New Issue
Block a user