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 BuildInstanceTemplateRevision(template *corev1.PodTemplateSpec, parent *workloads.InstanceSet) (string, error)
- func BuildPodTemplate(its *workloads.InstanceSet, envConfigName string) *corev1.PodTemplateSpec
- func ComposeRolePriorityMap(roles []workloads.ReplicaRole) map[string]int
- func ControllerRevisionName(prefix string, hash string) string
- func DeepHashObject(hasher hash.Hash, objectToWrite interface{})
- func GenerateAllInstanceNames(parentName string, replicas int32, templates []InstanceTemplate, ...) []string
- func GenerateInstanceNames(parentName, templateName string, replicas int32, ordinal int32, ...) ([]string, int32)
- func GenerateInstanceNamesFromTemplate(parentName, templateName string, replicas int32, offlineInstances []string) []string
- func GetEnvConfigMapName(itsName string) string
- func HashControllerRevision(revision *apps.ControllerRevision, probe *int32) string
- func IsInstanceSetReady(its *workloads.InstanceSet) bool
- func IsPodUpdated(its *workloads.InstanceSet, pod *corev1.Pod) (bool, error)
- func NewAssistantObjectReconciler() kubebuilderx.Reconciler
- func NewControllerRevision(parent metav1.Object, parentKind schema.GroupVersionKind, ...) (*apps.ControllerRevision, error)
- func NewDeletionReconciler() kubebuilderx.Reconciler
- func NewFixMetaReconciler() kubebuilderx.Reconciler
- func NewReplicasAlignmentReconciler() kubebuilderx.Reconciler
- func NewRevision(its *workloads.InstanceSet) (*apps.ControllerRevision, error)
- 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 ParseAnnotationsOfScope(scope AnnotationScope, scopedAnnotations map[string]string) map[string]string
- func ParseParentNameAndOrdinal(s string) (string, int)
- func SortPods(pods []corev1.Pod, rolePriorityMap map[string]int, reverse bool)
- func ValidateDupInstanceNames[T any](instances []T, getNameFunc func(item T) string) error
- type AnnotationScope
- type InstanceTemplate
- type PodRoleEventHandler
- type PodUpdatePolicy
Constants ¶
const ( WorkloadsManagedByLabelKey = "workloads.kubeblocks.io/managed-by" WorkloadsInstanceLabelKey = "workloads.kubeblocks.io/instance" RoleLabelKey = "kubeblocks.io/role" AccessModeLabelKey = "workloads.kubeblocks.io/access-mode" LegacyRSMFinalizerName = "rsm.workloads.kubeblocks.io/finalizer" RoleUpdateMechanismVarName = "KB_RSM_ROLE_UPDATE_MECHANISM" )
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 ControllerRevisionHashLabel = "controller.kubernetes.io/hash"
ControllerRevisionHashLabel is the label used to indicate the hash value of a ControllerRevision's Data.
const (
EventReasonInvalidSpec = "InvalidSpec"
)
Variables ¶
var Codecs = serializer.NewCodecFactory(model.GetScheme())
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 BuildInstanceTemplateRevision ¶
func BuildInstanceTemplateRevision(template *corev1.PodTemplateSpec, parent *workloads.InstanceSet) (string, error)
func BuildPodTemplate ¶
func BuildPodTemplate(its *workloads.InstanceSet, envConfigName string) *corev1.PodTemplateSpec
func ComposeRolePriorityMap ¶
func ComposeRolePriorityMap(roles []workloads.ReplicaRole) map[string]int
ComposeRolePriorityMap generates a priority map based on roles.
func ControllerRevisionName ¶
ControllerRevisionName returns the Name for a ControllerRevision in the form prefix-hash. If the length of prefix is greater than 223 bytes, it is truncated to allow for a name that is no larger than 253 bytes.
func DeepHashObject ¶
DeepHashObject writes specified object to hash using the spew library which follows pointers and prints actual values of the nested objects ensuring the hash does not change when a pointer changes.
func GenerateAllInstanceNames ¶
func GenerateAllInstanceNames(parentName string, replicas int32, templates []InstanceTemplate, offlineInstances []string) []string
func GenerateInstanceNames ¶
func GenerateInstanceNames(parentName, templateName string, replicas int32, ordinal int32, offlineInstances []string) ([]string, int32)
GenerateInstanceNames generates instance names based on certain rules: The naming convention for instances (pods) based on the Parent Name, InstanceTemplate Name, and ordinal. The constructed instance name follows the pattern: $(parent.name)-$(template.name)-$(ordinal).
func GetEnvConfigMapName ¶
func HashControllerRevision ¶
func HashControllerRevision(revision *apps.ControllerRevision, probe *int32) string
HashControllerRevision hashes the contents of revision's Data using FNV hashing. If probe is not nil, the byte value of probe is added written to the hash as well. The returned hash will be a safe encoded string to avoid bad words.
func IsInstanceSetReady ¶
func IsInstanceSetReady(its *workloads.InstanceSet) bool
IsInstanceSetReady gives InstanceSet level 'ready' state: 1. all instances are available 2. and all members have role set (if they are role-ful)
func IsPodUpdated ¶
IsPodUpdated tells whether the pod's spec is as expected in the InstanceSet. This function is meant to replace the old fashion `GetPodRevision(pod) == updateRevision`, as the pod template revision has been redefined in instanceset.
func NewAssistantObjectReconciler ¶
func NewAssistantObjectReconciler() kubebuilderx.Reconciler
func NewControllerRevision ¶
func NewControllerRevision(parent metav1.Object, parentKind schema.GroupVersionKind, templateLabels map[string]string, data runtime.RawExtension, revision int64, collisionCount *int32) (*apps.ControllerRevision, error)
NewControllerRevision returns a ControllerRevision with a ControllerRef pointing to parent and indicating that parent is of parentKind. The ControllerRevision has labels matching template labels, contains Data equal to data, and has a Revision equal to revision. The collisionCount is used when creating the name of the ControllerRevision so the name is likely unique. If the returned error is nil, the returned ControllerRevision is valid. If the returned error is not nil, the returned ControllerRevision is invalid for use.
func NewDeletionReconciler ¶
func NewDeletionReconciler() kubebuilderx.Reconciler
func NewFixMetaReconciler ¶
func NewFixMetaReconciler() kubebuilderx.Reconciler
func NewReplicasAlignmentReconciler ¶
func NewReplicasAlignmentReconciler() kubebuilderx.Reconciler
func NewRevision ¶
func NewRevision(its *workloads.InstanceSet) (*apps.ControllerRevision, error)
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 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 ParseParentNameAndOrdinal ¶
ParseParentNameAndOrdinal parses parent (instance template) Name and ordinal from the give instance name. -1 will be returned if no numeric suffix contained.
func SortPods ¶
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'.
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
type PodUpdatePolicy ¶
type PodUpdatePolicy string
const ( NoOpsPolicy PodUpdatePolicy = "NoOps" RecreatePolicy PodUpdatePolicy = "Recreate" InPlaceUpdatePolicy PodUpdatePolicy = "InPlaceUpdate" )
Source Files ¶
- doc.go
- in_place_update_util.go
- instance_util.go
- object_builder.go
- pod_role_event_handler.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
- revision_util.go
- tree_loader.go
- types.go
- update_plan.go
- utils.go