Documentation
¶
Overview ¶
Example (ControllerUsage) ¶
This example shows how to use the SmartRequeue package in a Kubernetes controller.
package main
import (
"fmt"
"time"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/openmcp-project/controller-utils/pkg/controller/smartrequeue"
)
func main() {
// Create a store with min and max requeue intervals
store := smartrequeue.NewStore(5*time.Second, 10*time.Minute, 2.0)
// In your controller's Reconcile function:
reconcileFunction := func(_ ctrl.Request) (ctrl.Result, error) {
// Create a dummy object representing what you'd get from the client
var obj client.Object // In real code: Get this from the client
// Get the Entry for this specific object
entry := store.For(obj)
// Determine the state of the external resource...
inProgress := false // This would be determined by your logic
errOccurred := false // This would be determined by your logic
// nolint:gocritic
if errOccurred {
// Handle error case
err := fmt.Errorf("something went wrong")
return entry.Error(err)
} else if inProgress {
// Resource is changing - check back soon
return entry.Reset()
} else {
// Resource is stable - gradually back off
return entry.Backoff()
}
}
// Call the reconcile function
_, _ = reconcileFunction(ctrl.Request{})
}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
Entry is used to manage the requeue logic for a specific object. It holds the next duration to requeue and the store it belongs to.
func FromContext ¶
FromContext retrieves the Entry from the context, if it exists. Returns nil if no Entry is found in the context.
func (*Entry) Backoff ¶
Backoff returns a Result and increments the interval for the next iteration.
func (*Entry) Error ¶
Error resets the duration to the minInterval and returns an empty Result and the error so that the controller-runtime can handle the exponential backoff for errors.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is used to manage requeue entries for different objects. It holds a map of entries indexed by a key that uniquely identifies the object.
func NewStore ¶
NewStore creates a new Store with the specified minimum and maximum intervals and a multiplier for the exponential backoff logic.