Documentation
¶
Overview ¶
Package controller is the core of the HAProxy Kubernetes Gateway Controller. It is responsible for watching for Kubernetes objects and converting them into a HAProxy configuration.
Copyright 2025 HAProxy Technologies LLC ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- func Add(ctx context.Context, cfg config.Configuration, ...) error
- func Register(params registerParams) error
- type Controller
- type Getter
- type NamespacedNameFilterFunc
- type NewReconcilerFunc
- type Option
- func WithEnqueueFor(l []enqueueForParams) Option
- func WithFieldIndices(fieldIndices index.FieldIndices) Option
- func WithK8sPredicate(p predicate.Predicate) Option
- func WithNamespacedNameFilter(filter NamespacedNameFilterFunc) Option
- func WithNewReconciler(newReconciler NewReconcilerFunc) Option
- func WithOnlyMetadata() Option
- type Reconciler
- type ReconcilerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶
func Add( ctx context.Context, cfg config.Configuration, haproxyClient hapi.HAProxyClient, mgr manager.Manager, ) error
func Register ¶
func Register(params registerParams) error
Register registers a new controller for the object type in the manager and configure it with the provided options. If the options include WithFieldIndices, it will add the specified indices to FieldIndexer of the manager. The registered controller will send events to the provided channel.
Types ¶
type Controller ¶
type Controller struct {
// HAProxyClient is set if Configuration.UpdateHaproxyThroughRuntime is true
HaproxyClient hapi.HAProxyClient
Configuration config.Configuration
}
func New ¶
func New(options config.GateConfigOptions) (Controller, error)
type Getter ¶
type Getter interface {
// Get is from client.Reader.
Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error
}
Getter gets a resource from the k8s API. Useful to mock the client.Reader.Get method.
type NamespacedNameFilterFunc ¶
type NamespacedNameFilterFunc func(nsname types.NamespacedName) (shouldProcess bool, msg string)
NamespacedNameFilterFunc is a function that returns true if the resource should be processed by the reconciler. If the function returns false, the reconciler will log the returned string.
type NewReconcilerFunc ¶
type NewReconcilerFunc func(cfg ReconcilerConfig) *Reconciler
type Option ¶
type Option func(*recConfig)
Option defines configuration options for registering a controller.
func WithEnqueueFor ¶ added in v0.8.0
func WithEnqueueFor(l []enqueueForParams) Option
WithEnqueueFor tells the controller to also watch for other types
func WithFieldIndices ¶
func WithFieldIndices(fieldIndices index.FieldIndices) Option
WithFieldIndices adds indices to the FieldIndexer of the manager.
func WithK8sPredicate ¶
WithK8sPredicate enables filtering of events before they are sent to the controller.
func WithNamespacedNameFilter ¶
func WithNamespacedNameFilter(filter NamespacedNameFilterFunc) Option
WithNamespacedNameFilter enables filtering of objects by NamespacedName by the controller.
func WithNewReconciler ¶
func WithNewReconciler(newReconciler NewReconcilerFunc) Option
WithNewReconciler allows us to mock reconciler creation in the unit tests.
func WithOnlyMetadata ¶
func WithOnlyMetadata() Option
WithOnlyMetadata tells the controller to only cache metadata, and to watch the API server in metadata-only form.
type Reconciler ¶
type Reconciler struct {
// contains filtered or unexported fields
}
Reconciler reconciles Kubernetes resources of a specific type. It implements the reconcile.Reconciler interface. A successful reconciliation of a resource has the two possible outcomes: (1) If the resource is deleted, the Implementation will send a DeleteEvent to the event channel. (2) If the resource is upserted (created or updated), the Implementation will send an UpsertEvent to the event channel.
func NewReconciler ¶
func NewReconciler(cfg ReconcilerConfig) *Reconciler
NewReconciler creates a new reconciler.
type ReconcilerConfig ¶
type ReconcilerConfig struct {
// Getter gets a resource from the k8s API.
Getter Getter
// ObjectType is the type of the resource that the reconciler will reconcile.
ObjectType client.Object
// EventCh is the channel where the reconciler will send events.
EventCh chan<- any
// NamespacedNameFilter filters resources the controller will process. Can be nil.
NamespacedNameFilter NamespacedNameFilterFunc
Logger *slog.Logger
OnlyMetadata bool
}
ReconcilerConfig is the configuration for the reconciler.