controller

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultInitialRequeueDelay = 1
	DefaultMaxRequeueDelay     = 30
)

Variables

This section is empty.

Functions

func CreateLockBucketIfNotExists

func CreateLockBucketIfNotExists(js nats.KeyValueManager, config *nats.KeyValueConfig) (nats.KeyValue, error)

CreateLockBucketIfNotExists binds to the existing KeyValue store if it has been created. If not created it will be created and the KeyValue store returned.

func SetRequeueDelay

func SetRequeueDelay(creationTime *int64) int64

SetRequeueDelay sets the requeue delay. It will be set to the initial delay value if the first requeue for the object. It will be set to double the previous delay if not the first, or the max delay if reached.

Types

type Reconciler

type Reconciler struct {
	// Reconciler name for display in logs.
	Name string

	// ObjectType is the name of the object that is being reconciled.
	ObjectType string

	// APIServer is the endpoint to reach Threeport REST API.
	// format: [protocol]://[hostname]:[port]
	APIServer string

	// APIClient is the HTTP client used to make requests to the Threeport API.
	APIClient *http.Client

	// JetStreamContext is the context for the NATS persistence layer.
	JetStreamContext nats.JetStreamContext

	// Sub is the NATS subscription used to get messages to reconcile.
	Sub *nats.Subscription

	// KeyValue is the NATS key-value store to be used for locking object
	// reconciliation.
	KeyValue nats.KeyValue

	// ControllerID is the unique identifier for each controller instance.
	ControllerID uuid.UUID

	// Log is the logger used to write logs.
	Log *logr.Logger

	// Shutdown is used to instruct a reconciler to shut down.
	Shutdown chan bool

	// ShutdownWait is the wait group that waits for reconcilers to finish
	// before shutting down the controller.
	ShutdownWait *sync.WaitGroup

	// EncryptionKey is the key used to encrypt and decrypt sensitive fields.
	EncryptionKey string
}

Reconciler contains the assets needed by reconcilers to recieve subscription messages and update the key-value store in order to lock reconciliation of objects.

func (*Reconciler) CheckLock

func (r *Reconciler) CheckLock(object v0.APIObject) (bool, bool)

CheckLock returns two bool values when checking for a lock on an object. The first value is whether the object is locked and the second is the status of the check. If the check was unsuccessful and unable to be clearly determined the second value will be false.

func (*Reconciler) Lock

func (r *Reconciler) Lock(object v0.APIObject) bool

Lock puts a lock on the given object so that no other reconcilation of this object is attempted until unlocked. Returns true if successful.

func (*Reconciler) PullMessage

func (r *Reconciler) PullMessage() *nats.Msg

PullMessage checks the queue for a message and returns it if there was a message to retrieve. It fetches only one message at a time and waits 20 seconds for a message to become available. If no message is returned in 20 seconds, it returns nil so the reconciler can reconnect to NATS.

func (*Reconciler) ReleaseLock

func (r *Reconciler) ReleaseLock(object v0.APIObject, lockReleased chan bool, msg *nats.Msg, reconcileSuccess bool) bool

ReleaseLock deletes the kev-value key so that future reconciliation will no longer be locked. Rerturns true if successful. If the lock fails to be released it will remain locked until the TTL expires in NATS.

func (*Reconciler) Requeue

func (r *Reconciler) Requeue(
	object v0.APIObject,
	requeueDelay int64,
	msg *nats.Msg,
)

Requeue waits for the delay duration and then sends the notifcation to the NATS server to trigger reconciliation.

func (*Reconciler) RequeueRaw

func (r *Reconciler) RequeueRaw(msg *nats.Msg)

RequeueRaw requeues a notification when the last one could not be unmarshalled properly or when a new notification payload could not be properly constructed. Since a backoff cannot be properly calculated we requeue after 10 sec.

func (*Reconciler) UnlockAndRequeue

func (r *Reconciler) UnlockAndRequeue(
	object v0.APIObject,
	requeueDelay int64,
	lockReleased chan bool,
	msg *nats.Msg,
)

UnlockAndRequeue releases the lock on the object and requeues reconciliation for that object.

type ReconcilerConfig

type ReconcilerConfig struct {
	// The name to use for the reconciler.
	Name string

	// The object type the reconciler will manage.
	ObjectType string

	// The function that will perform object reconciliation.
	ReconcileFunc func(r *Reconciler)

	// The maximum number of concurrent reconilation process to run.  This
	// number should be tuned (programatically) to be higher for reconcilers
	// that are called more often.  The tuning should be based on the length of
	// queue in NATS with a cap at some reasonable number that will keep CPU
	// consumption at a reasonable level for each individual controller.  The
	// proportion of activity among reconcilers within a controller is the key.
	ConcurrentReconciles int

	// The NATS Jetstream subject used for notifications to a reconciler
	NotifSubject string
}

ReconcilerConfig contains values needed to start new reconcilers in controllers.

Jump to

Keyboard shortcuts

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