dataplane

package
v2.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Package dataplane provides functionality for communicating with and providing configuration to backend dataplane APIs.

Index

Constants

View Source
const (
	// KongConfigurationTranslationFailedEventReason defines an event reason used for creating all translation resource failure events.
	KongConfigurationTranslationFailedEventReason = "KongConfigurationTranslationFailed"
	// KongConfigurationApplyFailedEventReason defines an event reason used for creating all config apply resource failure events.
	KongConfigurationApplyFailedEventReason = "KongConfigurationApplyFailed"
)
View Source
const (
	// DefaultSyncSeconds indicates the time.Duration (minimum) that will occur between
	// updates to the DataplaneClient.
	//
	// This default was based on local testing wherein it appeared sub-second updates
	// to the Admin API could be problematic (or at least operate differently) based on
	// which storage backend was in use (i.e. "dbless", "postgres"). This is a workaround
	// for improvements we still need to investigate upstream.
	//
	// See Also: https://github.com/Kong/kubernetes-ingress-controller/issues/1398
	DefaultSyncSeconds float32 = 3.0

	DefaultInitWaitPeriod = 5 * time.Second
)
View Source
const (
	// DefaultTimeoutSeconds indicates the time.Duration allowed for responses to
	// come back from the backend data-plane API.
	//
	// NOTE: the current default is based on observed latency in a CI environment using
	// the GKE cloud provider with the Kong Admin API.
	DefaultTimeoutSeconds float32 = 30.0
)

Variables

This section is empty.

Functions

func HandleSendToClientResult added in v2.9.0

func HandleSendToClientResult(client sendconfig.KonnectAwareClient, logger logrus.FieldLogger, newSHA string, err error) (string, error)

HandleSendToClientResult handles a result returned from sendToClient. It will ignore errors that are returned from Konnect client.

func UniqueObjects added in v2.9.0

func UniqueObjects(reportedObjects []client.Object, resourceFailures []failures.ResourceFailure) []client.Object

Types

type AddressFinder

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

AddressFinder is a threadsafe metadata object which can provide the current live addresses in use by the dataplane at any point in time.

func NewAddressFinder

func NewAddressFinder() *AddressFinder

NewAddressFinder provides a new AddressFinder which can be used to find the current listening addresses of the data-plane for ingress network traffic.

func (*AddressFinder) GetAddresses

func (a *AddressFinder) GetAddresses(ctx context.Context) ([]string, error)

GetAddresses provides a list of the addresses which the data-plane is listening on for ingress network traffic. Addresses can either be IP addresses or hostnames.

func (*AddressFinder) GetLoadBalancerAddresses

func (a *AddressFinder) GetLoadBalancerAddresses(ctx context.Context) ([]netv1.IngressLoadBalancerIngress, error)

GetLoadBalancerAddresses provides a list of the addresses which the data-plane is listening on for ingress network traffic, but provides the addresses in Kubernetes corev1.LoadBalancerIngress format. Addresses can be IP addresses or hostnames.

func (*AddressFinder) SetGetter

func (a *AddressFinder) SetGetter(getter AddressGetter)

SetGetter provides a callback function that the AddressFinder will use to dynamically retrieve the addresses of the data-plane.

func (*AddressFinder) SetOverrides

func (a *AddressFinder) SetOverrides(addrs []string)

SetOverrides hard codes a specific list of addresses to be the addresses that this finder produces for the data-plane. To disable overrides, call this method again with an empty list.

type AddressGetter

type AddressGetter func(ctx context.Context) ([]string, error)

AddressGetter is a function which can dynamically retrieve the list of IPs that the data-plane is listening on for ingress network traffic.

type AdminAPIClientsManager added in v2.9.0

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 clients' list update with use of Notify method, and queried for the latest slice of those with use of Clients method.

func NewAdminAPIClientsManager added in v2.9.0

func NewAdminAPIClientsManager(
	ctx context.Context,
	logger logrus.FieldLogger,
	initialClients []*adminapi.Client,
	kongClientFactory ClientFactory,
) (*AdminAPIClientsManager, error)

func (*AdminAPIClientsManager) AllClients added in v2.9.0

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

AllClients returns a copy of current client's slice. It will also include Konnect client if set.

func (*AdminAPIClientsManager) GatewayClients added in v2.9.0

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 added in v2.9.0

func (c *AdminAPIClientsManager) GatewayClientsCount() int

func (*AdminAPIClientsManager) Notify added in v2.9.0

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) RunNotifyLoop added in v2.9.0

func (c *AdminAPIClientsManager) RunNotifyLoop()

RunNotifyLoop runs a goroutine that will dynamically ingest new addresses of Kong Admin API endpoints.

func (*AdminAPIClientsManager) Running added in v2.9.0

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 added in v2.9.0

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

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 added in v2.9.0

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 AdminAPIClientsProvider added in v2.9.0

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

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

type ChannelConfigNotifier added in v2.9.0

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

func NewChannelConfigNotifier added in v2.9.0

func NewChannelConfigNotifier(logger logr.Logger) *ChannelConfigNotifier

func (*ChannelConfigNotifier) NotifyConfigStatus added in v2.9.0

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 added in v2.9.0

func (n *ChannelConfigNotifier) SubscribeConfigStatus() chan ConfigStatus

type Client

type Client interface {
	// DBMode informs the caller which DB mode the data-plane has employed
	// (e.g. "off" (dbless) or "postgres").
	DBMode() string

	// Update the data-plane by parsing the current configuring and applying
	// it to the backend API.
	Update(ctx context.Context) error
}

type ClientFactory added in v2.9.0

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

type ConfigStatus added in v2.9.0

type ConfigStatus int
const (
	// ConfigStatusOK: no error happens in translation from k8s objects to kong configuration
	// and succeeded to apply kong configuration to kong gateway.
	ConfigStatusOK ConfigStatus = iota
	// ConfigStatusTranslationErrorHappened: error happened in translation of k8s objects
	// but succeeded to apply kong configuration for remaining objects.
	ConfigStatusTranslationErrorHappened
	// ConfigStatusApplyFailed: failed to apply kong configurations.
	ConfigStatusApplyFailed
)

type ConfigStatusNotifier added in v2.9.0

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

type ConfigStatusSubscriber added in v2.9.0

type ConfigStatusSubscriber interface {
	SubscribeConfigStatus() chan ConfigStatus
}

type KongClient

type KongClient struct {

	// SHAs is a slice is configuration hashes send in last batch send.
	SHAs []string
	// contains filtered or unexported fields
}

KongClient is a threadsafe high level API client for the Kong data-plane(s) which parses Kubernetes object caches into Kong Admin configurations and sends them as updates to the data-plane(s) (Kong Admin API).

func NewKongClient

func NewKongClient(
	logger logrus.FieldLogger,
	timeout time.Duration,
	ingressClass string,
	diagnostic util.ConfigDumpDiagnostic,
	kongConfig sendconfig.Config,
	eventRecorder record.EventRecorder,
	dbMode string,
	clientsProvider AdminAPIClientsProvider,
	updateStrategyResolver sendconfig.UpdateStrategyResolver,
	configChangeDetector sendconfig.ConfigurationChangeDetector,
) (*KongClient, error)

NewKongClient provides a new KongClient object after connecting to the data-plane API and verifying integrity.

func (*KongClient) AreCombinedServiceRoutesEnabled added in v2.4.0

func (c *KongClient) AreCombinedServiceRoutesEnabled() bool

AreCombinedServiceRoutesEnabled determines whether the combined service routes translation mode has been enabled, or if the legacy logic is being used. When enabled this changes the logic to try and combine multiple paths into single routes, but it also changes the names of existing routes and so it should be considered disruptive as it will temporarily drop routes when it's first enabled.

func (*KongClient) AreKubernetesObjectReportsEnabled

func (c *KongClient) AreKubernetesObjectReportsEnabled() bool

AreKubernetesObjectReportsEnabled returns true or false whether this client has been configured to report on Kubernetes objects which have been successfully configured for in the data-plane.

func (*KongClient) DBMode

func (c *KongClient) DBMode() string

DBMode indicates which database the Kong Gateway is using.

func (*KongClient) DeleteObject

func (c *KongClient) DeleteObject(obj client.Object) error

DeleteObject accepts a Kubernetes controller-runtime client.Object and removes it from the configuration cache. The delete action will asynchronously be converted to Kong DSL and applied to the Kong Admin API. A status will later be added to the object whether the configuration update succeeds or fails.

under the hood the cache implementation will ignore deletions on objects that are not present in the cache, so in those cases this is a no-op.

func (*KongClient) EnableCombinedServiceRoutes added in v2.4.0

func (c *KongClient) EnableCombinedServiceRoutes()

EnableCombinedServiceRoutes turns on the combined service routes feature for the Kong Dataplane client.

func (*KongClient) EnableKubernetesObjectReports

func (c *KongClient) EnableKubernetesObjectReports(q *status.Queue)

EnableKubernetesObjectReports turns on reporting for Kubernetes objects which are configured as part of Update() operations. Enabling this makes it possible to use ObjectConfigured(obj) to determine whether an object has successfully been configured for on the data-plane.

func (*KongClient) KubernetesObjectConfigurationStatus added in v2.9.0

func (c *KongClient) KubernetesObjectConfigurationStatus(obj client.Object) k8sobj.ConfigurationStatus

func (*KongClient) KubernetesObjectIsConfigured

func (c *KongClient) KubernetesObjectIsConfigured(obj client.Object) bool

KubernetesObjectIsConfigured reports whether the provided object has active configuration for itself successfully applied to the data-plane.

func (*KongClient) Listeners

Listeners retrieves the currently configured listeners from the underlying proxy so that callers can gather this metadata to know which ports and protocols are in use by the proxy.

func (*KongClient) ObjectExists

func (c *KongClient) ObjectExists(obj client.Object) (bool, error)

ObjectExists indicates whether or not any version of the provided object is already present in the proxy.

func (*KongClient) SetConfigStatusNotifier added in v2.9.0

func (c *KongClient) SetConfigStatusNotifier(n ConfigStatusNotifier)

SetConfigStatusNotifier sets a notifier which notifies subscribers about configuration sending results. Currently it is used for uploading the node status to konnect runtime group.

func (*KongClient) Update

func (c *KongClient) Update(ctx context.Context) error

Update parses the Cache present in the client and converts current Kubernetes state into Kong objects and state, and then ships the resulting configuration to the data-plane (Kong Admin API).

func (*KongClient) UpdateObject

func (c *KongClient) UpdateObject(obj client.Object) error

UpdateObject accepts a Kubernetes controller-runtime client.Object and adds/updates that to the configuration cache. It will be asynchronously converted into the upstream Kong DSL and applied to the Kong Admin API. A status will later be added to the object whether the configuration update succeeds or fails.

type NoOpConfigStatusNotifier added in v2.9.0

type NoOpConfigStatusNotifier struct{}

func (NoOpConfigStatusNotifier) NotifyConfigStatus added in v2.9.0

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

type Synchronizer

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

Synchronizer is a threadsafe object which starts a goroutine to updates the data-plane at regular intervals.

func NewSynchronizer

func NewSynchronizer(logger logrus.FieldLogger, client Client, opts ...SynchronizerOption) (*Synchronizer, error)

NewSynchronizer will provide a new Synchronizer object with a specified stagger time for data-plane updates to occur. Note that this starts some background goroutines and the caller is resonsible for marking the provided context.Context as "Done()" to shut down the background routines.

func (*Synchronizer) IsReady

func (p *Synchronizer) IsReady() bool

IsReady indicates whether the synchronizer is actively able to synchronize configuration to the dataplane. It's similar to IsRunning() but reports on whether configuration can actually be successful and is also used as part of a controller-runtime Runnable interface to wait for readiness before starting controllers.

func (*Synchronizer) IsRunning

func (p *Synchronizer) IsRunning() bool

IsRunning informs the caller whether the synchronization server is running.

func (*Synchronizer) NeedLeaderElection

func (p *Synchronizer) NeedLeaderElection() bool

NeedLeaderElection implements the controller-runtime Runnable interface to inform the controller manager whether leadership election is needed, which is always true in our case.

func (*Synchronizer) Start

func (p *Synchronizer) Start(ctx context.Context) error

Start starts the goroutine synchronization server that will perform an Update() on the provided dataplane.Client according to the provided stagger time, or using the DefaultSyncSeconds if not otherwise provided.

To stop the server, the provided context must be Done().

type SynchronizerOption added in v2.8.0

type SynchronizerOption func(*Synchronizer)

func WithInitWaitPeriod added in v2.8.0

func WithInitWaitPeriod(period time.Duration) SynchronizerOption

WithInitWaitPeriod returns a SynchronizerOption which sets the initial wait period.

func WithStagger added in v2.8.0

func WithStagger(period time.Duration) SynchronizerOption

WithStagger returns a SynchronizerOption which sets the stagger period.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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