events

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

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 *v1beta1.HTTPRoute, pass &v1beta1.HTTPRoute{} as Type.
	Type client.Object
	// NamespacedName is the namespace & name of the deleted resource.
	NamespacedName types.NamespacedName
}

DeleteEvent representing deleting a resource.

type EachListItemFunc added in v0.1.0

type EachListItemFunc func(obj runtime.Object, fn func(runtime.Object) error) error

EachListItemFunc lists each item of a client.ObjectList. It is from k8s.io/apimachinery/pkg/api/meta.

type EventBatch added in v0.1.0

type EventBatch []interface{}

EventBatch is a batch of events to be handled at once. FIXME(pleshakov): think about how to avoid using an interface{} here

type EventHandler added in v0.1.0

type EventHandler interface {
	// HandleEventBatch handles a batch of events.
	// EventBatch can include duplicated events.
	HandleEventBatch(ctx context.Context, batch EventBatch)
}

EventHandler handle events.

type EventHandlerConfig added in v0.1.0

type EventHandlerConfig struct {
	// Processor is the state ChangeProcessor.
	Processor state.ChangeProcessor
	// SecretStore is the state SecretStore.
	SecretStore secrets.SecretStore
	// SecretMemoryManager is the state SecretMemoryManager.
	SecretMemoryManager secrets.SecretDiskMemoryManager
	// Generator is the nginx config Generator.
	Generator config.Generator
	// NginxFileMgr is the file Manager for nginx.
	NginxFileMgr file.Manager
	// NginxRuntimeMgr manages nginx runtime.
	NginxRuntimeMgr runtime.Manager
	// StatusUpdater updates statuses on Kubernetes resources.
	StatusUpdater status.Updater
	// Logger is the logger to be used by the EventHandler.
	Logger logr.Logger
}

EventHandlerConfig holds configuration parameters for EventHandlerImpl.

type EventHandlerImpl added in v0.1.0

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

EventHandlerImpl implements EventHandler. EventHandlerImpl is responsible for: (1) Reconciling the Gateway API and Kubernetes built-in resources with the NGINX configuration. (2) Keeping the statuses of the Gateway API resources updated.

func NewEventHandlerImpl added in v0.1.0

func NewEventHandlerImpl(cfg EventHandlerConfig) *EventHandlerImpl

NewEventHandlerImpl creates a new EventHandlerImpl.

func (*EventHandlerImpl) HandleEventBatch added in v0.1.0

func (h *EventHandlerImpl) HandleEventBatch(ctx context.Context, batch EventBatch)

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, because typically handling an event (or multiple events at once) will result into reloading NGINX, which is the 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 including the number of TLS certs, available CPU cycles. (2) A reload can have side-effects for the 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.

func NewEventLoop

func NewEventLoop(
	eventCh <-chan interface{},
	logger logr.Logger,
	handler EventHandler,
	preparer FirstEventBatchPreparer,
) *EventLoop

NewEventLoop creates a new EventLoop.

func (*EventLoop) Start

func (el *EventLoop) Start(ctx context.Context) error

Start starts the EventLoop. This method will block until the EventLoop stops, which will happen after the ctx is closed.

type FirstEventBatchPreparer added in v0.1.0

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 added in v0.1.0

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

FirstEventBatchPreparerImpl is an implementation of FirstEventBatchPreparer.

func NewFirstEventBatchPreparerImpl added in v0.1.0

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 added in v0.1.0

func (*FirstEventBatchPreparerImpl) SetEachListItem added in v0.1.0

func (p *FirstEventBatchPreparerImpl) SetEachListItem(eachListItem EachListItemFunc)

SetEachListItem sets the EachListItemFunc function. Used for unit testing.

type Reader added in v0.1.0

type Reader interface {
	client.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.

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