status

package
v2.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UpdateAll means to update statuses of all Gateway API resources.
	UpdateAll = iota
	// UpdateGateway means to just update the status of the Gateway resource.
	UpdateGateway
)

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 ControlPlaneUpdateResult

type ControlPlaneUpdateResult struct {
	// Error is the error that occurred during the update.
	Error error
}

ControlPlaneUpdateResult describes the result of a control plane update.

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 controller/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 Queue

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

Queue represents a queue with unlimited size.

func NewQueue

func NewQueue() *Queue

NewQueue returns a new Queue object.

func (*Queue) Dequeue

func (q *Queue) Dequeue(ctx context.Context) *QueueObject

Dequeue removes and returns the front item from the queue. It blocks if the queue is empty or when the context is canceled.

func (*Queue) Enqueue

func (q *Queue) Enqueue(item *QueueObject)

Enqueue adds an item to the queue and notifies any blocked readers.

type QueueObject

type QueueObject struct {
	// GatewayService is the Gateway Service that was updated. When set, UpdateType should be UpdateGateway.
	// Set by the provisioner
	GatewayService *corev1.Service
	Error          error
	Deployment     types.NamespacedName
	UpdateType     UpdateType
}

QueueObject is the object to be passed to the queue for status updates.

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.

func PrepareBackendTLSPolicyRequests

func PrepareBackendTLSPolicyRequests(
	policies map[types.NamespacedName]*graph.BackendTLSPolicy,
	transitionTime metav1.Time,
	gatewayCtlrName string,
) []UpdateRequest

PrepareBackendTLSPolicyRequests prepares status UpdateRequests for the given BackendTLSPolicies.

func PrepareGatewayClassRequests

func PrepareGatewayClassRequests(
	gc *graph.GatewayClass,
	ignoredGwClasses map[types.NamespacedName]*v1.GatewayClass,
	transitionTime metav1.Time,
) []UpdateRequest

PrepareGatewayClassRequests prepares status UpdateRequests for the given GatewayClasses.

func PrepareGatewayRequests

func PrepareGatewayRequests(
	gateway *graph.Gateway,
	transitionTime metav1.Time,
	gwAddresses []v1.GatewayStatusAddress,
	nginxReloadRes graph.NginxReloadResult,
) []UpdateRequest

PrepareGatewayRequests prepares status UpdateRequests for the given Gateways.

func PrepareNGFPolicyRequests

func PrepareNGFPolicyRequests(
	policies map[graph.PolicyKey]*graph.Policy,
	transitionTime metav1.Time,
	gatewayCtlrName string,
) []UpdateRequest

func PrepareNginxGatewayStatus

func PrepareNginxGatewayStatus(
	nginxGateway *ngfAPI.NginxGateway,
	transitionTime metav1.Time,
	cpUpdateRes ControlPlaneUpdateResult,
) *UpdateRequest

PrepareNginxGatewayStatus prepares a status UpdateRequest for the given NginxGateway. If the NginxGateway is nil, it returns nil.

func PrepareRouteRequests

func PrepareRouteRequests(
	l4routes map[graph.L4RouteKey]*graph.L4Route,
	routes map[graph.RouteKey]*graph.L7Route,
	transitionTime metav1.Time,
	gatewayCtlrName string,
) []UpdateRequest

PrepareRouteRequests prepares status UpdateRequests for the given Routes.

func PrepareSnippetsFilterRequests

func PrepareSnippetsFilterRequests(
	snippetsFilters map[types.NamespacedName]*graph.SnippetsFilter,
	transitionTime metav1.Time,
	gatewayCtlrName string,
) []UpdateRequest

PrepareSnippetsFilterRequests prepares status UpdateRequests for the given SnippetsFilters.

type UpdateType

type UpdateType int

UpdateType is the type of status update to perform.

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