controller

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Predicate

func Predicate(clusterRingName, shardName string, predicates ...predicate.Predicate) predicate.Predicate

Predicate sets up a predicate that evaluates to true if a) the object needs to be drained or b) the given shard is responsible and all other predicates match. To support sharding in your controller, use this function to construct a predicate for the object kind given to `builder.Builder.For` (i.e., the controller's main kind). It is not needed to use this predicate for secondary watches (e.g., for object kinds given to `builder.Builder.{Owns,Watches}`) as secondary objects are not drained by the sharder.

Types

type Builder

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

Builder can build a sharded reconciler. Use NewShardedReconciler to create a new Builder.

func NewShardedReconciler

func NewShardedReconciler(mgr manager.Manager) *Builder

NewShardedReconciler returns a new Builder for building a sharded reconciler. A sharded reconciler needs to handle the shard and drain labels correctly. This builder helps to construct a wrapper reconciler that takes care of the sharding-related logic and calls the delegate reconciler whenever the shard is responsible for reconciling an object.

func (*Builder) Build

Build takes the actual reconciler and wraps it in the sharded reconciler.

func (*Builder) For

func (b *Builder) For(object client.Object) *Builder

For sets the object kind being reconciled by the reconciler.

func (*Builder) InClusterRing

func (b *Builder) InClusterRing(name string) *Builder

InClusterRing sets the name of the ClusterRing that the shard belongs to.

func (*Builder) MustBuild

MustBuild calls Build and panics if Build returns an error.

func (*Builder) WithClient

func (b *Builder) WithClient(c client.Client) *Builder

WithClient overwrites the client to use for reading and patching the controller's objects. If not set, the manager's client is used.

func (*Builder) WithShardName

func (b *Builder) WithShardName(name string) *Builder

WithShardName sets the name the shard.

type Reconciler

type Reconciler struct {
	// Object is the object type of the controller.
	Object client.Object
	// Client is used to read and patch the controller's objects.
	Client client.Client
	// ShardName is the shard ID of the manager.
	ShardName string
	// LabelShard is the shard label specific to the manager's ClusterRing.
	LabelShard string
	// LabelDrain is the drain label specific to the manager's ClusterRing.
	LabelDrain string
	// Do is the actual Reconciler.
	Do reconcile.Reconciler
}

Reconciler wraps another reconciler to ensure that the controller correctly handles the shard and drain labels. It ignores any objects that are not assigned to the configured shard name and drains objects if instructed to by the sharder. You can use NewShardedReconciler to construct a sharded reconciler.

func (*Reconciler) Reconcile

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

Reconcile implements reconcile.Reconciler. It performs the following steps: 1) read the object using the client, forget the object if it is not found 2) check whether the object is (still) assigned to this shard, forget the object otherwise 3) acknowledge the drain operation if requested by removing the shard and drain label, skip reconciliation, and forget the object 4) delegate reconciliation to the actual reconciler otherwise

Jump to

Keyboard shortcuts

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