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
- Variables
- func AddAnnotationScope(scope AnnotationScope, annotations map[string]string) map[string]string
- func ComposeRolePriorityMap(roles []workloads.ReplicaRole) map[string]int
- func CopyOwnership(owner, obj client.Object, scheme *runtime.Scheme, finalizer string) error
- func IsRSMReady(rsm *workloads.ReplicatedStateMachine) bool
- func NewRSMPlanBuilder(ctx intctrlutil.RequestCtx, cli client.Client, req ctrl.Request) graph.PlanBuilder
- func ParseAnnotationsOfScope(scope AnnotationScope, scopedAnnotations map[string]string) map[string]string
- func SortPods(pods []corev1.Pod, rolePriorityMap map[string]int, reverse bool)
- type AnnotationScope
- type FixMetaTransformer
- type MemberReconfigurationTransformer
- type ObjectDeletionTransformer
- type ObjectGenerationTransformer
- type ObjectStatusTransformer
- type Plan
- type PlanBuilder
- type PodRoleEventHandler
- type UpdateStrategyTransformer
Constants ¶
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" RoleUpdateMechanismVarName = "KB_RSM_ROLE_UPDATE_MECHANISM" )
Variables ¶
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 ComposeRolePriorityMap ¶
func ComposeRolePriorityMap(roles []workloads.ReplicaRole) map[string]int
ComposeRolePriorityMap generates a priority map based on roles.
func CopyOwnership ¶
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 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 ¶
func (t *MemberReconfigurationTransformer) Transform(ctx graph.TransformContext, dag *graph.DAG) error
type ObjectDeletionTransformer ¶
type ObjectDeletionTransformer struct{}
ObjectDeletionTransformer handles object and its secondary resources' deletion
func (*ObjectDeletionTransformer) Transform ¶
func (t *ObjectDeletionTransformer) Transform(ctx graph.TransformContext, dag *graph.DAG) error
type ObjectGenerationTransformer ¶
type ObjectGenerationTransformer struct{}
func (*ObjectGenerationTransformer) Transform ¶
func (t *ObjectGenerationTransformer) Transform(ctx graph.TransformContext, dag *graph.DAG) error
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 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) 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 ¶
func (t *UpdateStrategyTransformer) Transform(ctx graph.TransformContext, dag *graph.DAG) error