Documentation ¶
Index ¶
- func Predicate(clusterRingName, shardName string, predicates ...predicate.Predicate) predicate.Predicate
- type Builder
- func (b *Builder) Build(r reconcile.Reconciler) (reconcile.Reconciler, error)
- func (b *Builder) For(object client.Object) *Builder
- func (b *Builder) InClusterRing(name string) *Builder
- func (b *Builder) MustBuild(r reconcile.Reconciler) reconcile.Reconciler
- func (b *Builder) WithClient(c client.Client) *Builder
- func (b *Builder) WithShardName(name string) *Builder
- type Reconciler
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 ¶
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 ¶
func (b *Builder) Build(r reconcile.Reconciler) (reconcile.Reconciler, error)
Build takes the actual reconciler and wraps it in the sharded reconciler.
func (*Builder) InClusterRing ¶
InClusterRing sets the name of the ClusterRing that the shard belongs to.
func (*Builder) MustBuild ¶
func (b *Builder) MustBuild(r reconcile.Reconciler) reconcile.Reconciler
MustBuild calls Build and panics if Build returns an error.
func (*Builder) WithClient ¶
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 ¶
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