ipamutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: Apache-2.0 Imports: 24 Imported by: 2

Documentation

Overview

Package ipamutil implements various utility functions to assist with CAPI IPAM implementation.

Index

Constants

View Source
const (
	// ReleaseAddressFinalizer is used to release an IP address before cleaning up the claim.
	ReleaseAddressFinalizer = "ipam.cluster.x-k8s.io/ReleaseAddress"

	// ProtectAddressFinalizer is used to prevent deletion of an IPAddress object while its claim is not deleted.
	ProtectAddressFinalizer = "ipam.cluster.x-k8s.io/ProtectAddress"
)

Variables

This section is empty.

Functions

func NewIPAddress

func NewIPAddress(claim *ipamv1.IPAddressClaim, pool client.Object) ipamv1.IPAddress

NewIPAddress creates a new ipamv1.IPAddress with references to a pool and claim.

Types

type ClaimHandler

type ClaimHandler interface {
	// FetchPool is called to fetch the pool referenced by the claim. The pool needs to be stored by the handler.
	FetchPool(ctx context.Context) (client.Object, *ctrl.Result, error)
	// EnsureAddress is called to make sure that the IPAddress.Spec is correct and the address is allocated.
	EnsureAddress(ctx context.Context, address *ipamv1.IPAddress) (*ctrl.Result, error)
	// ReleaseAddress is called to release the ip address that was allocated for the claim.
	ReleaseAddress(ctx context.Context) (*ctrl.Result, error)
}

ClaimHandler knows how to allocate and release IP addresses for a specific provider.

type ClaimReconciler

type ClaimReconciler struct {
	client.Client
	Scheme *runtime.Scheme

	WatchFilterValue string

	Adapter ProviderAdapter
}

ClaimReconciler reconciles a IPAddressClaim object using a ProviderAdapter. It can be used to implement custom IPAM providers without worrying about the basic lifecycle, pausing and owner references, which should be the same or very similar for any provider. The custom implementation for a specific provider is provided by implementing the ProviderAdapter interface. The ClaimReconciler can then be used as follows, with controllers.InClusterProviderAdapter serving as the provider implementation.

(&ipamutil.ClaimReconciler{
	Client:           mgr.GetClient(),
	Scheme:           mgr.GetScheme(),
	WatchFilterValue: watchFilter,
	Adapter: &controllers.InClusterProviderAdapter{},
}).SetupWithManager(ctx, mgr)

func (*ClaimReconciler) Reconcile

func (r *ClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error)

Reconcile is called by the controller to reconcile a claim.

func (*ClaimReconciler) SetupWithManager

func (r *ClaimReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) error

SetupWithManager sets up the controller with the Manager.

type ProviderAdapter

type ProviderAdapter interface {
	// SetupWithManager will be called during the setup of the controller for the ClaimReconciler to allow the provider
	// implementation to extend the controller configuration.
	SetupWithManager(context.Context, *ctrl.Builder) error
	// ClaimHandlerFor is called during reconciliation to get a ClaimHandler for the reconciled [ipamv1.IPAddressClaim].
	ClaimHandlerFor(client.Client, *ipamv1.IPAddressClaim) ClaimHandler
}

ProviderAdapter is an interface that must be implemented by the IPAM provider.

Jump to

Keyboard shortcuts

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