rsm

package
v0.7.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: AGPL-3.0 Imports: 36 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"

	RoleUpdateMechanismVarName = "KB_RSM_ROLE_UPDATE_MECHANISM"
)

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 ComposeRolePriorityMap

func ComposeRolePriorityMap(roles []workloads.ReplicaRole) map[string]int

ComposeRolePriorityMap generates a priority map based on roles.

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.

func SortPods

func SortPods(pods []corev1.Pod, rolePriorityMap map[string]int, reverse bool)

SortPods sorts pods by their role priority e.g.: unknown -> empty -> learner -> follower1 -> follower2 -> leader, with follower1.Name < follower2.Name reverse it if reverse==true

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

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