status

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConditionsEqual added in v1.3.0

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 added in v1.3.0

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 added in v1.3.0

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 added in v1.3.0

func NewLeaderAwareGroupUpdater(updater *Updater) *LeaderAwareGroupUpdater

NewLeaderAwareGroupUpdater creates a new LeaderAwareGroupUpdater.

func (*LeaderAwareGroupUpdater) Enable added in v1.3.0

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

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

func (*LeaderAwareGroupUpdater) UpdateGroup added in v1.3.0

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

UpdateGroup updates statuses of a group of resources.

type Setter added in v1.3.0

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 added in v1.3.0

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/nginxinc/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/nginxinc/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/nginxinc/nginx-gateway-fabric/issues/1813

func NewUpdater

func NewUpdater(client 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