expect

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

ControlleeKeyFunc is a key function used to create Controllee keys that are used to uniquely identify expectations that are stored in the expectations store.

Functions

This section is empty.

Types

type ControlleeExpectations

type ControlleeExpectations struct {
	// contains filtered or unexported fields
}

ControlleeExpectations tracks expectations for the reconciled/controlled resource. It will track the object UIDs for expected creations and deletions. NOTE: When creating a resource, UID of an object is only available post the Create call. It is expected that the consumers will capture the expectations after every Create call. For deletes the UID is already available before the call to delete is made.

type ExpectationsStore

type ExpectationsStore struct {
	cache.Store
	// contains filtered or unexported fields
}

ExpectationsStore is a cache where add and delete expectations are captured. `controller-runtime` serves the read requests from an informer cache and will query the kube-apiserver during startup or resyncs. The informer cache does not provide read-your-writes consistency which leads to stale caches. Informer caches are eventually consistent but if your controller gets quick events then it is possible that the controller operates on a stale state, thus leading to side effects which could include creation of adding resource replicas or deletion of more then desired replicas of a resource. NOTE: Expectations is an existing pattern already used in kubernetes. See [ControllerExpectationsInterface]: https://github.com/kubernetes/kubernetes/blob/e6161070d4416f6d9c1ac9961029fdceef5c9286/pkg/controller/controller_utils.go#L157 where expectations are used to provide a barrier when reconciling resources. If the previous expectations are not fulfilled, or they have not yet expired no further resource creation/deletion will be done. This implementation takes inspiration from it but takes a different take on how resources are tracked. We propose to not use expectations as a barrier but only as an additional in-memory store of expectations that help the reconciler correctly compute the desired number of creates or deletes. It also attempts to resolve the 2 issues that are listed in https://github.com/kubernetes/kubernetes/issues/129795#issuecomment-2657716713

func NewExpectationsStore

func NewExpectationsStore() *ExpectationsStore

NewExpectationsStore creates a new expectations store.

func (*ExpectationsStore) DeleteExpectations

func (s *ExpectationsStore) DeleteExpectations(logger logr.Logger, controlleeKey string) error

DeleteExpectations removes all expectations stored against a controlleeKey from the store.

func (*ExpectationsStore) ExpectCreations

func (s *ExpectationsStore) ExpectCreations(logger logr.Logger, controlleeKey string, uids ...types.UID) error

ExpectCreations records resource creation expectations for uids for a controlled resource identified by a controlleeKey.

func (*ExpectationsStore) ExpectDeletions

func (s *ExpectationsStore) ExpectDeletions(logger logr.Logger, controlleeKey string, uids ...types.UID) error

ExpectDeletions records resource deletion expectations for uids for a controlled resource identified by a controlleeKey.

func (*ExpectationsStore) GetCreateExpectations

func (s *ExpectationsStore) GetCreateExpectations(controlleeKey string) []types.UID

GetCreateExpectations is a convenience method which gives a slice of resource UIDs for which creation has not yet been synced in the informer cache.

func (*ExpectationsStore) GetDeleteExpectations

func (s *ExpectationsStore) GetDeleteExpectations(controlleeKey string) []types.UID

GetDeleteExpectations is a convenience method which gives a slice of resource UIDs for which deletion has not yet been synced in the informer cache.

func (*ExpectationsStore) GetExpectations

func (s *ExpectationsStore) GetExpectations(controlleeKey string) (*ControlleeExpectations, bool, error)

GetExpectations gets the recorded expectations against a controlleeKey.

func (*ExpectationsStore) HasDeleteExpectation

func (s *ExpectationsStore) HasDeleteExpectation(controlleeKey string, uid types.UID) bool

HasDeleteExpectation returns true if a delete expectation has been recorded for the controlleeKey and the target resource UID.

func (*ExpectationsStore) ObserveDeletions

func (s *ExpectationsStore) ObserveDeletions(logger logr.Logger, controlleeKey string, uids ...types.UID)

ObserveDeletions lowers the delete expectations removing the uids passed.

func (*ExpectationsStore) SyncExpectations

func (s *ExpectationsStore) SyncExpectations(controlleeKey string, existingNonTerminatingUIDs []types.UID, existingTerminatingUIDs []types.UID)

SyncExpectations allows the expectations store to sync up expectations against the existingNonTerminatingUIDs. Informer caches are either updated via watch events or via an explicit sync to the kube-apiserver. Thus, an informer cache is a single source of truth. Consumers while computing pending work anyway need to make a LIST call which will most probably hit the informer cache. This function removes the need to have `ObserveCreation` and there is no longer a need to reduce the expectations from within the event handlers. This function takes in an existing resource type.UIDs as seen by the informer cache and removes the expectations that are no longer valid in the store.

Jump to

Keyboard shortcuts

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