retry

package
v0.0.0-...-0a2bef2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const MaxFailedAttempts = 15 // same value used for the services level-driven controller
View Source
const RetryObjInterval = 30 * time.Second

Variables

This section is empty.

Functions

func CheckRetryObj

func CheckRetryObj(key string, r *RetryFramework) bool

func CheckRetryObjectEventually

func CheckRetryObjectEventually(key string, shouldExist bool, r *RetryFramework)

func CheckRetryObjectEventuallyWrapped

func CheckRetryObjectEventuallyWrapped(g gomega.Gomega, key string, shouldExist bool, r *RetryFramework)

same as CheckRetryObjectEventually, but takes an input gomega argument from which the assertion is made. This is to be used from within an Eventually block.

func CheckRetryObjectMultipleFieldsEventually

func CheckRetryObjectMultipleFieldsEventually(
	key string,
	r *RetryFramework,
	expectedParams ...types.GomegaMatcher)

CheckRetryObjectMultipleFieldsEventually verifies that eventually the oldObj, newObj, config and failedAttemptsfields fields all satisfy the input conditions expectedParams, given in the same order. In order not to check any of these four fields, the corresponding input type.GomegaMatcher must be set to nil.

func DeleteRetryObj

func DeleteRetryObj(key string, r *RetryFramework)

func GetConfigFromRetryObj

func GetConfigFromRetryObj(key string, r *RetryFramework) interface{}

func GetNewObjFieldFromRetryObj

func GetNewObjFieldFromRetryObj(key string, r *RetryFramework) interface{}

func GetOldObjFromRetryObj

func GetOldObjFromRetryObj(key string, r *RetryFramework) interface{}

func GetResourceKey

func GetResourceKey(obj interface{}) (string, error)

Given an object and its type, it returns the key for this object and an error if the key retrieval failed. For all namespaced resources, the key will be namespace/name. For resource types without a namespace, the key will be the object name itself. obj must be a pointer to an API type.

func GetRetryObj

func GetRetryObj(key string, r *RetryFramework) (*retryObjEntry, bool)

func InitRetryObjWithAdd

func InitRetryObjWithAdd(obj interface{}, key string, r *RetryFramework)

func RetryObjsLen

func RetryObjsLen(r *RetryFramework) int

func SetFailedAttemptsCounterForTestingOnly

func SetFailedAttemptsCounterForTestingOnly(key string, val uint8, r *RetryFramework)

func SetNewObjFieldInRetryObj

func SetNewObjFieldInRetryObj(key string, r *RetryFramework, newObj interface{}) bool

func SetRetryObjWithNoBackoff

func SetRetryObjWithNoBackoff(key string, r *RetryFramework)

Types

type DefaultEventHandler

type DefaultEventHandler struct{}

DefaultEventHandler has the default implementations for some EventHandler methods, that are not required for every handler

func (*DefaultEventHandler) AreResourcesEqual

func (h *DefaultEventHandler) AreResourcesEqual(obj1, obj2 interface{}) (bool, error)

func (*DefaultEventHandler) GetInternalCacheEntry

func (h *DefaultEventHandler) GetInternalCacheEntry(obj interface{}) interface{}

func (*DefaultEventHandler) IsObjectInTerminalState

func (h *DefaultEventHandler) IsObjectInTerminalState(obj interface{}) bool

func (*DefaultEventHandler) IsResourceScheduled

func (h *DefaultEventHandler) IsResourceScheduled(obj interface{}) bool

func (*DefaultEventHandler) RecordAddEvent

func (h *DefaultEventHandler) RecordAddEvent(obj interface{})

func (*DefaultEventHandler) RecordDeleteEvent

func (h *DefaultEventHandler) RecordDeleteEvent(obj interface{})

func (*DefaultEventHandler) RecordErrorEvent

func (h *DefaultEventHandler) RecordErrorEvent(obj interface{}, reason string, err error)

func (*DefaultEventHandler) RecordSuccessEvent

func (h *DefaultEventHandler) RecordSuccessEvent(obj interface{})

func (*DefaultEventHandler) RecordUpdateEvent

func (h *DefaultEventHandler) RecordUpdateEvent(obj interface{})

func (*DefaultEventHandler) SyncFunc

func (h *DefaultEventHandler) SyncFunc([]interface{}) error

type EventHandler

type EventHandler interface {
	AddResource(obj interface{}, fromRetryLoop bool) error
	UpdateResource(oldObj, newObj interface{}, inRetryCache bool) error
	DeleteResource(obj, cachedObj interface{}) error
	SyncFunc([]interface{}) error

	// auxiliary functions needed in the retry logic
	GetResourceFromInformerCache(key string) (interface{}, error)
	AreResourcesEqual(obj1, obj2 interface{}) (bool, error)
	GetInternalCacheEntry(obj interface{}) interface{}
	IsResourceScheduled(obj interface{}) bool
	IsObjectInTerminalState(obj interface{}) bool

	// functions related to metrics and events
	RecordAddEvent(obj interface{})
	RecordUpdateEvent(obj interface{})
	RecordDeleteEvent(obj interface{})
	RecordSuccessEvent(obj interface{})
	RecordErrorEvent(obj interface{}, reason string, err error)
}

type ResourceHandler

type ResourceHandler struct {
	// HasUpdateFunc is true if an update event for this resource type is implemented as an
	// update action; it is false, if instead it is implemented as a delete on the old obj and
	// an add on the new one.
	HasUpdateFunc          bool
	NeedsUpdateDuringRetry bool
	ObjType                reflect.Type
	EventHandler
}

type RetryFramework

type RetryFramework struct {
	ResourceHandler *ResourceHandler
	// contains filtered or unexported fields
}

func NewRetryFramework

func NewRetryFramework(
	stopChan <-chan struct{}, doneWg *sync.WaitGroup,
	watchFactory *factory.WatchFactory,
	resourceHandler *ResourceHandler) *RetryFramework

NewRetryFramework returns a new RetryFramework instance, essential for the whole retry logic. It returns a new struct packed with the desired input parameters and with its function attributes pre-filled with default code. Clients of this pkg (ovnk master, ovnk node) will have to override the functions in the returned struct with the desired per-resource logic.

func (*RetryFramework) AddRetryObjWithAddNoBackoff

func (r *RetryFramework) AddRetryObjWithAddNoBackoff(obj interface{}) error

AddRetryObjWithAddNoBackoff adds an object to be retried immediately for add. It will lock the key, create or update retryObject, and unlock the key

func (*RetryFramework) DeleteRetryObj

func (r *RetryFramework) DeleteRetryObj(lockedKey string)

func (*RetryFramework) DoWithLock

func (r *RetryFramework) DoWithLock(key string, f func(key string))

func (*RetryFramework) InitRetryObjWithDelete

func (r *RetryFramework) InitRetryObjWithDelete(obj interface{}, lockedKey string, config interface{}, noRetryAdd bool) *retryObjEntry

InitRetryObjWithDelete creates a retry entry for an object that is being deleted, so that, if it fails, the delete can be potentially retried later. When applied to pods, we include the config object as well in case the namespace is removed and the object is orphaned from the namespace. The noRetryAdd boolean argument is to indicate whether to retry for addition

func (*RetryFramework) RequestRetryObjs

func (r *RetryFramework) RequestRetryObjs()

RequestRetryFramework allows a caller to immediately request to iterate through all objects that are in the retry cache. This will ignore any outstanding time wait/backoff state

func (*RetryFramework) WatchResource

func (r *RetryFramework) WatchResource() (*factory.Handler, error)

func (*RetryFramework) WatchResourceFiltered

func (r *RetryFramework) WatchResourceFiltered(namespaceForFilteredHandler string, labelSelectorForFilteredHandler labels.Selector) (*factory.Handler, error)

WatchResourceFiltered starts the watching of a resource type, manages its retry entries and calls back the appropriate handler logic. It also starts a goroutine that goes over all retry objects periodically or when explicitly requested. Note: when applying WatchResourceFiltered to a new resource type, the appropriate resource-specific logic must be added to the the different methods it calls.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL