clients

package
v2.12.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DefaultReadinessReconciliationInterval = 10 * time.Second

DefaultReadinessReconciliationInterval is the interval at which the manager will run readiness reconciliation loop. It's the same as the default interval of a Kubernetes container's readiness probe.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdminAPIClientsManager

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

AdminAPIClientsManager keeps track of current Admin API clients of Gateways that we should configure. In particular, it can be notified about the discovered clients' list with use of Notify method, and queried for the latest slice of ready to be configured clients with use of GatewayClients method. It also runs periodic readiness reconciliation loop which is responsible for checking readiness of the clients.

func NewAdminAPIClientsManager

func NewAdminAPIClientsManager(
	ctx context.Context,
	logger logrus.FieldLogger,
	initialClients []*adminapi.Client,
	readinessChecker ReadinessChecker,
	opts ...AdminAPIClientsManagerOption,
) (*AdminAPIClientsManager, error)

func (*AdminAPIClientsManager) GatewayClients

func (c *AdminAPIClientsManager) GatewayClients() []*adminapi.Client

GatewayClients returns a copy of current client's slice. Konnect client won't be included. This method can be used when some actions need to be performed only against Kong Gateway clients.

func (*AdminAPIClientsManager) GatewayClientsCount

func (c *AdminAPIClientsManager) GatewayClientsCount() int

func (*AdminAPIClientsManager) KonnectClient

func (c *AdminAPIClientsManager) KonnectClient() *adminapi.KonnectClient

func (*AdminAPIClientsManager) Notify

func (c *AdminAPIClientsManager) Notify(discoveredAPIs []adminapi.DiscoveredAdminAPI)

Notify receives a list of addresses that KongClient should use from now on as a list of Kong Admin API endpoints.

func (*AdminAPIClientsManager) Run added in v2.11.0

func (c *AdminAPIClientsManager) Run()

Run runs a goroutine that will dynamically ingest new addresses of Kong Admin API endpoints. It should only be called when Gateway Discovery is enabled.

func (*AdminAPIClientsManager) Running

func (c *AdminAPIClientsManager) Running() chan struct{}

Running returns a channel that is closed when the manager's background tasks are already running.

func (*AdminAPIClientsManager) SetKonnectClient

func (c *AdminAPIClientsManager) SetKonnectClient(client *adminapi.KonnectClient)

SetKonnectClient sets a client that will be used to communicate with Konnect Runtime Group Admin API. If called multiple times, it will override the client.

func (*AdminAPIClientsManager) SubscribeToGatewayClientsChanges

func (c *AdminAPIClientsManager) SubscribeToGatewayClientsChanges() (<-chan struct{}, bool)

SubscribeToGatewayClientsChanges returns a channel that will receive a notification on every Gateway clients update. Can be used to receive a signal when immediate reaction to the changes is needed. After receiving the notification, GatewayClients call will return an already updated slice of clients. It will return `false` as a second result in case the notifications loop is not running (e.g. static clients setup is used and no updates are going to happen).

type AdminAPIClientsManagerOption added in v2.11.0

type AdminAPIClientsManagerOption func(*AdminAPIClientsManager)

func WithReadinessReconciliationTicker added in v2.11.0

func WithReadinessReconciliationTicker(ticker Ticker) AdminAPIClientsManagerOption

WithReadinessReconciliationTicker allows to set a custom ticker for readiness reconciliation loop.

type AdminAPIClientsProvider

type AdminAPIClientsProvider interface {
	KonnectClient() *adminapi.KonnectClient
	GatewayClients() []*adminapi.Client
}

AdminAPIClientsProvider allows fetching the most recent list of Admin API clients of Gateways that we should configure.

type AlreadyCreatedClient added in v2.11.0

type AlreadyCreatedClient interface {
	IsReady(context.Context) error
	PodReference() (k8stypes.NamespacedName, bool)
	BaseRootURL() string
}

AlreadyCreatedClient represents an Admin API client that has already been created.

type CalculateConfigStatusInput

type CalculateConfigStatusInput struct {
	// Any error occurred when syncing with Gateways.
	GatewaysFailed bool

	// Any error occurred when syncing with Konnect,
	KonnectFailed bool

	// Translation of some of Kubernetes objects failed.
	TranslationFailuresOccurred bool
}

CalculateConfigStatusInput aggregates the input to CalculateConfigStatus.

type ChannelConfigNotifier

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

func NewChannelConfigNotifier

func NewChannelConfigNotifier(logger logr.Logger) *ChannelConfigNotifier

func (*ChannelConfigNotifier) NotifyConfigStatus

func (n *ChannelConfigNotifier) NotifyConfigStatus(ctx context.Context, status ConfigStatus)

NotifyConfigStatus sends the status in a separate goroutine. If the notification is not received in 1s, it's dropped.

func (*ChannelConfigNotifier) SubscribeConfigStatus

func (n *ChannelConfigNotifier) SubscribeConfigStatus() chan ConfigStatus

type ClientFactory

type ClientFactory interface {
	CreateAdminAPIClient(ctx context.Context, address adminapi.DiscoveredAdminAPI) (*adminapi.Client, error)
}

ClientFactory is responsible for creating Admin API clients.

type ConfigStatus

type ConfigStatus string

ConfigStatus is an enumerated type that represents the status of the configuration synchronisation. Look at CalculateConfigStatus for more details.

const (
	ConfigStatusOK                                         ConfigStatus = "OK"
	ConfigStatusTranslationErrorHappened                   ConfigStatus = "TranslationErrorHappened"
	ConfigStatusApplyFailed                                ConfigStatus = "ApplyFailed"
	ConfigStatusOKKonnectApplyFailed                       ConfigStatus = "OKKonnectApplyFailed"
	ConfigStatusTranslationErrorHappenedKonnectApplyFailed ConfigStatus = "TranslationErrorHappenedKonnectApplyFailed"
	ConfigStatusApplyFailedKonnectApplyFailed              ConfigStatus = "ApplyFailedKonnectApplyFailed"
	ConfigStatusUnknown                                    ConfigStatus = "Unknown"
)

func CalculateConfigStatus

func CalculateConfigStatus(i CalculateConfigStatusInput) ConfigStatus

CalculateConfigStatus calculates a clients.ConfigStatus that sums up the configuration synchronisation result as a single enumerated value.

type ConfigStatusNotifier

type ConfigStatusNotifier interface {
	NotifyConfigStatus(context.Context, ConfigStatus)
}

type ConfigStatusSubscriber

type ConfigStatusSubscriber interface {
	SubscribeConfigStatus() chan ConfigStatus
}

type DefaultReadinessChecker added in v2.11.0

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

func NewDefaultReadinessChecker added in v2.11.0

func NewDefaultReadinessChecker(factory ClientFactory, logger logr.Logger) DefaultReadinessChecker

func (DefaultReadinessChecker) CheckReadiness added in v2.11.0

func (c DefaultReadinessChecker) CheckReadiness(
	ctx context.Context,
	readyClients []AlreadyCreatedClient,
	pendingClients []adminapi.DiscoveredAdminAPI,
) ReadinessCheckResult

type NoOpConfigStatusNotifier

type NoOpConfigStatusNotifier struct{}

func (NoOpConfigStatusNotifier) NotifyConfigStatus

func (n NoOpConfigStatusNotifier) NotifyConfigStatus(_ context.Context, _ ConfigStatus)

type ReadinessCheckResult added in v2.11.0

type ReadinessCheckResult struct {
	// ClientsTurnedReady are the clients that were pending and are now ready to be used.
	ClientsTurnedReady []*adminapi.Client
	// ClientsTurnedPending are the clients that were ready and are now pending to be created.
	ClientsTurnedPending []adminapi.DiscoveredAdminAPI
}

ReadinessCheckResult represents the result of a readiness check.

func (ReadinessCheckResult) HasChanges added in v2.11.0

func (r ReadinessCheckResult) HasChanges() bool

HasChanges returns true if there are any changes in the readiness check result. When no changes are present, it means that the readiness check haven't successfully created any pending client nor detected any already created client that became not ready.

type ReadinessChecker added in v2.11.0

type ReadinessChecker interface {
	// CheckReadiness checks readiness of the provided clients:
	// - alreadyCreatedClients are the clients that have already been created. The readiness of these clients will be
	//   checked by their IsReady() method.
	// - pendingClients are the clients that have not been created yet and are pending to be created. The readiness of
	//   these clients will be checked by trying to create them.
	CheckReadiness(
		ctx context.Context,
		alreadyCreatedClients []AlreadyCreatedClient,
		pendingClients []adminapi.DiscoveredAdminAPI,
	) ReadinessCheckResult
}

ReadinessChecker is responsible for checking the readiness of Admin API clients.

type Ticker added in v2.11.0

type Ticker interface {
	Stop()
	Channel() <-chan time.Time
	Reset(d time.Duration)
}

Ticker is an interface that allows to control a ticker.

Jump to

Keyboard shortcuts

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