status

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFailedAssert = errors.New("type assertion failed")

Functions

func ConditionsEqual

func ConditionsEqual(prev, cur []metav1.Condition) bool

ConditionsEqual compares conditions. It doesn't check the last transition time of conditions.

func NewRetryUpdateFunc

func NewRetryUpdateFunc(
	getter controller.Getter,
	updater K8sUpdater,
	nsname types.NamespacedName,
	obj client.Object,
	logger logr.Logger,
	statusSetter Setter,
) func(ctx context.Context) (bool, error)

NewRetryUpdateFunc returns a function which will be used in wait.ExponentialBackoffWithContext. The function will attempt to Update a kubernetes resource and will be retried in wait.ExponentialBackoffWithContext if an error occurs. Exported for testing purposes.

wait.ExponentialBackoffWithContext will retry if this function returns nil as its error, which is what we want if we encounter an error from the functions we call. However, the linter will complain if we return nil if an error was found.

Note: this function is public because fake dependencies require us to test this function from the test package to avoid import cycles.

Types

type GroupUpdater

type GroupUpdater interface {
	UpdateGroup(ctx context.Context, name string, reqs ...UpdateRequest)
}

GroupUpdater updates statuses of groups of resources.

Note: this interface is created so that it that we can create a fake from it and use it in mode/static/handler_test.go (to avoid import cycles).

type K8sUpdater

type K8sUpdater interface {
	// Update is from client.StatusClient.SubResourceWriter.
	Update(ctx context.Context, obj client.Object, opts ...client.SubResourceUpdateOption) error
}

K8sUpdater updates a resource from the k8s API. It allows us to mock the client.Reader.Status.Update method.

type LeaderAwareGroupUpdater

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

LeaderAwareGroupUpdater updates statuses of groups of resources. Before it is enabled, it saves all requests. When it is enabled, it updates status using the saved requests. Note: it can only be enabled once. After it is enabled, it will not save requests anymore and update statuses immediately.

func NewLeaderAwareGroupUpdater

func NewLeaderAwareGroupUpdater(updater *Updater) *LeaderAwareGroupUpdater

NewLeaderAwareGroupUpdater creates a new LeaderAwareGroupUpdater.

func (*LeaderAwareGroupUpdater) Enable

func (u *LeaderAwareGroupUpdater) Enable(ctx context.Context)

Enable enables the LeaderAwareGroupUpdater, updating statuses using the saved requests.

func (*LeaderAwareGroupUpdater) UpdateGroup

func (u *LeaderAwareGroupUpdater) UpdateGroup(ctx context.Context, name string, reqs ...UpdateRequest)

UpdateGroup updates statuses of a group of resources.

type Setter

type Setter func(client.Object) (wasSet bool)

Setter is a function that sets the status of the passed resource. It returns true if the status was set, false otherwise. The status is not set when the status is already up-to-date.

type UpdateRequest

type UpdateRequest struct {
	ResourceType ngftypes.ObjectType
	Setter       Setter
	NsName       types.NamespacedName
}

UpdateRequest is a request to update the status of a resource.

type Updater

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

Updater updates the status of resources.

It has the following limitations:

(1) It is synchronous, which means the status reporter can slow down the event loop. Consider the following cases: (a) Sometimes the Gateway will need to update statuses of all resources it handles, which could be ~1000. Making 1000 status API calls sequentially will take time. (b) k8s API can become slow or even timeout. This will increase every update status API call. Making Updater asynchronous will prevent it from adding variable delays to the event loop. FIXME(pleshakov): https://github.com/nginx/nginx-gateway-fabric/issues/1014

(2) It doesn't clear the statuses of a resources that are no longer handled by the Gateway. For example, if an HTTPRoute resource no longer has the parentRef to the Gateway resources, the Gateway must update the status of the resource to remove the status about the removed parentRef. FIXME(pleshakov): https://github.com/nginx/nginx-gateway-fabric/issues/1015

(3) If another controllers changes the status of the Gateway/HTTPRoute resource so that the information set by our Gateway is removed, our Gateway will not restore the status until the EventLoop invokes the StatusUpdater as a result of processing some other new change to a resource(s). FIXME(pleshakov): https://github.com/nginx/nginx-gateway-fabric/issues/1813

func NewUpdater

func NewUpdater(c client.Client, logger logr.Logger) *Updater

NewUpdater creates a new Updater.

func (*Updater) Update

func (u *Updater) Update(ctx context.Context, reqs ...UpdateRequest)

Update updates the status of the resources from the requests.

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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