controller

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 49 Imported by: 0

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.

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

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)

func (*Controller) Run

func (c *Controller) Run(ctx context.Context, wg *sync.WaitGroup) 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

func WithK8sPredicate(p predicate.Predicate) Option

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.

func (*Reconciler) Reconcile

func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error)

Reconcile implements the reconcile.Reconciler Reconcile method.

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.

Jump to

Keyboard shortcuts

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