dataplane

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 50 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dataplane contains the DataPlane reconciliation logic shared by the specialized DataPlane controllers (AIGatewayDataPlane, KegDataPlane). The generic Reconciler is parameterized over the DataPlane type, the Konnect control plane type it references and the Konnect certificate type it provisions; type specific behavior is injected through Config.

Index

Constants

View Source
const (
	// KonnectCertVolumeName is the name of the volume that holds the Konnect mTLS certificate.
	KonnectCertVolumeName = "konnect-cert"

	// KonnectCertMountPath is the path where the Konnect certificate Secret is mounted in the DataPlane container.
	KonnectCertMountPath = "/var/konnect-client-certificate/"

	// AdminCertVolumeName is the name of the volume that holds the Admin API TLS server certificate.
	AdminCertVolumeName = "admin-cert"

	// AdminCertMountPath is the path where the Admin API certificate Secret is mounted in the DataPlane container.
	AdminCertMountPath = "/var/admin-certificate/"
)
View Source
const LicenseMissingMessage = "No enabled KongLicense resource found; the gateway will run without a license"

LicenseMissingMessage is the message used when no enabled KongLicense is available and the gateway runs without a license.

Variables

This section is empty.

Functions

func BuildDeployment added in v2.4.0

func BuildDeployment[T Object](
	logger logr.Logger,
	tc managedfields.TypeConverter,
	dp T,
	cp ResolvedControlPlane,
	image string,
	certSecretName string,
	adminCertSecretName string,
	certChecksum string,
	cfg DeploymentConfig[T],
	checksumAnnotation string,
) (*unstructured.Unstructured, error)

BuildDeployment constructs the desired DataPlane Deployment as *unstructured.Unstructured. If the user has provided a PodTemplateSpec overlay, it is merged with the operator base via SMD. The result always has spec.strategy removed so that SSA does not claim ownership of it, leaving the API server (or admission webhooks) free to apply their own default.

func BuildService added in v2.4.0

func BuildService[T Object](
	tc managedfields.TypeConverter,
	dp T,
	cfg ServiceConfig[T],
) (client.Object, error)

BuildService constructs the desired Service. If the user has provided ServiceOptions, they are merged with the operator base via SMD: user-provided fields win on conflicts; the base supplies defaults (selector, default port) only when the user has not specified them.

func CertEntityName added in v2.4.0

func CertEntityName(dpName, certChecksum string) string

CertEntityName derives the Konnect certificate CR name from the DataPlane name and the certificate content checksum. Naming the entity after the content (rather than after the DataPlane name alone) means a certificate rotation creates a new CR/Konnect entity instead of overwriting the existing one in place, so the previous certificate stays registered and trusted by Konnect until it is safe to remove it (see CleanupStaleKonnectCertificates). When the DataPlane name must be truncated, a hash of the full name is retained to distinguish names with a shared prefix.

func CertificateChecksum added in v2.4.0

func CertificateChecksum(secret *corev1.Secret) string

CertificateChecksum computes a stable checksum of a certificate Secret's tls.crt and tls.key content, used to trigger a Deployment rollout when a manually-referenced Secret is edited in place.

func CleanupStaleAutomaticCertificateSecret added in v2.4.0

func CleanupStaleAutomaticCertificateSecret(
	ctx context.Context,
	cl client.Client,
	logger logr.Logger,
	dp client.Object,
	labelKey string,
) error

CleanupStaleAutomaticCertificateSecret deletes the operator-provisioned Automatic certificate Secret(s) owned by dp and marked with labelKey, if any still exist after a switch to Manual provisioning. It must only be called once the Deployment rollout onto the Manual Secret is confirmed complete, so that no running replica is left depending on a Secret this removes. Switching back to Automatic later simply provisions a new one; nothing guarantees the switch back ever happens, so the Secret can't be left around indefinitely waiting for it (owner-reference GC alone would only remove it when the DataPlane itself is deleted).

func CleanupStaleKonnectCertificates added in v2.4.0

func CleanupStaleKonnectCertificates(
	ctx context.Context,
	cl client.Client,
	logger logr.Logger,
	dp client.Object,
	certs client.ObjectList,
	certKind string,
	currentCertName string,
) error

CleanupStaleKonnectCertificates deletes every Konnect certificate object of kind certKind controlled by dp except the one named currentCertName. certs is an empty list of that kind (e.g. &AIGatewayDataPlaneCertificateList{}) used to list the candidates. It must only be called once the Deployment rollout using the current certificate is confirmed complete, so that no running replica is left depending on a certificate this removes from Konnect (deleting the CR deprovisions the underlying certificate via the Konnect entity finalizer).

func DeploymentRolledOut added in v2.4.0

func DeploymentRolledOut(deployment *appsv1.Deployment) bool

DeploymentRolledOut reports whether no pod of the Deployment runs anything but its current Pod template: the rollout completed, or it is scaled to zero, and no pod is left terminating, as far as status.terminatingReplicas reports them.

func EnqueueDataPlanesByIndex added in v2.4.0

func EnqueueDataPlanesByIndex(
	cl client.Client,
	newObjectList func() client.ObjectList,
	refIndexField string,
	kind string,
	refKind string,
) handler.MapFunc

EnqueueDataPlanesByIndex returns a MapFunc that enqueues reconcile requests for all DataPlanes whose refIndexField index entry ("namespace/name") matches the changed object. It backs both the control plane watches and the watch on manually-referenced certificate Secrets: operator-owned certificate Secrets are already covered by Owns(&corev1.Secret{}), but a user-owned one is only tied to its DataPlanes through that index. refKind is the changed object's kind, used in logs.

func GenerateBaseDeployment added in v2.4.0

func GenerateBaseDeployment[T Object](
	logger logr.Logger,
	dp T,
	cp ResolvedControlPlane,
	image string,
	certSecretName string,
	adminCertSecretName string,
	certChecksum string,
	cfg DeploymentConfig[T],
	checksumAnnotation string,
) (*appsv1.Deployment, error)

GenerateBaseDeployment creates the operator-managed DataPlane Deployment without user overlays.

func GenerateBaseService added in v2.4.0

func GenerateBaseService[T Object](dp T, cfg ServiceConfig[T]) *corev1.Service

GenerateBaseService returns the operator defaults for the Service: the pod selector and a default port. These are used only when the user has not provided conflicting values in ServiceOptions.

Service.spec.ports is a list-map keyed by [port, protocol], so SSA merges ports by port number. Two ports with different port numbers but the same name would both be kept after the merge, causing Kubernetes to reject the Service (port names must be unique). To prevent this, any base port whose name is already used by a user-provided port is omitted here so the user's port wins cleanly.

func GenerateServiceOverlay added in v2.4.0

func GenerateServiceOverlay[T Object](dp T, cfg ServiceConfig[T], opts *ServiceOptions) *corev1.Service

GenerateServiceOverlay builds a Service skeleton from the user-provided ServiceOptions. It is merged onto the base by MergeObjects, where the overlay wins on conflicts; the base only supplies the fields the overlay leaves unset (selector, default port).

func GetManualCertificateSecret added in v2.4.0

func GetManualCertificateSecret(
	ctx context.Context,
	cl client.Client,
	dp Object,
	secretName string,
	conds ManualCertificateConditions,
) (op.Result, *corev1.Secret, error)

GetManualCertificateSecret fetches the user-referenced certificate Secret named secretName and validates it contains a usable TLS certificate and key, reporting the outcome through conds. The operator never creates, modifies, rotates, or deletes this Secret. The reference is always resolved in the DataPlane's own namespace: a Secret can only ever be mounted into a Pod's volumes from that Pod's own namespace, so cross-namespace references are not supported.

func ResolveImage added in v2.4.0

func ResolveImage[T Object](dp T, cfg DeploymentConfig[T]) string

ResolveImage determines the DataPlane container image using the following priority:

  1. User-specified image in the pod template overlay (the DataPlane container)
  2. The related-image environment variable
  3. The configured default image

func SelectorLabels added in v2.4.0

func SelectorLabels[T Object](dp T, managedByLabelValue string) map[string]string

SelectorLabels returns the labels uniquely identifying the pods of the given DataPlane.

func SetLicenseStatusCondition added in v2.4.0

func SetLicenseStatusCondition(
	dp k8sutils.ConditionsAndGenerationAware,
	getter LicenseGetter,
	condType, validReason, missingReason string,
)

SetLicenseStatusCondition sets the license condition on dp based on the effective license provided by getter. It is a no-op when getter is nil or condType is empty (license reporting disabled). The condition never gates the Ready condition; see ensureReadyStatus. ponytail: no license validation is wired yet, so LicenseInvalidReason never fires; wire a ValidatorFunc into the KongLicense reconciler and map GetValidatedLicense().IsValid here when validation is needed.

Types

type AdminAPIConfig added in v2.4.0

type AdminAPIConfig[T Object] struct {
	// Enabled reports whether the Admin API should be exposed for the
	// DataPlane given its resolved control plane. cp is the zero
	// ResolvedControlPlane when the DataPlane has no control plane reference
	// configured. Must not be nil.
	Enabled func(dp T, cp ResolvedControlPlane) bool
	// ServiceNameSuffix is appended to the DataPlane name to form the admin
	// Service name (e.g. "-admin"). Must not be empty.
	ServiceNameSuffix string
	// ServicePortName is the name of the admin Service port (e.g. "admin").
	ServicePortName string
	// ServicePort is the port the admin Service exposes. Must be positive.
	ServicePort int32
	// ManagedByLabelValue is the value of the managed-by label used in the
	// admin Service selector.
	ManagedByLabelValue string
	// CertificateLabelKey marks the provisioned Admin API TLS server
	// certificate Secret. It must be distinct from Certificate.LabelKey so
	// the two Secrets never collide in the owner-scoped Secret listings
	// performed during provisioning. Must not be empty.
	CertificateLabelKey string
}

AdminAPIConfig carries the configuration of the DataPlane's Admin API exposure: a dedicated admin Service and a TLS server certificate for it, both gated on the same Enabled predicate. Control plane kinds that push configuration to the DataPlane over its Admin API (e.g. OnPremAIGateway) enable it. The certificate's subject is derived from the Service name: the in-cluster DNS name the control plane uses to reach the Admin API.

type CertificateConfig added in v2.4.0

type CertificateConfig[T Object, Cert CertificateObject] struct {
	// LabelKey marks the provisioned mTLS client certificate Secret. It must
	// be distinct from AdminAPI.CertificateLabelKey so the two Secrets never
	// collide in the owner-scoped Secret listings performed during
	// provisioning.
	LabelKey string
	// Kind is the certificate resource kind used in logs, errors and events
	// (e.g. "AIGatewayDataPlaneCertificate").
	Kind string
	// Build builds the desired certificate object for the DataPlane.
	// certChecksum identifies the certificate Secret's content ("" when
	// checksum tracking is not configured): controllers that name the
	// certificate entity after the content should derive both the object name
	// and the Konnect title from it so a rotation registers a new entity
	// instead of mutating the previous one in place.
	// Only called for control planes registering the certificate
	// (cp.RegistersCertificate): Konnect-backed ones, and non-Konnect kinds
	// with CertificateRegistration.
	Build func(dp T, cp ResolvedControlPlane, certSecretName, certChecksum string) Cert
	// AdaptToExisting, when non-nil, is called with the desired certificate
	// built by Build and the certificate currently stored in the cluster
	// (only when one exists) before the desired one is applied. It lets the
	// controller keep fields of the existing object that must not change,
	// e.g. which of two equivalent reference fields is in use.
	AdaptToExisting func(desired, existing Cert)
	// Ensure provisions (or finds) the DataPlane's TLS certificate Secrets,
	// signed by the cluster CA: the mTLS client certificate Secret, and the
	// Admin API TLS server certificate Secret when AdminAPI is
	// configured. It is invoked on both provisioning paths, so overriding it
	// affects both.
	Ensure EnsureCertificateFunc[T]
	// Resolve, when non-nil, resolves the mTLS client certificate Secret
	// before the default Ensure-based provisioning runs. It may:
	//   - return a non-nil Secret to use it as-is (e.g. a manually
	//     provisioned, user-referenced Secret);
	//   - return (op.Result, nil, nil) to wire no certificate at all (a
	//     condition explaining why is expected to be set on dp);
	//   - call resolveAutomatic to fall back to the default operator-managed
	//     provisioning;
	//   - return a *RequeueAfterError when the certificate can't be used yet
	//     but will become usable on its own (a condition explaining why is
	//     expected to be set on dp): the DataPlane is reconciled again after
	//     its After delay instead of being retried with error backoff.
	Resolve func(
		ctx context.Context,
		cl client.Client,
		dp T,
		cp ResolvedControlPlane,
		resolveAutomatic func(ctx context.Context, dp T) (op.Result, *corev1.Secret, error),
	) (op.Result, *corev1.Secret, error)
	// Requested, when non-nil, reports whether the DataPlane spec asks for
	// the mTLS client certificate at all. When resolution produced no
	// Secret, the reconcile only stops early if a certificate was requested
	// but could not be resolved (a condition explaining why is expected to
	// be set on dp); a DataPlane that requests no certificate proceeds to
	// reconcile its Deployment without any certificate wiring. When nil, a
	// nil resolved Secret always stops the reconcile early.
	Requested func(dp T) bool
	// Checksum, when non-nil, returns a stable checksum of the certificate
	// Secret content, recorded as a Pod-template annotation so that an
	// in-place Secret edit rolls the Deployment.
	Checksum func(secret *corev1.Secret) string
	// ChecksumAnnotation is the Pod-template annotation key used with
	// Checksum. Required when Checksum is set.
	ChecksumAnnotation string
	// CleanupStale, when non-nil, removes stale certificate entities and
	// operator-provisioned Secrets once the rollout onto the current
	// certificate completed.
	// Unlike certificate registration, this hook is intentionally not gated
	// on cp.RegistersCertificate: stale certificate entities still need
	// cleanup after a DataPlane switches to a control plane that doesn't
	// register its certificate. Implementations must tolerate a resolved
	// control plane of any configured kind (or an unconfigured one).
	CleanupStale func(ctx context.Context, cl client.Client, logger logr.Logger, dp T, cp ResolvedControlPlane, certChecksum string) error
	// RequeueAfter, when non-nil, returns when the resolved certificate must
	// be checked again, e.g. for its renewal, or 0. The reconcile is requeued
	// for the earliest of it and the expiry of a manual certificate. It isn't
	// called when no certificate Secret is resolved. cp is empty, with a nil
	// Object, when the DataPlane has no control plane reference.
	RequeueAfter func(dp T, cp ResolvedControlPlane, secret *corev1.Secret, now time.Time) time.Duration
}

CertificateConfig groups the configuration of the DataPlane's TLS certificates: the mTLS client certificate used for the outbound connection to a Konnect-backed control plane (provisioning, optional manual resolution, Konnect registration and stale cleanup) and — when AdminAPI is configured — the Admin API TLS server certificate provisioned for on-prem control planes. Both Secrets are provisioned through the same Ensure hook.

type CertificateObject added in v2.4.0

type CertificateObject interface {
	client.Object
	GetConditions() []metav1.Condition
}

CertificateObject is the constraint for the Konnect certificate types provisioned for the DataPlane (e.g. AIGatewayDataPlaneCertificate, EventGatewayDataPlaneCertificate).

type CertificateRegistrationConditions added in v2.4.0

type CertificateRegistrationConditions struct {
	// Type is the type of the condition.
	Type string
	// RegisteredReason is the reason used once the certificate is Programmed.
	RegisteredReason string
	// RegistrationFailedReason is the reason used when the certificate object
	// can't be ensured.
	RegistrationFailedReason string
	// NotProgrammedReason is the reason used while the certificate object is
	// not Programmed.
	NotProgrammedReason string
	// Target names what the certificate is registered on, e.g. "gw-admin".
	Target string
	// NotProgrammedHint, when set, is appended as is, so with its own leading
	// space, to the message used while the certificate object has no
	// Programmed condition, e.g. to name what programs it.
	NotProgrammedHint string
	// ReportProgrammedCondition, when set, adds the reason and message of the
	// Programmed condition of the certificate object, when it has one, to the
	// message used while it is not Programmed.
	ReportProgrammedCondition bool
	// CreatedEventReason and CreatedEventAction are the reason and action of
	// the event recorded on the DataPlane when the certificate object is
	// created.
	CreatedEventReason string
	CreatedEventAction string
	// UpdatedEventReason and UpdatedEventAction are the reason and action of
	// the event recorded on the DataPlane when the certificate object is
	// updated.
	UpdatedEventReason string
	UpdatedEventAction string
}

CertificateRegistrationConditions carries the condition type and reasons a non-Konnect control plane kind reports the registration of the client certificate of the DataPlane with, and the name of what it is registered on for the messages. Konnect-backed kinds use the Konnect certificate conditions of Config.Conditions.

type Conditions added in v2.4.0

type Conditions struct {
	// ReadyType is the type of the top-level Ready condition.
	ReadyType string
	// ResourceReadyReason is the reason used when the resource is ready.
	ResourceReadyReason string
	// DependenciesNotReadyReason is the reason used when another condition is not true.
	DependenciesNotReadyReason string
	// DependenciesNotReadyMessage is the message used when the Deployment does not exist yet.
	DependenciesNotReadyMessage string
	// WaitingToBecomeReadyReason is the reason used while the Deployment rollout is in progress.
	WaitingToBecomeReadyReason string
	// WaitingToBecomeReadyMessage is the message used while the Deployment rollout is in progress.
	WaitingToBecomeReadyMessage string
	// UnableToProvisionReason is the reason used when provisioning a resource fails.
	UnableToProvisionReason string

	// CertificateProvisionedType is the type of the mTLS certificate Secret condition.
	CertificateProvisionedType string
	// CertificateProvisionedReason is the reason used when the certificate Secret has been provisioned.
	CertificateProvisionedReason string

	// KonnectCertificateRegisteredType is the type of the Konnect certificate registration condition.
	KonnectCertificateRegisteredType string
	// KonnectCertificateRegisteredReason is the reason used when the certificate is ensured and programmed.
	KonnectCertificateRegisteredReason string
	// KonnectCertificateRegistrationFailedReason is the reason used when the certificate could not be ensured.
	KonnectCertificateRegistrationFailedReason string
	// KonnectCertificateNotProgrammedReason is the reason used when the certificate is not yet programmed on Konnect.
	KonnectCertificateNotProgrammedReason string

	// ServiceReadyType is the type of the Service readiness condition.
	ServiceReadyType string
	// ServiceReadyReason is the reason used when the Service is ready.
	ServiceReadyReason string
	// ServiceReadyMessage is the message used when the Service is ready.
	ServiceReadyMessage string
	// WaitingForAddressReason is the reason used while the Service waits for an external address.
	WaitingForAddressReason string
	// WaitingForAddressMessage is the message used while the Service waits for an external address.
	WaitingForAddressMessage string

	// AdminCertificateProvisionedType is the type of the Admin API server
	// certificate condition. Only used when AdminAPI is configured.
	AdminCertificateProvisionedType string
	// AdminCertificateProvisionedReason is the reason used when the Admin
	// API certificate Secret has been provisioned.
	AdminCertificateProvisionedReason string

	// LicenseValidType is the type of the license condition. When empty, the
	// license condition is disabled (the reconciler never sets it and the
	// Ready computation ignores the feature).
	LicenseValidType string
	// LicenseValidReason is the reason used when a license is available.
	LicenseValidReason string
	// LicenseMissingReason is the reason used when no license is available.
	LicenseMissingReason string
	// LicenseInvalidReason is the reason used when the license is invalid.
	// Currently unused: the operator does not wire a license validator yet.
	LicenseInvalidReason string
}

Conditions carries the condition types, reasons and messages used by the reconciler. Values are supplied by each specialized controller from its API package constants so the shared logic stays bound to the API definitions.

type Config added in v2.4.0

type Config[T Object, Cert CertificateObject] struct {
	// ControllerName is the name used for logging and event recording.
	ControllerName string
	// Kind is the human-readable DataPlane kind used in logs, errors and
	// events (e.g. "AIGatewayDataPlane", "KegDataPlane").
	Kind string
	// GVK identifies the DataPlane kind in a KongReferenceGrant. Only used by
	// a kind whose control plane references can name a namespace.
	GVK metav1.GroupVersionKind

	// NewObject returns a new empty DataPlane object.
	NewObject func() T
	// NewCertificateObject returns a new empty certificate object.
	NewCertificateObject func() Cert
	// NewObjectList returns a new empty DataPlane list object, used by the
	// control plane watches to list the DataPlanes referencing them.
	NewObjectList func() client.ObjectList

	// ControlPlaneRef returns the kind and name of the control plane referenced
	// by the DataPlane. Name is empty when the DataPlane has no control plane
	// reference configured; in that case control plane resolution and Konnect
	// certificate automation are skipped.
	// The returned Kind must match the Kind of one of the ControlPlanes entries.
	ControlPlaneRef func(T) ControlPlaneRef
	// ControlPlanes lists the supported control plane kinds for this DataPlane
	// kind (e.g. KonnectAIGateway and OnPremAIGateway for AIGatewayDataPlane).
	// One watch and one index field are registered per entry.
	ControlPlanes []ControlPlaneKindConfig

	// Conditions carries the condition types, reasons and messages.
	Conditions Conditions

	// Certificate configures the DataPlane's TLS certificates.
	Certificate CertificateConfig[T, Cert]
	// ExtraWatches, when non-nil, registers additional watches on the
	// controller builder (e.g. a watch on user-referenced certificate
	// Secrets). It receives the in-progress builder and must return it.
	ExtraWatches func(blder *builder.Builder, mgr ctrl.Manager) *builder.Builder

	// Deployment configures the owned Deployment.
	Deployment DeploymentConfig[T]

	// Service configures the Ingress Service: the one feeding the DataPlane
	// status (SetStatusAddresses) and driving the ServiceReady condition.
	// It is always reconciled and never removed, so Enabled does not apply
	// to it and must be left nil.
	Service ServiceConfig[T]

	// AdminAPI, when non-nil, enables the exposure of the DataPlane's Admin
	// API: a dedicated admin Service and a TLS server certificate for it,
	// both gated on AdminAPI.Enabled. The certificate Secret is provisioned
	// through Certificate.Ensure, which has it signed by the cluster CA, and
	// its name is passed to Deployment.BuildContainer so the container can
	// wire the admin listener to it.
	AdminAPI *AdminAPIConfig[T]

	// SetStatusReplicas copies the Deployment replica counts into the DataPlane status.
	SetStatusReplicas func(dp T, replicas, readyReplicas int32)
}

Config wires the type specific behavior of a specialized DataPlane reconciler into the shared generic Reconciler.

func (Config[T, Cert]) ControlPlaneKindConfig added in v2.4.0

func (c Config[T, Cert]) ControlPlaneKindConfig(kind string) (ControlPlaneKindConfig, bool)

ControlPlaneKindConfig returns the ControlPlaneKindConfig for the given kind.

type ControlPlaneConditions added in v2.4.0

type ControlPlaneConditions struct {
	// ResolvedType is the type of the control plane resolution condition.
	ResolvedType string
	// ResolvedReason is the reason used when the control plane has been resolved.
	ResolvedReason string
	// ResolvedMessage is the message used when the control plane has been resolved.
	ResolvedMessage string
	// NotFoundReason is the reason used when the control plane was not found.
	NotFoundReason string
	// NotFoundMessage is the message used when the control plane was not found.
	NotFoundMessage string
	// NotPermittedReason is the reason used when the control plane is in
	// another namespace and no KongReferenceGrant allows the reference. Only
	// used by a kind whose references can name a namespace.
	NotPermittedReason string
	// NotProgrammedReason is the reason used when the control plane is not yet Programmed.
	NotProgrammedReason string
	// NotProgrammedMessage is the message used when the control plane is not yet Programmed.
	NotProgrammedMessage string
	// NotReadyReason is the reason used when a non-Konnect control plane is not yet Ready.
	// Only used when the kind config sets ReadinessConditionType.
	NotReadyReason string
	// NotReadyMessage is the message used when a non-Konnect control plane is not yet Ready.
	// Only used when the kind config sets ReadinessConditionType.
	NotReadyMessage string
	// EndpointMismatchReason is the reason used when the control plane returns
	// endpoints its serverURL cannot be used with. The condition message is the
	// error returned by the kind's EndpointCheck, so it names the endpoint.
	// Only used when the kind config sets EndpointCheck.
	EndpointMismatchReason string
}

ControlPlaneConditions carries the condition types, reasons and messages used when resolving a control plane of a given kind. Values are supplied by each specialized controller from its API package constants.

type ControlPlaneKindConfig added in v2.4.0

type ControlPlaneKindConfig struct {
	// Kind is the human-readable control plane kind used in logs, errors and
	// events (e.g. "KonnectAIGateway", "OnPremAIGateway").
	Kind string
	// GVK identifies the control plane kind in a KongReferenceGrant. Only used
	// by a kind whose references can name a namespace.
	GVK metav1.GroupVersionKind
	// NewObject returns a new empty control plane object of this kind.
	NewObject func() ControlPlaneObject
	// ControlPlaneRefIndexField is the field index used to list DataPlanes by
	// their reference to this kind of control plane.
	ControlPlaneRefIndexField string
	// IsKonnect reports whether this control plane kind is Konnect-backed.
	// Konnect-backed control planes are checked for the Konnect Programmed
	// condition during resolution and trigger Konnect certificate automation.
	IsKonnect bool
	// ReadinessConditionType is the condition type on a non-Konnect control
	// plane (e.g. "Ready" for OnPremAIGateway) that must be True for the
	// control plane to be considered resolved. When empty, a non-Konnect
	// control plane is considered resolved as soon as it exists.
	ReadinessConditionType string
	// EndpointCheck reports whether the control plane's endpoints are usable
	// with its serverURL, naming the offending endpoint in the error. dp is
	// the reconciled DataPlane, for kinds whose verdict depends on its spec.
	// A non-nil error holds the DataPlane: it sets Resolved=False with
	// Conditions.EndpointMismatchReason and returns errEndpointsMismatch.
	// Nil for kinds that have no such endpoints.
	EndpointCheck func(dp Object, cp ControlPlaneObject) error
	// Conditions carries the control plane resolution condition types, reasons
	// and messages for this kind.
	Conditions ControlPlaneConditions
	// DisabledMessage, when set, disables the kind, e.g. when its CRDs are
	// not installed: no watch is registered for it, and a DataPlane
	// referencing it is reported in the resolution condition with
	// Conditions.NotFoundReason and this message, and not retried.
	DisabledMessage string
	// Dependencies, when set, reads what the DataPlane needs besides the
	// control plane object once it is resolved, e.g. the trust material of
	// an on-prem control plane. The result is carried in
	// ResolvedControlPlane.Dependencies. A *DependenciesNotReadyError is
	// reported in the resolution condition, with Conditions.NotReadyReason.
	Dependencies func(ctx context.Context, cl client.Client, cp ControlPlaneObject) (any, error)
	// CertificateRegistration, when set, makes the DataPlane register its
	// client certificate on the control plane through a certificate object
	// (Config.Certificate.Build), and wait for it to be Programmed before
	// building the Deployment, as Konnect-backed kinds do. It is meant for
	// non-Konnect kinds: on a Konnect-backed kind it replaces the Konnect
	// certificate conditions of Config.Conditions.
	CertificateRegistration *CertificateRegistrationConditions
}

ControlPlaneKindConfig describes one kind of control plane that a DataPlane can reference. A DataPlane kind lists one entry per supported control plane kind in Config.ControlPlanes; each entry gets its own watch and index field.

type ControlPlaneObject added in v2.4.0

type ControlPlaneObject interface {
	client.Object
	GetConditions() []metav1.Condition
}

ControlPlaneObject is the constraint for the control plane types referenced by the DataPlane (e.g. KonnectAIGateway, KonnectEventGateway, OnPremAIGateway).

type ControlPlaneRef added in v2.4.0

type ControlPlaneRef struct {
	// Kind is the human-readable kind of the referenced control plane. It must
	// match the Kind of one of the Config's ControlPlanes entries.
	Kind string
	// Name is the name of the referenced control plane. It is empty when the
	// DataPlane has no control plane reference configured.
	Name string
	// Namespace is the namespace of the referenced control plane, the
	// DataPlane's when empty. Another namespace needs a KongReferenceGrant.
	Namespace string
}

ControlPlaneRef identifies the control plane referenced by a DataPlane.

type DependenciesNotReadyError added in v2.4.0

type DependenciesNotReadyError struct {
	Message string
	// ControlPlaneGone tells the control plane won't be resolved again, e.g.
	// it is being deleted: the DataPlane is then released from it (see
	// DeploymentConfig.ControlPlaneGone), like when it doesn't exist.
	ControlPlaneGone bool
}

DependenciesNotReadyError is returned by ControlPlaneKindConfig.Dependencies when something the DataPlane needs from the control plane is not available yet. The resolution condition is set to False with the NotReadyReason of the kind and the message of the error, and the reconcile is not retried: a watch must trigger it again.

func (*DependenciesNotReadyError) Error added in v2.4.0

func (e *DependenciesNotReadyError) Error() string

type DeploymentConfig added in v2.4.0

type DeploymentConfig[T Object] struct {
	// ContainerName is the name of the DataPlane container (e.g. "aigw", "keg").
	ContainerName string
	// RelatedImageEnvVar is the environment variable used to override the container image.
	RelatedImageEnvVar string
	// DefaultImage is the fallback container image.
	DefaultImage string
	// ManagedByLabelValue is the value of the managed-by label (e.g. "aigateway-dataplane", "dataplane").
	ManagedByLabelValue string

	// PodTemplateSpec returns the user-provided pod template overlay, or nil.
	PodTemplateSpec func(T) *corev1.PodTemplateSpec
	// DeploymentLabels returns the user-provided Deployment labels, or nil.
	DeploymentLabels func(T) map[string]string
	// DeploymentAnnotations returns the user-provided Deployment annotations, or nil.
	DeploymentAnnotations func(T) map[string]string

	// BuildContainer builds the DataPlane container and the additional volumes
	// it requires. The Konnect certificate volume itself is managed by the
	// shared machinery and appended separately when certSecretName is not empty,
	// and so is the Admin API certificate volume when adminCertSecretName is
	// not empty. cp.Object is nil when the DataPlane has no control plane
	// reference configured.
	BuildContainer func(dp T, cp ResolvedControlPlane, image, certSecretName, adminCertSecretName string) (corev1.Container, []corev1.Volume, error)
	// ReassertEnvVars lists env var names that the operator injects into the
	// DataPlane container and that must win over a user pod template overlay
	// (e.g. KONG_LICENSE_DATA): MergeObjects lets the overlay win on conflicts,
	// so the overlay's conflicting entries are dropped before the merge, like
	// the certificate checksum annotation is re-asserted after it. Leave it
	// empty for DataPlanes that inject no such env vars.
	ReassertEnvVars []string
	// ReassertVolumes lists names of volumes the operator mounts in the
	// DataPlane container that a user pod template overlay must not replace:
	// the overlay's volumes of the same names, its mounts of them, and its
	// mounts at their mount paths in the DataPlane container are dropped
	// before the merge. Only the volumes the operator actually added are.
	ReassertVolumes []string
	// LabelManaged, when non-nil, marks the Deployment and its pod template as
	// managed (e.g. k8sresources.LabelObjectAsAIGatewayDataPlaneManaged).
	LabelManaged func(metav1.Object)
	// TerminationGracePeriodSeconds, when non-nil, returns the termination
	// grace period of the DataPlane pods, e.g. long enough for the DataPlane
	// to drain its connections, or nil to keep the Kubernetes default. A
	// value the user pod template overlay sets wins.
	TerminationGracePeriodSeconds func(T) *int64
	// ControlPlaneGone, when non-nil, adjusts the existing Deployment once its
	// control plane won't be resolved again: it doesn't exist, or is being
	// deleted (see DependenciesNotReadyError.ControlPlaneGone). The
	// Deployment isn't rebuilt then, so what Customize set for the control
	// plane stays otherwise, e.g. labels other controllers select the data
	// planes of the control plane with.
	// It is called for a control plane of any configured kind, on every
	// reconcile while the control plane is gone, and possibly before the
	// Deployment exists: implementations must be idempotent and tolerate a
	// missing Deployment.
	ControlPlaneGone func(ctx context.Context, cl client.Client, dp T) error
	// ControlPlaneNotPermitted, when non-nil, is called, on every reconcile,
	// while no KongReferenceGrant lets the data plane reference its control
	// plane of another namespace: the owner of the control plane revoked its
	// trust, e.g. to disconnect the data plane. Implementations must be
	// idempotent and tolerate a missing Deployment.
	ControlPlaneNotPermitted func(ctx context.Context, cl client.Client, dp T) error
	// IgnoredSettings, when non-nil, returns, for each setting of the
	// DataPlane its container of the image doesn't read, why it is ignored:
	// each is reported as a Warning Event on the DataPlane when its
	// Deployment is built.
	IgnoredSettings func(dp T, image string) []string
	// Customize, when non-nil, adjusts the operator base Deployment for the
	// resolved control plane, after the user Deployment labels and
	// annotations are applied and before the user PodTemplateSpec overlay is
	// merged, e.g. to label it for the control plane. The labels and
	// annotations maps of the Deployment and of its Pod template may be
	// shared: replace them rather than mutating them. cp is empty, with a nil
	// Object, when the DataPlane has no control plane reference.
	Customize func(dp T, cp ResolvedControlPlane, d *appsv1.Deployment)
}

DeploymentConfig carries the type specific bits of the owned Deployment.

type EnsureCertificateFunc added in v2.4.0

type EnsureCertificateFunc[T Object] func(
	ctx context.Context,
	owner T,
	subject string,
	mtlsCASecretNN types.NamespacedName,
	usages []certificatesv1.KeyUsage,
	cl client.Client,
	additionalMatchingLabels client.MatchingLabels,
	certTTL time.Duration,
) (op.Result, *corev1.Secret, error)

EnsureCertificateFunc provisions (or finds) a TLS certificate Secret for a DataPlane, signed by the cluster CA: the mTLS client certificate used for the outbound connection to a Konnect-backed control plane, and the Admin API TLS server certificate when AdminAPI is configured. It mirrors secrets.EnsureCertificate, which cannot be called from generic code because of its union type constraint; pass an explicitly instantiated secrets.EnsureCertificate[*YourDataPlane] here.

type KongLicenseCacheGetter added in v2.4.0

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

KongLicenseCacheGetter is a LicenseGetter that picks the effective KongLicense directly from the manager's shared, informer-backed cache. Unlike the KongLicense reconciler's own cache, this is updated before watch events are delivered, so a reconcile triggered by a KongLicense add/update/delete never observes a stale license (no cross-workqueue ordering race).

func NewKongLicenseCacheGetter added in v2.4.0

func NewKongLicenseCacheGetter(r client.Reader) *KongLicenseCacheGetter

NewKongLicenseCacheGetter returns a LicenseGetter backed by the given (informer-backed) client reader.

func (KongLicenseCacheGetter) GetLicense added in v2.4.0

func (g KongLicenseCacheGetter) GetLicense() mo.Option[kong.License]

GetLicense returns the newest enabled KongLicense in the cache, in Kong configuration format. It does not check license validity.

type LicenseGetter added in v2.4.0

type LicenseGetter interface {
	GetLicense() mo.Option[kong.License]
}

LicenseGetter provides the effective Kong license for DataPlane deployments. It is satisfied by the KongLicense reconciler (ingress-controller/internal/controllers/license); the local interface keeps this shared package decoupled from the KIC internals.

type ManualCertificateConditions added in v2.4.0

type ManualCertificateConditions struct {
	// Type is the type of the certificate condition.
	Type string
	// ProvisionedReason is the reason used when the Secret is valid.
	ProvisionedReason string
	// UnableToProvisionReason is the reason used when reading the Secret fails.
	UnableToProvisionReason string
	// SecretRefNotFoundReason is the reason used when the Secret does not exist.
	SecretRefNotFoundReason string
	// SecretRefNotFoundMessage formats the message used when the Secret does not exist.
	SecretRefNotFoundMessage func(name string) string
	// SecretInvalidReason is the reason used when the Secret has no usable TLS pair.
	SecretInvalidReason string
	// SecretInvalidMessage is the message used when the Secret has no usable
	// TLS pair. The specific validation failure is appended to it.
	SecretInvalidMessage string
	// SecretOperatorManagedReason is the reason used when the Secret is an
	// operator-provisioned (Automatic) certificate Secret.
	SecretOperatorManagedReason string
	// SecretOperatorManagedMessage is the message used when the Secret is an
	// operator-provisioned (Automatic) certificate Secret.
	SecretOperatorManagedMessage string
}

ManualCertificateConditions carries the condition type, reasons and messages GetManualCertificateSecret reports on the DataPlane. Values are supplied by each specialized controller from its API package constants.

type Object added in v2.4.0

type Object interface {
	client.Object
	k8sutils.ConditionsAware
	hpa.Owner
}

Object is the constraint for the reconciled DataPlane types (e.g. AIGatewayDataPlane, KegDataPlane).

type Reconciler added in v2.4.0

type Reconciler[T Object, Cert CertificateObject] struct {
	client.Client

	// LoggingMode controls the format of log output.
	LoggingMode logging.Mode

	ClusterCASecretName      string
	ClusterCASecretNamespace string
	SecretLabelSelector      string
	CertTTL                  time.Duration

	// TypeConverter is injected via the TypeConverterProvider at controller
	// registration time. It is used for both diff-before-apply and
	// structured-merge-diff based PodTemplateSpec merging.
	TypeConverter managedfields.TypeConverter

	// EventRecorder records Kubernetes events on the DataPlane objects.
	EventRecorder events.EventRecorder

	// LicenseGetter, when non-nil, provides the effective Kong license: the
	// reconciler propagates it to the gateway (via the type-specific
	// DeploymentConfig.BuildContainer) and reports its availability in the
	// license condition configured in Config.Conditions.
	LicenseGetter LicenseGetter

	// Config wires the type specific behavior.
	Config Config[T, Cert]
}

Reconciler reconciles a specialized DataPlane object (e.g. AIGatewayDataPlane, KegDataPlane) using the behavior provided by Config.

func (*Reconciler[T, Cert]) Reconcile added in v2.4.0

func (r *Reconciler[T, Cert]) Reconcile(ctx context.Context, dp T) (res ctrl.Result, err error)

Reconcile moves the current state of a DataPlane toward the desired state.

func (*Reconciler[T, Cert]) SetupWithManager added in v2.4.0

func (r *Reconciler[T, Cert]) SetupWithManager(ctx context.Context, mgr ctrl.Manager) error

SetupWithManager sets up the controller with the Manager.

type RequeueAfterError added in v2.4.0

type RequeueAfterError struct {
	// After is the delay after which the DataPlane should be reconciled again.
	After time.Duration
	// Err describes why the certificate can't be used yet.
	Err error
}

RequeueAfterError is returned by certificate resolution when the certificate can't be used yet but will become usable on its own at a known time (e.g. a certificate whose NotBefore is in the future). The shared reconciler requeues the DataPlane after After instead of retrying with error backoff; the reason is surfaced through a status condition.

func (*RequeueAfterError) Error added in v2.4.0

func (e *RequeueAfterError) Error() string

Error returns the reason the certificate can't be used yet.

func (*RequeueAfterError) Unwrap added in v2.4.0

func (e *RequeueAfterError) Unwrap() error

Unwrap returns the underlying reason the certificate can't be used yet.

type ResolvedControlPlane added in v2.4.0

type ResolvedControlPlane struct {
	// Kind is the human-readable kind of the resolved control plane
	// (e.g. "KonnectAIGateway", "OnPremAIGateway").
	Kind string
	// IsKonnect reports whether the control plane is a Konnect-backed entity.
	// Only Konnect-backed control planes are checked for the Konnect Programmed
	// condition during resolution and trigger Konnect certificate automation.
	IsKonnect bool
	// Object is the resolved control plane object. It is nil when the DataPlane
	// has no control plane reference configured.
	Object ControlPlaneObject
	// Dependencies is what ControlPlaneKindConfig.Dependencies read for the
	// control plane, or nil.
	Dependencies any
	// CertificateRegistration is the ControlPlaneKindConfig.CertificateRegistration
	// of the kind of the control plane.
	CertificateRegistration *CertificateRegistrationConditions
}

ResolvedControlPlane carries the control plane resolved for a DataPlane through the reconcile flow. It abstracts over the concrete control plane kinds a DataPlane can reference (e.g. KonnectAIGateway, OnPremAIGateway for AIGatewayDataPlane); specialized controllers type-assert Object to the concrete type they support.

func (ResolvedControlPlane) IsResolved added in v2.4.0

func (cp ResolvedControlPlane) IsResolved() bool

IsResolved reports whether the DataPlane has a control plane reference resolved.

func (ResolvedControlPlane) RegistersCertificate added in v2.4.0

func (cp ResolvedControlPlane) RegistersCertificate() bool

RegistersCertificate reports whether the client certificate of the DataPlane is registered on the control plane through a certificate object.

type ServiceConfig added in v2.4.0

type ServiceConfig[T Object] struct {
	// Description is the human-readable Service description used in logs,
	// errors and events (e.g. "Ingress", "Kafka").
	Description string
	// NameSuffix is appended to the DataPlane name to form the Service name (e.g. "-ingress").
	NameSuffix string
	// DefaultPortName is the name of the default port (e.g. "ingress").
	DefaultPortName string
	// DefaultPort is the port exposed by default.
	DefaultPort int32
	// ManagedByLabelValue is the value of the managed-by label used in the
	// Service selector (e.g. "aigateway-dataplane", "dataplane").
	ManagedByLabelValue string
	// Options returns the user-provided Service options, or nil.
	Options func(T) *ServiceOptions
	// Enabled, when non-nil, reports whether this Service should be reconciled
	// for the DataPlane given its resolved control plane. A disabled Service
	// is not created, and a Service left over from an earlier reconcile in
	// which the predicate was true is removed. Only used on Services whose
	// existence is conditional (e.g. the Admin API Service derived from
	// AdminAPI): the primary Service always exists, so Config.Service.Enabled
	// must be left nil.
	Enabled func(dp T, cp ResolvedControlPlane) bool
	// SetStatusAddresses copies the Service's addresses into the DataPlane
	// status through this function; the Service's readiness feeds the
	// ServiceReady condition (see Conditions). Must be set on the primary
	// Service (Config.Service), which the status depends on; Services whose
	// existence is conditional (e.g. the Admin API Service derived from
	// AdminAPI) never set it.
	SetStatusAddresses func(dp T, addrs []operatorv1beta1.Address)
}

ServiceConfig carries the type specific bits of an owned Service. For Ingress Service, defined in Config.Service For Admin Service, derived by Config.AdminAPI.serviceConfig().

type ServiceOptions added in v2.4.0

type ServiceOptions struct {
	// Type determines how the Service is exposed.
	Type corev1.ServiceType
	// Annotations is an unstructured key value map stored with the Service resource.
	Annotations map[string]string
	// Labels are propagated to the Service.
	Labels map[string]string
	// ExternalTrafficPolicy describes how nodes distribute service traffic they
	// receive on one of the Service's externally-facing addresses.
	ExternalTrafficPolicy corev1.ServiceExternalTrafficPolicy
	// TrafficDistribution offers a way to express preferences for how traffic is
	// distributed to Service endpoints.
	TrafficDistribution *string
	// InternalTrafficPolicy describes how nodes distribute service traffic they
	// receive on the ClusterIP.
	InternalTrafficPolicy *corev1.ServiceInternalTrafficPolicy
	// Ports is the list of ports that are exposed by the Service.
	Ports []ServicePort
}

ServiceOptions mirrors the user-provided Service options of the specialized DataPlane APIs (e.g. spec.network.services.ingress). Each controller converts its API type into this shared representation.

type ServicePort added in v2.4.0

type ServicePort struct {
	// Name is the name of the port.
	Name *string
	// Port is the port that will be exposed by the Service.
	Port int32
	// TargetPort is the port on the pod the Service routes traffic to.
	TargetPort *intstr.IntOrString
	// NodePort is the port on each node on which the Service is exposed when
	// Type is NodePort or LoadBalancer.
	NodePort *int32
}

ServicePort contains information on a user-provided Service port.

Jump to

Keyboard shortcuts

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