Documentation
¶
Overview ¶
Package aigateway is able to dynamically run multiple on-prem AI Gateway control plane instances and manage their lifecycle. The generic instance lifecycle is shared with the Kong Ingress Controller's multi-instance manager through the instances package.
Index ¶
- Constants
- func Hash(cfg Config) (string, error)
- type AdminAPIEndpointsReconciler
- type Config
- type EntityFailure
- type EntityStatusReporter
- func (r *EntityStatusReporter) AreKubernetesObjectReportsEnabled() bool
- func (r *EntityStatusReporter) KubernetesObjectConfigurationStatus(obj client.Object) status.ConfigurationStatus
- func (r *EntityStatusReporter) KubernetesObjectConfigurationStatusMessage(obj client.Object) string
- func (r *EntityStatusReporter) KubernetesObjectIsConfigured(obj client.Object) bool
- func (r *EntityStatusReporter) Queue() *status.Queue
- func (r *EntityStatusReporter) Report(included []client.Object, failures []EntityFailure)
- type Env
- type Instance
- func (i *Instance) AdminAPIs() sets.Set[adminapi.DiscoveredAdminAPI]
- func (i *Instance) Config() Config
- func (i *Instance) ConfigHash() (string, error)
- func (i *Instance) DiagnosticsHandler() http.Handler
- func (i *Instance) Done() <-chan struct{}
- func (i *Instance) ID() manager.ID
- func (i *Instance) IsReady() error
- func (i *Instance) Run(ctx context.Context) error
- type Manager
Constants ¶
const ControllerNameAdminAPIEndpoints = "onprem-aigateway-adminapi-endpoints"
ControllerNameAdminAPIEndpoints is the name used for logging and event recording by the Admin API endpoints discovery controller.
const DefaultSyncInterval = 3 * time.Second
DefaultSyncInterval is the interval between two rounds of syncing configuration with the data planes used when the OnPremAIGateway doesn't specify one.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AdminAPIEndpointsReconciler ¶
type AdminAPIEndpointsReconciler struct {
client.Client
// GatewayNN is the OnPremAIGateway whose referencing AIGatewayDataPlanes'
// Admin API endpoints are discovered.
GatewayNN types.NamespacedName
// Discoverer performs the EndpointSlice -> Admin API endpoint discovery.
Discoverer *adminapidiscovery.Discoverer
// Log is the logger used by the reconciler.
Log logr.Logger
// OnDiscovery is called with the Admin APIs discovered for all the
// AIGatewayDataPlanes referencing GatewayNN. It is called on every
// successful reconciliation, including when the set is empty.
OnDiscovery func(ctx context.Context, adminAPIs sets.Set[adminapidiscovery.DiscoveredAdminAPI])
}
AdminAPIEndpointsReconciler discovers the Admin API endpoints of all the AIGatewayDataPlanes referencing the Reconciler's OnPremAIGateway and notifies about the discovered set through OnDiscovery.
It reconciles whole data planes rather than individual EndpointSlices: on every relevant event it re-discovers the endpoints of all the referencing data planes' Admin API Services, so the notified set always reflects the complete state.
func (*AdminAPIEndpointsReconciler) Reconcile ¶
func (r *AdminAPIEndpointsReconciler) Reconcile(ctx context.Context, _ reconcile.Request) (ctrl.Result, error)
Reconcile discovers the Admin API endpoints of all the AIGatewayDataPlanes referencing the Reconciler's OnPremAIGateway and notifies about the result. The reconcile.Request is ignored because we reconcile whole data planes instead of individual EndpointSlices: any relevant event (a data plane added or removed, an EndpointSlice changed) invalidates the complete discovered set, so re-discovering all of it is the only correct response. This is cheap - just a couple of cached list calls - and guarantees the notified set is always complete, with no state to keep in sync.
func (*AdminAPIEndpointsReconciler) SetupWithManager ¶
func (r *AdminAPIEndpointsReconciler) SetupWithManager(mgr ctrl.Manager) error
SetupWithManager sets up the controller with the Manager.
type Config ¶
type Config struct {
// DBLessConfig is the rendered dbless declarative payload for this gateway, ready to be
// pushed to its data planes' Admin API.
DBLessConfig []byte
// SyncInterval is the interval between two rounds of syncing configuration with the
// data planes. Zero means the operator default (DefaultSyncInterval) applies.
// It's part of the hashed config so that changing it restarts the instance,
// whose sync loop reads it at start-up.
SyncInterval time.Duration
// SyncTimeout is the timeout of a single run of syncing configuration with
// a gateway's data planes. Zero means no timeout is applied to a sync run.
// It's part of the hashed config so that changing it restarts the instance
// with the new value.
SyncTimeout time.Duration
// MinRuntimeVersion is the oldest AI Gateway release that must accept the
// generated configuration. Zero means the translator default applies.
// It's part of the hashed config so that changing it restarts the instance
// with the new value.
MinRuntimeVersion string
// AdminClientCertSecretNN is the reference to the mTLS client certificate Secret the
// instance reads when pushing configuration to its data planes. It is part of the
// hashed config so that a renewed Secret - recreated under a new GenerateName by
// EnsureCertificate - drifts the hash and restarts the instance with the new reference.
AdminClientCertSecretNN types.NamespacedName
// SecretLabelFilters are the matchLabels from the OnPremAIGateway's
// spec.objectFilters.secrets.matchLabels. They are ANDed with the operator's
// SecretLabelSelector on the instance's Secret cache, so user entity Secrets
// must carry both. The Admin API client certificate Secret is stamped with
// them by the OnPremAIGateway controller, so it always stays visible.
// They are part of the hashed config so that changing them restarts the
// instance: its cache is built at manager start and cannot pick the new
// filters up otherwise.
SecretLabelFilters map[string]string
// WatchNamespaces are the namespaces the instance watches for the
// configuration entities and the Secrets they reference, resolved from the
// OnPremAIGateway's spec.watchNamespaces. A nil list means every namespace.
// It's part of the hashed config so that changing it restarts the instance:
// its caches are built at manager start and cannot pick the new namespaces
// up otherwise.
WatchNamespaces []string
}
Config is the resolved configuration of a single on-prem AI Gateway control plane instance.
type EntityFailure ¶
type EntityFailure struct {
// Obj is the configuration entity the failure is attributed to.
Obj client.Object
// Err is the failure cause, reported in the entity's Programmed condition message.
Err error
}
EntityFailure is a single configuration entity that failed to be translated into or applied as part of the configuration pushed to the data planes.
type EntityStatusReporter ¶
type EntityStatusReporter struct {
// contains filtered or unexported fields
}
EntityStatusReporter records the per-entity outcome of the instance's configuration syncs (translation into the aigw.Document and the push to the data planes' Admin APIs) and serves it to the configuration-entity reconcilers, which turn it into the entities' Programmed conditions.
It mirrors the KIC pattern of KongClient's kubernetesObjectReportsFilter: the whole status set is swapped after every sync and the status queue is notified so that the reconcilers re-read it.
func NewEntityStatusReporter ¶
func NewEntityStatusReporter(scheme *runtime.Scheme) *EntityStatusReporter
NewEntityStatusReporter creates a new EntityStatusReporter. The scheme is used to resolve the GVK of the reported entities: typed objects read from the client cache carry no TypeMeta, and the underlying status set keys its entries on the GVK.
func (*EntityStatusReporter) AreKubernetesObjectReportsEnabled ¶
func (r *EntityStatusReporter) AreKubernetesObjectReportsEnabled() bool
AreKubernetesObjectReportsEnabled always returns true: the reporter exists precisely to report entity configuration status.
func (*EntityStatusReporter) KubernetesObjectConfigurationStatus ¶
func (r *EntityStatusReporter) KubernetesObjectConfigurationStatus(obj client.Object) status.ConfigurationStatus
KubernetesObjectConfigurationStatus reports the configuration status of the provided entity: Succeeded when it was part of the last successfully pushed configuration, Failed when its translation or the push failed, Unknown when it has never been reported or its generation is newer than the last report.
func (*EntityStatusReporter) KubernetesObjectConfigurationStatusMessage ¶
func (r *EntityStatusReporter) KubernetesObjectConfigurationStatusMessage(obj client.Object) string
KubernetesObjectConfigurationStatusMessage returns the error message reported for the provided entity by the last sync, or an empty string when the entity did not fail (or failed without a message).
func (*EntityStatusReporter) KubernetesObjectIsConfigured ¶
func (r *EntityStatusReporter) KubernetesObjectIsConfigured(obj client.Object) bool
KubernetesObjectIsConfigured reports whether the provided entity was part of the last successfully pushed configuration.
func (*EntityStatusReporter) Queue ¶
func (r *EntityStatusReporter) Queue() *status.Queue
Queue returns the status queue the reporter publishes status update events on. It is wired into the configuration-entity reconcilers' StatusQueue.
func (*EntityStatusReporter) Report ¶
func (r *EntityStatusReporter) Report(included []client.Object, failures []EntityFailure)
Report stores the outcome of a single configuration sync and notifies the configuration-entity reconcilers: included are the entities that were successfully translated and pushed, failures the ones that failed translation or apply, along with the error cause.
type Env ¶
type Env struct {
// RestConfig is the rest config used to reach the Kubernetes API server.
RestConfig *rest.Config
// Scheme is the scheme the instance's manager registers its objects in.
Scheme *runtime.Scheme
// CacheSyncTimeout is the cache sync timeout for the instance's controllers.
CacheSyncTimeout time.Duration
// GatewayNN is the reference to the OnPremAIGateway resource the instance
// serves. It is used to discover the AIGatewayDataPlanes referencing the
// gateway and their Admin API endpoints.
GatewayNN types.NamespacedName
// AdminClientCertSecretNN is the reference to the mTLS client certificate Secret
// provisioned by the OnPremAIGateway controller. The instance reads it to build
// the Admin API clients that push configuration to the data planes.
AdminClientCertSecretNN types.NamespacedName
// TypeConverter is the SSA type converter used to patch the OnPremAIGateway status.
TypeConverter managedfields.TypeConverter
// SecretLabelSelector is the label key the operator's main manager caches Secrets
// by (see modules/manager config.SecretLabelSelector). The instance's own cache
// mirrors it, so Secrets the translation reads (e.g. AIGatewayAuthStrategy's oidc
// clientSecret and consumer credential apiKeys) see the same set the main manager
// deems ingestible.
SecretLabelSelector string
}
Env carries the process-level dependencies an instance needs to build and run its own controller-runtime manager. They never drift with the spec, so they stay out of Config, which is hashed for drift detection.
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance is a single on-prem AI Gateway control plane instance. It runs its own controller-runtime manager hosting the configuration-entity controllers (AIGatewayModel, and its sibling kinds as they are added), so that the controllers start and stop together with the OnPremAIGateway resource that owns the instance.
func NewInstance ¶
NewInstance creates a new on-prem AI Gateway control plane instance. It does not start it.
func (*Instance) AdminAPIs ¶
func (i *Instance) AdminAPIs() sets.Set[adminapi.DiscoveredAdminAPI]
AdminAPIs returns a copy of the Admin API endpoints discovered for the AIGatewayDataPlanes referencing the instance's OnPremAIGateway.
func (*Instance) ConfigHash ¶
ConfigHash returns a hash of the instance's configuration.
func (*Instance) DiagnosticsHandler ¶
DiagnosticsHandler returns nil: the instance does not expose diagnostics data yet. TODO: https://github.com/Kong/kong-operator/issues/5630
func (*Instance) Done ¶
func (i *Instance) Done() <-chan struct{}
Done returns a channel closed once the instance stopped: its controllers no longer write to the cluster.
func (*Instance) IsReady ¶
IsReady returns an error if the instance is not ready yet.
The instance reports push failures on the gateway's DataPlanesConfigured condition, so there is nothing to wait for here yet. TODO: https://github.com/Kong/kong-operator/issues/5569
type Manager ¶
Manager runs multiple on-prem AI Gateway control plane instances.
On top of the shared registry, it keeps the scheduled instances so a caller can wait for a stopped instance to actually stop: the registry forgets an instance as soon as it is told to stop, while its controllers may still be writing.
func NewManager ¶
func NewManager(logger logr.Logger, opts ...instances.RegistryOption) *Manager
NewManager creates a new AI Gateway multi-instance manager.
func (*Manager) ScheduleInstance ¶
ScheduleInstance schedules the instance on the registry and keeps track of it.
func (*Manager) StopInstance ¶
StopInstance stops the instance with the given ID. It does not wait for the instance to stop: use WaitForInstanceStop for that.