rsm

package
v0.7.0-alpha.12 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: AGPL-3.0 Imports: 40 Imported by: 0

Documentation

Overview

Package rsm is a general component aims to hold role-based stateful workloads(such as databases). RSM stands for Replicated State Machine based on the truth that the workloads are solving state replication related problems. Treat RSM as an enhanced StatefulSet.

The K8s native StatefulSet can handle stateful workloads well, but there are more works to do if the workload pods have roles(leader/follower in etcd, primary/secondary in PostgreSQL etc.).

RSM adds an abstract layer above StatefulSet, and provides: 1. role-based update strategy(Serial/Parallel/BestEffortParallel) 2. role-based access modes(ReadWrite/Readonly/None) 3. auto switchover 4. membership reconfiguration

Index

Constants

View Source
const (
	// FeatureGateRSMCompatibilityMode whether run rsm in compatibility mode(i.e. make rsm having backward and forward compatibility with KubeBlocks version prior 0.6.0)
	// what the compatibility mode will do:
	// 1. labels compatibility
	//    copy labels of rsm to secondary resources(i.e. svc, sts, cm) in creation; list secondary resources by labels of rsm in update and deletion
	// 2. owner reference compatibility
	//    copy the owner ref of rsm to secondary resources; list secondary resources by owner ref of rsm in update and deletion
	// 3. finalizer compatibility
	//    copy the finalizer of rsm to secondary resources; remove the finalizer same as rsm in deletion
	// what if not:
	// labels, owner ref and finalizer of secondary resources will be generated by (not copied from) rsm.
	FeatureGateRSMCompatibilityMode = "RSM_COMPATIBILITY_MODE"
)

Variables

View Source
var (
	ErrContinue error
	ErrWait     = errors.New("wait")
	ErrStop     = errors.New("stop")
)

Functions

func AddAnnotationScope

func AddAnnotationScope(scope AnnotationScope, annotations map[string]string) map[string]string

AddAnnotationScope will add AnnotationScope defined by 'scope' to all keys in map 'annotations'.

func CopyOwnership

func CopyOwnership(owner, obj client.Object, scheme *runtime.Scheme, finalizer string) error

CopyOwnership copies owner ref fields of 'owner' to 'obj' and calls controllerutil.AddFinalizer if not exists.

func IsRSMReady

func IsRSMReady(rsm *workloads.ReplicatedStateMachine) bool

IsRSMReady gives rsm level 'ready' state: 1. all replicas exist 2. all members have role set

func NewRSMPlanBuilder

func NewRSMPlanBuilder(ctx intctrlutil.RequestCtx, cli client.Client, req ctrl.Request) graph.PlanBuilder

NewRSMPlanBuilder returns a RSMPlanBuilder powered PlanBuilder

func ParseAnnotationsOfScope

func ParseAnnotationsOfScope(scope AnnotationScope, scopedAnnotations map[string]string) map[string]string

ParseAnnotationsOfScope parses all annotations with AnnotationScope defined by 'scope'. the AnnotationScope suffix of keys in result map will be trimmed.

Types

type AnnotationScope

type AnnotationScope string

AnnotationScope defines scope that annotations belong to.

it is a common pattern to add annotations to extend the functionalities of K8s builtin resources.

e.g.: Prometheus will start to scrape metrics if a service has annotation 'prometheus.io/scrape'.

RSM has encapsulated K8s builtin resources like Service, Headless Service, StatefulSet, ConfigMap etc. AnnotationScope specified a way to tell RSM controller which resource an annotation belongs to.

e.g.: let's say we want to add an annotation 'prometheus.io/scrape' with value 'true' to the underlying headless service. here is what we should do: add annotation 'prometheus.io/scrape' with an HeadlessServiceScope suffix to the RSM object's annotations field.

kind: ReplicatedStateMachine
metadata:
  annotations:
    prometheus.io/scrape.headless.rsm: true

the RSM controller will figure out which objects this annotation belongs to, cut the suffix and set it to the right place:

kind: Service
metadata:
  annotations:
    prometheus.io/scrape: true
const (
	// RootScope specifies the annotation belongs to the RSM object itself.
	// they will also be set on the encapsulated StatefulSet.
	RootScope AnnotationScope = ""

	// HeadlessServiceScope specifies the annotation belongs to the encapsulated headless Service.
	HeadlessServiceScope AnnotationScope = ".headless.rsm"

	// ServiceScope specifies the annotation belongs to the encapsulated Service.
	ServiceScope AnnotationScope = ".svc.rsm"

	// AlternativeServiceScope specifies the annotation belongs to the encapsulated alternative Services.
	AlternativeServiceScope AnnotationScope = ".alternative.rsm"

	// ConfigMapScope specifies the annotation belongs to the encapsulated ConfigMap.
	ConfigMapScope AnnotationScope = ".cm.rsm"
)

type EnqueueRequestForAncestor

type EnqueueRequestForAncestor struct {
	// Client used to get owner object of
	Client roclient.ReadonlyClient

	// OwnerType is the type of the Owner object to look for in OwnerReferences.  Only Group and Kind are compared.
	OwnerType runtime.Object

	// find event source up to UpToLevel
	UpToLevel int

	// InTypes specified the range to look for the ancestor, means all ancestors' type in the looking up tree should be in InTypes.
	// OwnerType will be included.
	// nil means only look for in OwnerType.
	InTypes []runtime.Object
	// contains filtered or unexported fields
}

EnqueueRequestForAncestor enqueues Requests for the ancestor object. E.g. the ancestor object creates the StatefulSet/Deployment which then creates the Pod.

If a ReplicatedStateMachine creates Pods, users may reconcile the ReplicatedStateMachine in response to Pod Events using:

- a source.Kind Source with Type of Pod.

- a EnqueueRequestForAncestor EventHandler with an OwnerType of ReplicatedStateMachine and UpToLevel set to 2.

If source kind is corev1.Event, Event.InvolvedObject will be used as the source kind

func (*EnqueueRequestForAncestor) Create

Create implements EventHandler.

func (*EnqueueRequestForAncestor) Delete

Delete implements EventHandler.

func (*EnqueueRequestForAncestor) Generic

Generic implements EventHandler.

func (*EnqueueRequestForAncestor) InjectMapper

func (e *EnqueueRequestForAncestor) InjectMapper(m meta.RESTMapper) error

InjectMapper is called by the Controller to provide the rest mapper used by the manager.

func (*EnqueueRequestForAncestor) InjectScheme

func (e *EnqueueRequestForAncestor) InjectScheme(s *runtime.Scheme) error

InjectScheme is called by the Controller to provide a singleton scheme to the EnqueueRequestForAncestor.

func (*EnqueueRequestForAncestor) Update

Update implements EventHandler.

type FixMetaTransformer

type FixMetaTransformer struct{}

func (*FixMetaTransformer) Transform

func (t *FixMetaTransformer) Transform(ctx graph.TransformContext, dag *graph.DAG) error

type MemberReconfigurationTransformer

type MemberReconfigurationTransformer struct{}

MemberReconfigurationTransformer handles member reconfiguration

func (*MemberReconfigurationTransformer) Transform

type ObjectDeletionTransformer

type ObjectDeletionTransformer struct{}

ObjectDeletionTransformer handles object and its secondary resources' deletion

func (*ObjectDeletionTransformer) Transform

type ObjectGenerationTransformer

type ObjectGenerationTransformer struct{}

func (*ObjectGenerationTransformer) Transform

type ObjectStatusTransformer

type ObjectStatusTransformer struct{}

ObjectStatusTransformer computes the current status: 1. read the underlying sts's status and copy them to the primary object's status 2. read pod role label and update the primary object's status role fields

func (*ObjectStatusTransformer) Transform

func (t *ObjectStatusTransformer) Transform(ctx graph.TransformContext, dag *graph.DAG) error

type Plan

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

func (*Plan) Execute

func (p *Plan) Execute() error

type PlanBuilder

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

func (*PlanBuilder) AddParallelTransformer

func (b *PlanBuilder) AddParallelTransformer(transformer ...graph.Transformer) graph.PlanBuilder

func (*PlanBuilder) AddTransformer

func (b *PlanBuilder) AddTransformer(transformer ...graph.Transformer) graph.PlanBuilder

func (*PlanBuilder) Build

func (b *PlanBuilder) Build() (graph.Plan, error)

func (*PlanBuilder) Init

func (b *PlanBuilder) Init() error

type PodRoleEventHandler

type PodRoleEventHandler struct{}

func (*PodRoleEventHandler) Handle

func (h *PodRoleEventHandler) Handle(cli client.Client, reqCtx intctrlutil.RequestCtx, recorder record.EventRecorder, event *corev1.Event) error

type UpdateStrategyTransformer

type UpdateStrategyTransformer struct{}

func (*UpdateStrategyTransformer) Transform

Jump to

Keyboard shortcuts

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