Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DeleteEvent ¶
type DeleteEvent struct { // Type is the resource type. For example, if the event is for *v1.HTTPRoute, pass &v1.HTTPRoute{} as Type. Type ngftypes.ObjectType // NamespacedName is the namespace & name of the deleted resource. NamespacedName types.NamespacedName }
DeleteEvent representing deleting a resource.
type EachListItemFunc ¶
EachListItemFunc lists each item of a client.ObjectList. It is from k8s.io/apimachinery/pkg/api/meta.
type EventBatch ¶
type EventBatch []interface{}
EventBatch is a batch of events to be handled at once.
type EventHandler ¶
type EventHandler interface { // HandleEventBatch handles a batch of events. // EventBatch can include duplicated events. HandleEventBatch(ctx context.Context, logger logr.Logger, batch EventBatch) }
EventHandler handles events.
type EventLoop ¶
type EventLoop struct {
// contains filtered or unexported fields
}
EventLoop is the main event loop of the Gateway. It handles events coming through the event channel.
When a new event comes, there are two cases: - If there is no event(s) currently being handled, the new event is handled immediately. - Otherwise, the new event will be saved for later handling. All saved events will be handled after the handling of the current event(s) finishes. Multiple saved events will be handled at once -- they will be batched.
Batching is needed because handling an event (or multiple events at once) will typically result in reloading NGINX, which is an operation we want to minimize for the following reasons: (1) A reload takes time - at least 200ms. The time depends on the size of the configuration, the number of TLS certs, and the number of available CPU cycles. (2) A reload can have side-effects for data plane traffic. FIXME(pleshakov): better document the side effects and how to prevent and mitigate them. So when the EventLoop have 100 saved events, it is better to process them at once rather than one by one. https://github.com/nginxinc/nginx-gateway-fabric/issues/551
func NewEventLoop ¶
func NewEventLoop( eventCh <-chan interface{}, logger logr.Logger, handler EventHandler, preparer FirstEventBatchPreparer, ) *EventLoop
NewEventLoop creates a new EventLoop.
type FirstEventBatchPreparer ¶
type FirstEventBatchPreparer interface { // Prepare prepares the first event batch. Prepare(ctx context.Context) (EventBatch, error) }
FirstEventBatchPreparer prepares the first batch of events to be processed by the EventHandler. The first batch includes the UpsertEvents for all relevant resources in the cluster.
type FirstEventBatchPreparerImpl ¶
type FirstEventBatchPreparerImpl struct {
// contains filtered or unexported fields
}
FirstEventBatchPreparerImpl is an implementation of FirstEventBatchPreparer.
func NewFirstEventBatchPreparerImpl ¶
func NewFirstEventBatchPreparerImpl( reader Reader, objects []client.Object, objectLists []client.ObjectList, ) *FirstEventBatchPreparerImpl
NewFirstEventBatchPreparerImpl creates a new FirstEventBatchPreparerImpl. objects and objectList specify which resources will be included in the first batch. For each object from objects, FirstEventBatchPreparerImpl will get the corresponding resource from the reader. The object must specify its namespace (if any) and name. For each list from objectLists, FirstEventBatchPreparerImpl will list the resources of the corresponding type from the reader.
func (*FirstEventBatchPreparerImpl) Prepare ¶
func (p *FirstEventBatchPreparerImpl) Prepare(ctx context.Context) (EventBatch, error)
func (*FirstEventBatchPreparerImpl) SetEachListItem ¶
func (p *FirstEventBatchPreparerImpl) SetEachListItem(eachListItem EachListItemFunc)
SetEachListItem sets the EachListItemFunc function. Used for unit testing.
type Reader ¶
Reader allows getting and listing resources from a cache. This interface is introduced for testing to mock the methods from sigs.k8s.io/controller-runtime/pkg/client.Reader.
type UpsertEvent ¶
type UpsertEvent struct { // Resource is the resource that is being upserted. Resource client.Object }
UpsertEvent represents upserting a resource.