clients

package
v3.3.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// 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.
	DefaultReadinessReconciliationInterval = 10 * time.Second
	// MinReadinessReconciliationInterval is the minimum interval of readiness reconciliation loop.
	MinReadinessReconciliationInterval = 3 * time.Second
)
View Source
const (
	// DefaultReadinessCheckTimeout is the default timeout of readiness check.
	// When a readiness check request did not get response within the timeout, the gateway instance will turn into `Pending` status.
	DefaultReadinessCheckTimeout = 5 * time.Second
)

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 logr.Logger,
	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) GatewayClientsToConfigure

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

GatewayClientsToConfigure returns the gateway clients which need to be configured with the new configuration. In DBLess mode, it returns ALL gateway clients because we need to update configurations of each gateway instance. In DB-backed mode, it returns ONE random gateway client because we only need to send configurations to one gateway instance while others will be synced using the DB.

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

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 Control Plane 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).

func (*AdminAPIClientsManager) WithDBMode

WithDBMode allows to set the DBMode of the Kong gateway instances behind the admin API service.

func (*AdminAPIClientsManager) WithReconciliationInterval added in v3.3.0

func (c *AdminAPIClientsManager) WithReconciliationInterval(d time.Duration) *AdminAPIClientsManager

WithReconciliationInterval allows to set the Reconciliation interval to check readiness of clients.

type AdminAPIClientsManagerOption

type AdminAPIClientsManagerOption func(*AdminAPIClientsManager)

func WithReadinessReconciliationTicker

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
	GatewayClientsToConfigure() []*adminapi.Client
}

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

type AlreadyCreatedClient

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 ChannelConfigNotifier

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

func NewChannelConfigNotifier

func NewChannelConfigNotifier(logger logr.Logger) *ChannelConfigNotifier

func (*ChannelConfigNotifier) NotifyGatewayConfigStatus added in v3.3.0

func (n *ChannelConfigNotifier) NotifyGatewayConfigStatus(ctx context.Context, status GatewayConfigApplyStatus)

NotifyGatewayConfigStatus notifies status of sending configuration to Kong gateway(s).

func (*ChannelConfigNotifier) NotifyKonnectConfigStatus added in v3.3.0

func (n *ChannelConfigNotifier) NotifyKonnectConfigStatus(ctx context.Context, status KonnectConfigUploadStatus)

NotifyKonnectConfigStatus notifies status of sending configuration to Konnect.

func (*ChannelConfigNotifier) SubscribeGatewayConfigStatus added in v3.3.0

func (n *ChannelConfigNotifier) SubscribeGatewayConfigStatus() chan GatewayConfigApplyStatus

func (*ChannelConfigNotifier) SubscribeKonnectConfigStatus added in v3.3.0

func (n *ChannelConfigNotifier) SubscribeKonnectConfigStatus() chan KonnectConfigUploadStatus

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

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

type ConfigStatusNotifier

type ConfigStatusNotifier interface {
	NotifyGatewayConfigStatus(context.Context, GatewayConfigApplyStatus)
	NotifyKonnectConfigStatus(context.Context, KonnectConfigUploadStatus)
}

type ConfigStatusSubscriber

type ConfigStatusSubscriber interface {
	SubscribeGatewayConfigStatus() chan GatewayConfigApplyStatus
	SubscribeKonnectConfigStatus() chan KonnectConfigUploadStatus
}

type DefaultReadinessChecker

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

func NewDefaultReadinessChecker

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

func (DefaultReadinessChecker) CheckReadiness

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

type GatewayConfigApplyStatus added in v3.3.0

type GatewayConfigApplyStatus struct {
	// TranslationFailuresOccurred is true means Translation of some of Kubernetes objects failed.
	TranslationFailuresOccurred bool

	// Any error occurred when syncing with Gateways.
	ApplyConfigFailed bool
}

GatewayConfigApplyStatus stores the status of building Kong configuration and sending configuration to Kong gateways.

type KonnectConfigUploadStatus added in v3.3.0

type KonnectConfigUploadStatus struct {
	Failed bool
}

KonnectConfigUploadStatus stores the status of uploading configuration to Konnect.

type NoOpConfigStatusNotifier

type NoOpConfigStatusNotifier struct{}

func (NoOpConfigStatusNotifier) NotifyGatewayConfigStatus added in v3.3.0

func (n NoOpConfigStatusNotifier) NotifyGatewayConfigStatus(_ context.Context, _ GatewayConfigApplyStatus)

func (NoOpConfigStatusNotifier) NotifyKonnectConfigStatus added in v3.3.0

func (n NoOpConfigStatusNotifier) NotifyKonnectConfigStatus(_ context.Context, _ KonnectConfigUploadStatus)

type ReadinessCheckResult

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

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

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

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