Documentation
¶
Overview ¶
Package instanceset is a general-purpose workload API designed to manage role-based stateful workloads, such as databases. Think of InstanceSet as an enhanced version of StatefulSet.
While the native StatefulSet in Kubernetes handles stateful workloads effectively, additional work is required when the workload pods have specific roles (e.g., leader/follower in etcd, primary/secondary in PostgreSQL, etc.).
InstanceSet provides the following features:
1. Role-based Update Strategy (Serial/Parallel/BestEffortParallel) 2. Role-based Access Mode (ReadWrite/Readonly/None) 3. Automatic Switchover 4. Membership Reconfiguration 5. Multiple Instance Templates 6. Specified Instance Scale In 7. In-place Instance Update
Index ¶
- Constants
- Variables
- func AddAnnotationScope(scope AnnotationScope, annotations map[string]string) map[string]string
- func CalculateConcurrencyReplicas(concurrency *intstr.IntOrString, replicas int) (int, error)
- func ComposeRolePriorityMap(roles []workloads.ReplicaRole) map[string]int
- func ConvertOrdinalsToSortedList(ordinals kbappsv1.Ordinals) ([]int32, error)
- func GenerateAllInstanceNames(parentName string, replicas int32, templates []InstanceTemplate, ...) ([]string, error)deprecated
- func GenerateInstanceNamesFromTemplate(parentName, templateName string, replicas int32, offlineInstances []string, ...) ([]string, error)
- func GetMatchLabels(name string) map[string]string
- func GetPodNameSetFromInstanceSetCondition(its *workloads.InstanceSet, conditionType workloads.ConditionType) map[string]sets.Empty
- func GetRevisions(revisions map[string]string) (map[string]string, error)
- func MergeNodeSelectorOnceAnnotation(its *workloads.InstanceSet, podToNodeMapping map[string]string) error
- func NewAPIVersionReconciler() kubebuilderx.Reconciler
- func NewAssistantObjectReconciler() kubebuilderx.Reconciler
- func NewDeletionReconciler() kubebuilderx.Reconciler
- func NewFixMetaReconciler() kubebuilderx.Reconciler
- func NewReplicasAlignmentReconciler() kubebuilderx.Reconciler
- func NewRevisionUpdateReconciler() kubebuilderx.Reconciler
- func NewStatusReconciler() kubebuilderx.Reconciler
- func NewTreeLoader() kubebuilderx.TreeLoader
- func NewUpdatePlan(its workloads.InstanceSet, pods []*corev1.Pod, ...) updatePlan
- func NewUpdateReconciler() kubebuilderx.Reconciler
- func NewValidationReconciler() kubebuilderx.Reconciler
- func ParseAnnotationsOfScope(scope AnnotationScope, scopedAnnotations map[string]string) map[string]string
- func ParseNodeSelectorOnceAnnotation(its *workloads.InstanceSet) (map[string]string, error)
- func SortPods(pods []corev1.Pod, rolePriorityMap map[string]int, reverse bool)
- type AnnotationScope
- type InstanceTemplate
- type PodRoleEventHandler
Constants ¶
const ( WorkloadsManagedByLabelKey = "workloads.kubeblocks.io/managed-by" WorkloadsInstanceLabelKey = "workloads.kubeblocks.io/instance" RoleLabelKey = "kubeblocks.io/role" )
const ( // MaxPlainRevisionCount specified max number of plain revision stored in status.updateRevisions. // All revisions will be compressed if exceeding this value. MaxPlainRevisionCount = "MAX_PLAIN_REVISION_COUNT" FeatureGateIgnorePodVerticalScaling = "IGNORE_POD_VERTICAL_SCALING" )
const (
EventReasonStrictInPlace = "StrictInPlace"
)
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 CalculateConcurrencyReplicas ¶ added in v0.9.1
func CalculateConcurrencyReplicas(concurrency *intstr.IntOrString, replicas int) (int, error)
CalculateConcurrencyReplicas returns absolute value of concurrency for workload. This func can solve some corner cases about percentage-type concurrency, such as: - if concurrency > "0%" and replicas > 0, it will ensure at least 1 pod is reserved. - if concurrency < "100%" and replicas > 1, it will ensure at least 1 pod is reserved.
if concurrency is nil, concurrency will be treated as 100%.
func ComposeRolePriorityMap ¶
func ComposeRolePriorityMap(roles []workloads.ReplicaRole) map[string]int
ComposeRolePriorityMap generates a priority map based on roles.
func ConvertOrdinalsToSortedList ¶ added in v0.9.1
func GenerateAllInstanceNames
deprecated
func GetMatchLabels ¶ added in v1.0.0
GetMatchLabels exposes getMatchLabels for external usages TODO: remove this method when no usage
func GetPodNameSetFromInstanceSetCondition ¶
func GetPodNameSetFromInstanceSetCondition(its *workloads.InstanceSet, conditionType workloads.ConditionType) map[string]sets.Empty
GetPodNameSetFromInstanceSetCondition get the pod name sets from the InstanceSet conditions
func MergeNodeSelectorOnceAnnotation ¶ added in v0.9.2
func MergeNodeSelectorOnceAnnotation(its *workloads.InstanceSet, podToNodeMapping map[string]string) error
MergeNodeSelectorOnceAnnotation merges its's nodeSelectorOnce annotation in place
func NewAPIVersionReconciler ¶ added in v0.9.3
func NewAPIVersionReconciler() kubebuilderx.Reconciler
func NewAssistantObjectReconciler ¶
func NewAssistantObjectReconciler() kubebuilderx.Reconciler
func NewDeletionReconciler ¶
func NewDeletionReconciler() kubebuilderx.Reconciler
func NewFixMetaReconciler ¶
func NewFixMetaReconciler() kubebuilderx.Reconciler
func NewReplicasAlignmentReconciler ¶
func NewReplicasAlignmentReconciler() kubebuilderx.Reconciler
func NewRevisionUpdateReconciler ¶
func NewRevisionUpdateReconciler() kubebuilderx.Reconciler
func NewStatusReconciler ¶
func NewStatusReconciler() kubebuilderx.Reconciler
func NewTreeLoader ¶
func NewTreeLoader() kubebuilderx.TreeLoader
func NewUpdatePlan ¶
func NewUpdatePlan(its workloads.InstanceSet, pods []*corev1.Pod, isPodUpdated func(*workloads.InstanceSet, *corev1.Pod) (bool, error)) updatePlan
func NewUpdateReconciler ¶
func NewUpdateReconciler() kubebuilderx.Reconciler
func NewValidationReconciler ¶
func NewValidationReconciler() kubebuilderx.Reconciler
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 ParseNodeSelectorOnceAnnotation ¶ added in v0.9.2
func ParseNodeSelectorOnceAnnotation(its *workloads.InstanceSet) (map[string]string, error)
ParseNodeSelectorOnceAnnotation will return a non-nil map
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'.
The InstanceSet has encapsulated K8s builtin resources like Service, Headless Service, Pod, ConfigMap etc. AnnotationScope specified a way to tell the InstanceSet 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: InstanceSet
metadata:
annotations:
prometheus.io/scrape.headless.its: true
the InstanceSet 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.its" // ServiceScope specifies the annotation belongs to the encapsulated Service. ServiceScope AnnotationScope = ".svc.its" // AlternativeServiceScope specifies the annotation belongs to the encapsulated alternative Services. AlternativeServiceScope AnnotationScope = ".alternative.its" // ConfigMapScope specifies the annotation belongs to the encapsulated ConfigMap. ConfigMapScope AnnotationScope = ".cm.its" )
type InstanceTemplate ¶
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
Source Files
¶
- doc.go
- in_place_update_util.go
- instance_util.go
- object_builder.go
- pod_role_event_handler.go
- reconciler_api_version.go
- reconciler_assistant_object.go
- reconciler_deletion.go
- reconciler_fix_meta.go
- reconciler_instance_alignment.go
- reconciler_revision_update.go
- reconciler_status.go
- reconciler_update.go
- reconciler_validation.go
- revision_util.go
- tree_loader.go
- types.go
- update_plan.go
- utils.go