Documentation ¶
Index ¶
- Variables
- func BackgroundDeleteObject(cli client.Client, ctx context.Context, obj client.Object) error
- func CheckResourceExists(ctx context.Context, cli client.Client, key client.ObjectKey, ...) (bool, error)
- func CheckedRequeueWithError(err error, logger logr.Logger, msg string, keysAndValues ...interface{}) (reconcile.Result, error)
- func CreateOrUpdatePodVolumes(podSpec *corev1.PodSpec, volumes map[string]appsv1alpha1.ComponentTemplateSpec) error
- func CreateOrUpdateVolume(volumes []corev1.Volume, volumeName string, createFn createVolumeFn, ...) ([]corev1.Volume, error)
- func GetContainerByConfigSpec(podSpec *corev1.PodSpec, configs []appsv1alpha1.ComponentConfigSpec) *corev1.Container
- func GetContainerByName(containers []corev1.Container, name string) (int, *corev1.Container)
- func GetContainerID(pod *corev1.Pod, containerName string) string
- func GetContainersByConfigmap(containers []corev1.Container, volumeName string, ...) []string
- func GetCoreNum(container corev1.Container) int64
- func GetIntOrPercentValue(intOrStr *metautil.IntOrString) (int, bool, error)
- func GetMemorySize(container corev1.Container) int64
- func GetParentNameAndOrdinal(pod *corev1.Pod) (string, int)
- func GetPodCondition(status *corev1.PodStatus, conditionType corev1.PodConditionType) *corev1.PodCondition
- func GetPodContainerWithVolumeMount(podSpec *corev1.PodSpec, volumeName string) []*corev1.Container
- func GetPodRevision(pod *corev1.Pod) string
- func GetPortByPortName(pod *corev1.Pod, portName string) (int32, error)
- func GetProbeContainerName(pod *corev1.Pod) (string, error)
- func GetProbeGRPCPort(pod *corev1.Pod) (int32, error)
- func GetProbeHTTPPort(pod *corev1.Pod) (int32, error)
- func GetRequestMemorySize(container corev1.Container) int64
- func GetUncachedObjects() []client.Object
- func GetVolumeMountByVolume(container *corev1.Container, volumeName string) *corev1.VolumeMount
- func GetVolumeMountName(volumes []corev1.Volume, resourceName string) *corev1.Volume
- func HandleCRDeletion(reqCtx RequestCtx, r client.Writer, cr client.Object, finalizer string, ...) (*ctrl.Result, error)
- func IgnoreIsAlreadyExists(err error) error
- func InVolumeSnapshotV1Beta1() bool
- func IsAvailable(pod *corev1.Pod, minReadySeconds int32) bool
- func IsMatchConfigVersion(obj client.Object, labelKey string, version string) bool
- func IsNotFound(err error) bool
- func IsTargetError(err error, errorType ErrorType) bool
- func ManagedByKubeBlocksFilterPredicate(object client.Object) bool
- func PodIsControlledByLatestRevision(pod *corev1.Pod, sts *appsv1.StatefulSet) bool
- func PodIsReady(pod *corev1.Pod) bool
- func PodIsReadyWithLabel(pod corev1.Pod) bool
- func Reconciled() (reconcile.Result, error)
- func RecordCreatedEvent(r record.EventRecorder, cr client.Object)
- func Requeue(logger logr.Logger, msg string, keysAndValues ...interface{}) (reconcile.Result, error)
- func RequeueAfter(duration time.Duration, logger logr.Logger, msg string, ...) (reconcile.Result, error)
- func RequeueWithError(err error, logger logr.Logger, msg string, keysAndValues ...interface{}) (reconcile.Result, error)
- func RequeueWithErrorAndRecordEvent(obj client.Object, recorder record.EventRecorder, err error, ...) (reconcile.Result, error)
- func ResultToP(res reconcile.Result, err error) (*reconcile.Result, error)
- func SetOwnership(owner, obj client.Object, scheme *runtime.Scheme, finalizer string, ...) error
- func ValidateReferenceCR(reqCtx RequestCtx, cli client.Client, obj client.Object, labelKey string, ...) (*ctrl.Result, error)
- func WorkloadFilterPredicate(object client.Object) bool
- type ByPodName
- type CUEBuilder
- type CUETpl
- type Error
- func NewBackupJobFailed(jobName string) *Error
- func NewBackupNotSupported(backupType, backupPolicyName string) *Error
- func NewBackupPVCNameIsEmpty(backupPolicyName string) *Error
- func NewBackupPVTemplateNotFound(cmName, cmNamespace string) *Error
- func NewError(errorType ErrorType, message string) *Error
- func NewErrorf(errorType ErrorType, format string, a ...any) *Error
- func NewNotFound(format string, a ...any) *Error
- func ToControllerError(err error) *Error
- type ErrorType
- type RequestCtx
- func (r *RequestCtx) Event(object runtime.Object, eventtype, reason, message string)
- func (r *RequestCtx) Eventf(object runtime.Object, eventtype, reason, messageFmt string, ...)
- func (r *RequestCtx) UpdateCtxValue(key, val any) context.Context
- func (r *RequestCtx) WithValue(key, val any) context.Context
- type Task
- type TaskFunction
- type TaskType
- type VolumeSnapshotCompatClient
- func (c *VolumeSnapshotCompatClient) CheckResourceExists(key client.ObjectKey, obj *snapshotv1.VolumeSnapshot) (bool, error)
- func (c *VolumeSnapshotCompatClient) Create(snapshot *snapshotv1.VolumeSnapshot, opts ...client.CreateOption) error
- func (c *VolumeSnapshotCompatClient) Delete(snapshot *snapshotv1.VolumeSnapshot, opts ...client.DeleteOption) error
- func (c *VolumeSnapshotCompatClient) Get(key client.ObjectKey, snapshot *snapshotv1.VolumeSnapshot, ...) error
- func (c *VolumeSnapshotCompatClient) List(snapshotList *snapshotv1.VolumeSnapshotList, opts ...client.ListOption) error
- func (c *VolumeSnapshotCompatClient) Patch(snapshot *snapshotv1.VolumeSnapshot, deepCopy *snapshotv1.VolumeSnapshot, ...) error
Constants ¶
This section is empty.
Variables ¶
var ErrFailedToAddFinalizer = errors.New("failed to add finalizer")
Functions ¶
func BackgroundDeleteObject ¶
BackgroundDeleteObject delete the object in the background, usually used in the Reconcile method
func CheckResourceExists ¶
func CheckResourceExists( ctx context.Context, cli client.Client, key client.ObjectKey, obj client.Object) (bool, error)
CheckResourceExists checks whether resource exist or not.
func CheckedRequeueWithError ¶
func CheckedRequeueWithError(err error, logger logr.Logger, msg string, keysAndValues ...interface{}) (reconcile.Result, error)
CheckedRequeueWithError is a convenience wrapper around logging an error message separate from the stacktrace and then passing the error through to the controller manager, this will ignore not-found errors.
func CreateOrUpdatePodVolumes ¶
func CreateOrUpdatePodVolumes(podSpec *corev1.PodSpec, volumes map[string]appsv1alpha1.ComponentTemplateSpec) error
func CreateOrUpdateVolume ¶
func GetContainerByConfigSpec ¶
func GetContainerByConfigSpec(podSpec *corev1.PodSpec, configs []appsv1alpha1.ComponentConfigSpec) *corev1.Container
GetContainerByConfigSpec function description: Search the container using the configmap of config from the pod
Return: The first container pointer of using configs
e.g.: ClusterDefinition.configTemplateRef: - Name: "mysql-8.0" VolumeName: "mysql_config" PodTemplate.containers[*].volumeMounts: - mountPath: /data/config name: mysql_config - mountPath: /data name: data - mountPath: /log name: log
func GetContainerByName ¶
func GetContainerID ¶
GetContainerID find the containerID from pod by name
func GetCoreNum ¶
GetCoreNum function description: if not Resource field return 0 else Resources.Limits.cpu
func GetIntOrPercentValue ¶
func GetIntOrPercentValue(intOrStr *metautil.IntOrString) (int, bool, error)
func GetMemorySize ¶
GetMemorySize function description: if not Resource field, return 0 else Resources.Limits.memory
func GetParentNameAndOrdinal ¶
GetParentNameAndOrdinal gets the name of pod's parent StatefulSet and pod's ordinal as extracted from its Name. If the Pod was not created by a StatefulSet, its parent is considered to be empty string, and its ordinal is considered to be -1.
func GetPodCondition ¶
func GetPodCondition(status *corev1.PodStatus, conditionType corev1.PodConditionType) *corev1.PodCondition
func GetPodContainerWithVolumeMount ¶
GetPodContainerWithVolumeMount function description: Search which containers mounting the volume
Case: When the configmap update, we restart all containers who using configmap
Return: all containers mount volumeName
func GetPodRevision ¶
GetPodRevision gets the revision of Pod by inspecting the StatefulSetRevisionLabel. If pod has no revision the empty string is returned.
func GetPortByPortName ¶
GetPortByPortName find the Port from pod by name
func GetProbeContainerName ¶
GetProbeContainerName find the probe container from pod
func GetRequestMemorySize ¶
GetRequestMemorySize function description: if not Resource field, return 0 else Resources.Limits.memory
func GetUncachedObjects ¶
GetUncachedObjects returns a list of K8s objects, for these object types, and their list types, client.Reader will read directly from the API server instead of the cache, which may not be up-to-date. see sigs.k8s.io/controller-runtime/pkg/client/split.go to understand how client works with this UncachedObjects filter.
func GetVolumeMountByVolume ¶
func GetVolumeMountByVolume(container *corev1.Container, volumeName string) *corev1.VolumeMount
func GetVolumeMountName ¶
GetVolumeMountName function description: Find the volume of pod using name of cm
Case: When the configmap object of configuration is modified by user, we need to query whose volumeName
Return: The volume pointer of pod
func HandleCRDeletion ¶
func HandleCRDeletion(reqCtx RequestCtx, r client.Writer, cr client.Object, finalizer string, deletionHandler func() (*ctrl.Result, error)) (*ctrl.Result, error)
HandleCRDeletion Handled CR deletion flow, will add finalizer if discovered a non-deleting object and remove finalizer during deletion process. Pass optional 'deletionHandler' func for external dependency deletion. Return Result pointer if required to return out of outer 'Reconcile' reconciliation loop.
func IgnoreIsAlreadyExists ¶
IgnoreIsAlreadyExists return errors that is not AlreadyExists
func InVolumeSnapshotV1Beta1 ¶
func InVolumeSnapshotV1Beta1() bool
func IsMatchConfigVersion ¶
func IsNotFound ¶
IsNotFound returns true if the specified error is the error type of ErrorTypeNotFound.
func IsTargetError ¶
IsTargetError checks if the error is the target error.
func ManagedByKubeBlocksFilterPredicate ¶
ManagedByKubeBlocksFilterPredicate provides filter predicate for objects managed by kubeBlocks.
func PodIsControlledByLatestRevision ¶
func PodIsControlledByLatestRevision(pod *corev1.Pod, sts *appsv1.StatefulSet) bool
PodIsControlledByLatestRevision checks if the pod is controlled by latest controller revision.
func PodIsReadyWithLabel ¶
PodIsReadyWithLabel checks whether pod is ready or not if the component is ConsensusSet or ReplicationSet, it will be available when the pod is ready and labeled with its role.
func Reconciled ¶
Reconciled returns an empty result with nil error to signal a successful reconcile to the controller manager
func RecordCreatedEvent ¶
func RecordCreatedEvent(r record.EventRecorder, cr client.Object)
RecordCreatedEvent record an event when CR created successfully
func RequeueAfter ¶
func RequeueWithError ¶
func RequeueWithError(err error, logger logr.Logger, msg string, keysAndValues ...interface{}) (reconcile.Result, error)
RequeueWithError requeue when an error occurs
func RequeueWithErrorAndRecordEvent ¶
func RequeueWithErrorAndRecordEvent(obj client.Object, recorder record.EventRecorder, err error, logger logr.Logger) (reconcile.Result, error)
RequeueWithErrorAndRecordEvent requeue when an error occurs. if it is a not found error, send an event
func SetOwnership ¶
func SetOwnership(owner, obj client.Object, scheme *runtime.Scheme, finalizer string, useOwnerReference ...bool) error
SetOwnership provides helper function controllerutil.SetControllerReference/controllerutil.SetOwnerReference and controllerutil.AddFinalizer if not exists.
func ValidateReferenceCR ¶
func ValidateReferenceCR(reqCtx RequestCtx, cli client.Client, obj client.Object, labelKey string, recordEvent func(), objLists ...client.ObjectList) (*ctrl.Result, error)
ValidateReferenceCR validate is exist referencing CRs. if exists, requeue reconcile after 30 seconds
func WorkloadFilterPredicate ¶
WorkloadFilterPredicate provides filter predicate for workload objects, i.e., deployment/statefulset/pod/pvc.
Types ¶
type ByPodName ¶
ByPodName sorts a list of jobs by pod name
type CUEBuilder ¶
func NewCUEBuilder ¶
func NewCUEBuilder(cueTpl CUETpl) CUEBuilder
func (*CUEBuilder) FillRaw ¶
func (v *CUEBuilder) FillRaw(path string, value interface{}) error
type CUETpl ¶
func NewCUETplFromPath ¶
type Error ¶
func NewBackupJobFailed ¶
NewBackupJobFailed returns a new Error with ErrorTypeBackupJobFailed.
func NewBackupNotSupported ¶
NewBackupNotSupported returns a new Error with ErrorTypeBackupNotSupported.
func NewBackupPVCNameIsEmpty ¶
NewBackupPVCNameIsEmpty returns a new Error with ErrorTypeBackupPVCNameIsEmpty.
func NewBackupPVTemplateNotFound ¶
NewBackupPVTemplateNotFound returns a new Error with ErrorTypeBackupPVTemplateNotFound.
func NewNotFound ¶
NewNotFound returns a new Error with ErrorTypeNotFound.
func ToControllerError ¶
ToControllerError converts the error to the Controller error.
type ErrorType ¶
type ErrorType string
ErrorType is explicit error type.
const ( // ErrorWaitCacheRefresh waits for synchronization of the corresponding object cache in client-go from ApiServer. ErrorWaitCacheRefresh ErrorType = "WaitCacheRefresh" // ErrorTypeNotFound not found any resource. ErrorTypeNotFound ErrorType = "NotFound" ErrorTypeRequeue ErrorType = "Requeue" // requeue for reconcile. // ErrorType for backup ErrorTypeBackupNotSupported ErrorType = "BackupNotSupported" // this backup type not supported ErrorTypeBackupPVTemplateNotFound ErrorType = "BackupPVTemplateNotFound" // this pv template not found ErrorTypeBackupNotCompleted ErrorType = "BackupNotCompleted" // report backup not completed. ErrorTypeBackupPVCNameIsEmpty ErrorType = "BackupPVCNameIsEmpty" // pvc name for backup is empty ErrorTypeBackupJobFailed ErrorType = "BackupJobFailed" // backup job failed ErrorTypeStorageNotMatch ErrorType = "ErrorTypeStorageNotMatch" ErrorTypeReconfigureFailed ErrorType = "ErrorTypeReconfigureFailed" // ErrorType for cluster controller ErrorTypeBackupFailed ErrorType = "BackupFailed" ErrorTypeNeedWaiting ErrorType = "NeedWaiting" // waiting for next reconcile // ErrorType for preflight ErrorTypePreflightCommon = "PreflightCommon" ErrorTypeSkipPreflight = "SkipPreflight" )
type RequestCtx ¶
type RequestCtx struct { Ctx context.Context Req ctrl.Request Log logr.Logger Recorder record.EventRecorder }
RequestCtx wrapper for reconcile procedure context parameters
func (*RequestCtx) Event ¶
func (r *RequestCtx) Event(object runtime.Object, eventtype, reason, message string)
Event is wrapper for Recorder.Event, if Recorder is nil, then it's no-op.
func (*RequestCtx) Eventf ¶
func (r *RequestCtx) Eventf(object runtime.Object, eventtype, reason, messageFmt string, args ...interface{})
Eventf is wrapper for Recorder.Eventf, if Recorder is nil, then it's no-op.
func (*RequestCtx) UpdateCtxValue ¶
func (r *RequestCtx) UpdateCtxValue(key, val any) context.Context
UpdateCtxValue update Context value, return parent Context.
type Task ¶
type Task struct { Type TaskType SubTasks []Task PreFunction TaskFunction ExecFunction TaskFunction PostFunction TaskFunction Context map[string]interface{} }
type TaskFunction ¶
type TaskFunction func(RequestCtx, client.Client, interface{}) error
TaskFunction REVIEW (cx): using interface{} is rather error-prone
type VolumeSnapshotCompatClient ¶
type VolumeSnapshotCompatClient struct { client.Client roclient.ReadonlyClient Ctx context.Context }
VolumeSnapshotCompatClient client is compatible both VolumeSnapshot v1 and v1beta1
func (*VolumeSnapshotCompatClient) CheckResourceExists ¶
func (c *VolumeSnapshotCompatClient) CheckResourceExists(key client.ObjectKey, obj *snapshotv1.VolumeSnapshot) (bool, error)
CheckResourceExists checks whether resource exist or not.
func (*VolumeSnapshotCompatClient) Create ¶
func (c *VolumeSnapshotCompatClient) Create(snapshot *snapshotv1.VolumeSnapshot, opts ...client.CreateOption) error
func (*VolumeSnapshotCompatClient) Delete ¶
func (c *VolumeSnapshotCompatClient) Delete(snapshot *snapshotv1.VolumeSnapshot, opts ...client.DeleteOption) error
func (*VolumeSnapshotCompatClient) Get ¶
func (c *VolumeSnapshotCompatClient) Get(key client.ObjectKey, snapshot *snapshotv1.VolumeSnapshot, opts ...client.GetOption) error
func (*VolumeSnapshotCompatClient) List ¶
func (c *VolumeSnapshotCompatClient) List(snapshotList *snapshotv1.VolumeSnapshotList, opts ...client.ListOption) error
func (*VolumeSnapshotCompatClient) Patch ¶
func (c *VolumeSnapshotCompatClient) Patch(snapshot *snapshotv1.VolumeSnapshot, deepCopy *snapshotv1.VolumeSnapshot, opts ...client.PatchOption) error