Documentation ¶
Index ¶
- Variables
- func BackgroundDeleteObject(cli client.Client, ctx context.Context, obj client.Object) error
- func BuildPodHostDNS(pod *corev1.Pod) string
- 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 GetConfigSpecReconcilePhase(configMap *corev1.ConfigMap, item v1alpha1.ConfigurationItemDetail, ...) v1alpha1.ConfigurationPhase
- 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, cmName string, ...) []string
- func GetCoreNum(container corev1.Container) int64
- func GetIntOrPercentValue(intOrStr *metautil.IntOrString) (int, bool, error)
- func GetLorryContainerName(pod *corev1.Pod) (string, error)
- func GetLorryGRPCPort(pod *corev1.Pod) (int32, error)
- func GetLorryHTTPPort(pod *corev1.Pod) (int32, 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 GetRequestMemorySize(container corev1.Container) int64
- func GetStorageSizeFromPersistentVolume(pvc corev1.PersistentVolumeClaimTemplate) int64
- func GetUncachedObjects() []client.Object
- func GetVolumeMountByVolume(container *corev1.Container, volumeName string) *corev1.VolumeMount
- func GetVolumeMountName(volumes []corev1.Volume, resourceName string) *corev1.Volume
- func GuessLorryHTTPPort(pod *corev1.Pod) (int32, error)
- func HandleCRDeletion(reqCtx RequestCtx, r client.Writer, cr client.Object, finalizer string, ...) (*ctrl.Result, error)
- func IgnoreIsAlreadyExists(err error) error
- func InVolumeSnapshotV1Beta1() bool
- func InjectZeroResourcesLimitsIfEmpty(c *corev1.Container)
- func IsApplyConfigChanged(configMap *corev1.ConfigMap, item v1alpha1.ConfigurationItemDetail) bool
- func IsAvailable(pod *corev1.Pod, minReadySeconds int32) bool
- func IsDelayedRequeueError(err error) bool
- func IsMatchConfigVersion(obj client.Object, labelKey string, version string) bool
- func IsNil(i interface{}) bool
- func IsNotFound(err error) bool
- func IsRSMEnabled() bool
- func IsRequeueError(err error) bool
- func IsRerender(configMap *corev1.ConfigMap, item v1alpha1.ConfigurationItemDetail) bool
- func IsTargetError(err error, errorType ErrorType) bool
- func IsVolumeSnapshotEnabled(ctx context.Context, cli client.Client, pvName string) (bool, error)
- func ManagedByKubeBlocksFilterPredicate(object client.Object) bool
- func MergeAndValidateConfigs(configConstraint v1alpha1.ConfigConstraintSpec, baseConfigs map[string]string, ...) (map[string]string, error)
- func MergeMetadataMap(originalMap map[string]string, targetMap *map[string]string)
- func NewDelayedRequeueError(after time.Duration, reason string) error
- func NewEncryptor(encryptionKey string) *encryptor
- func NewRequeueError(after time.Duration, reason string) error
- 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 SetControllerReference(owner, object metav1.Object) error
- func SetOwnerReference(owner, object metav1.Object) error
- func SetOwnership(owner, obj client.Object, scheme *runtime.Scheme, finalizer string, ...) error
- func ValidateExistence(ctx context.Context, cli roclient.ReadonlyClient, key client.ObjectKey, ...) 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 DelayedRequeueError
- type Error
- type ErrorType
- type Fetcher
- 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 RequeueError
- type ResourceCtx
- type ResourceFetcher
- func (r *ResourceFetcher[T]) Cluster() *T
- func (r *ResourceFetcher[T]) ClusterComponent() *T
- func (r *ResourceFetcher[T]) ClusterDef() *T
- func (r *ResourceFetcher[T]) ClusterVer() *T
- func (r *ResourceFetcher[T]) Complete() error
- func (r *ResourceFetcher[T]) ConfigConstraints(ccName string) *T
- func (r *ResourceFetcher[T]) ConfigMap(configSpec string) *T
- func (r *ResourceFetcher[T]) Configuration() *T
- func (r *ResourceFetcher[T]) Init(ctx *ResourceCtx, object *T) *T
- func (r *ResourceFetcher[T]) Wrap(fn func() error) (ret *T)
- type Result
- type VolumeSnapshotCompatClient
- func (c *VolumeSnapshotCompatClient) CheckResourceExists(key client.ObjectKey, obj client.Object) (bool, error)
- func (c *VolumeSnapshotCompatClient) Create(obj client.Object, opts ...client.CreateOption) error
- func (c *VolumeSnapshotCompatClient) Delete(snapshot client.Object) error
- func (c *VolumeSnapshotCompatClient) Get(key client.ObjectKey, snapshot client.Object, opts ...client.GetOption) error
- func (c *VolumeSnapshotCompatClient) List(objList client.ObjectList, opts ...client.ListOption) error
- func (c *VolumeSnapshotCompatClient) Patch(snapshot client.Object, deepCopy client.Object, opts ...client.PatchOption) error
Constants ¶
This section is empty.
Variables ¶
var ErrFailedToAddFinalizer = errors.New("failed to add finalizer")
Functions ¶
func BackgroundDeleteObject ¶
BackgroundDeleteObject deletes the object in the background, usually used in the Reconcile method
func BuildPodHostDNS ¶
BuildPodHostDNS builds the host dns of pod. ref: https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/
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 passes the error through to the controller manager, it ignores unknown errors.
func CreateOrUpdatePodVolumes ¶
func CreateOrUpdatePodVolumes(podSpec *corev1.PodSpec, volumes map[string]appsv1alpha1.ComponentTemplateSpec) error
func CreateOrUpdateVolume ¶
func GetConfigSpecReconcilePhase ¶
func GetConfigSpecReconcilePhase(configMap *corev1.ConfigMap, item v1alpha1.ConfigurationItemDetail, status *v1alpha1.ConfigurationItemDetailStatus) v1alpha1.ConfigurationPhase
GetConfigSpecReconcilePhase gets the configuration phase
func GetContainerByConfigSpec ¶
func GetContainerByConfigSpec(podSpec *corev1.PodSpec, configs []appsv1alpha1.ComponentConfigSpec) *corev1.Container
GetContainerByConfigSpec searches for container using the configmap of config from the pod
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 gets the containerID from pod by name
func GetCoreNum ¶
GetCoreNum gets content of Resources.Limits.cpu
func GetIntOrPercentValue ¶
func GetIntOrPercentValue(intOrStr *metautil.IntOrString) (int, bool, error)
func GetLorryContainerName ¶ added in v0.7.1
GetLorryContainerName gets the probe container from pod
func GetMemorySize ¶
GetMemorySize gets content of 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 searches for containers mounting the volume
func GetPodRevision ¶
GetPodRevision gets the revision of Pod by inspecting the StatefulSetRevisionLabel. If pod has no revision empty string is returned.
func GetPortByPortName ¶
GetPortByPortName gets the Port from pod by name
func GetRequestMemorySize ¶
GetRequestMemorySize gets content of Resources.Limits.memory
func GetStorageSizeFromPersistentVolume ¶
func GetStorageSizeFromPersistentVolume(pvc corev1.PersistentVolumeClaimTemplate) int64
GetStorageSizeFromPersistentVolume gets content of Resources.Requests.storage
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 finds the volume with mount name
func GuessLorryHTTPPort ¶
GuessLorryHTTPPort guesses lorry container and serving port. TODO(xuriwuyun): should provide a deterministic way to find the lorry serving port.
func HandleCRDeletion ¶
func HandleCRDeletion(reqCtx RequestCtx, r client.Writer, cr client.Object, finalizer string, deletionHandler func() (*ctrl.Result, error)) (*ctrl.Result, error)
HandleCRDeletion handles CR deletion, adds finalizer if found a non-deleting object and removes finalizer during deletion process. Passes optional 'deletionHandler' func for external dependency deletion. Returns Result pointer if required to return out of outer 'Reconcile' reconciliation loop.
func IgnoreIsAlreadyExists ¶
IgnoreIsAlreadyExists returns errors if 'err' is not type of AlreadyExists
func InVolumeSnapshotV1Beta1 ¶
func InVolumeSnapshotV1Beta1() bool
func IsApplyConfigChanged ¶
func IsApplyConfigChanged(configMap *corev1.ConfigMap, item v1alpha1.ConfigurationItemDetail) bool
IsApplyConfigChanged checks if the configuration is changed
func IsDelayedRequeueError ¶
func IsMatchConfigVersion ¶
func IsNotFound ¶
IsNotFound returns true if the specified error is the error type of ErrorTypeNotFound.
func IsRSMEnabled ¶
func IsRSMEnabled() bool
IsRSMEnabled enables rsm by default. respect the feature gate if set, keep the ability to disable it.
func IsRequeueError ¶
IsRequeueError checks if the error is the RequeueError.
func IsRerender ¶
func IsRerender(configMap *corev1.ConfigMap, item v1alpha1.ConfigurationItemDetail) bool
IsRerender checks if the configuration template is changed
func IsTargetError ¶
IsTargetError checks if the error is the target error.
func IsVolumeSnapshotEnabled ¶
IsVolumeSnapshotEnabled checks if the CSI supports the volume snapshot.
func ManagedByKubeBlocksFilterPredicate ¶
ManagedByKubeBlocksFilterPredicate provides filter predicate for objects managed by kubeBlocks.
func MergeAndValidateConfigs ¶
func MergeAndValidateConfigs(configConstraint v1alpha1.ConfigConstraintSpec, baseConfigs map[string]string, cmKey []string, updatedParams []core.ParamPairs) (map[string]string, error)
MergeAndValidateConfigs merges and validates configuration files
func MergeMetadataMap ¶ added in v0.8.0
MergeMetadataMap merges two map[string]string, the targetMap will be updated.
func NewDelayedRequeueError ¶
NewDelayedRequeueError creates a delayed requeue error which only returns in the last step of the DAG.
func NewEncryptor ¶
func NewEncryptor(encryptionKey string) *encryptor
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 if pod is ready for ConsensusSet/ReplicationSet component, it will be available when the pod is ready and labeled with 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 records an event when a CR created successfully
func RequeueAfter ¶
func RequeueWithError ¶
func RequeueWithError(err error, logger logr.Logger, msg string, keysAndValues ...interface{}) (reconcile.Result, error)
RequeueWithError requeues when an error occurs
func RequeueWithErrorAndRecordEvent ¶
func RequeueWithErrorAndRecordEvent(obj client.Object, recorder record.EventRecorder, err error, logger logr.Logger) (reconcile.Result, error)
RequeueWithErrorAndRecordEvent requeues when an error occurs. if it is an unknown error, triggers an event
func SetControllerReference ¶
func SetOwnerReference ¶
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 ValidateExistence ¶
func ValidateReferenceCR ¶
func ValidateReferenceCR(reqCtx RequestCtx, cli client.Client, obj client.Object, labelKey string, recordEvent func(), objLists ...client.ObjectList) (*ctrl.Result, error)
ValidateReferenceCR validates existing 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 DelayedRequeueError ¶
type DelayedRequeueError interface { RequeueError Delayed() }
type Error ¶
func NewFatalError ¶
NewFatalError returns a new Error with ErrorTypeFatal
func NewNotFound ¶
NewNotFound returns a new Error with ErrorTypeNotFound.
func UnwrapControllerError ¶
UnwrapControllerError unwraps the Controller error from target 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. ErrorTypeFatal ErrorType = "Fatal" // fatal error // ErrorType for cluster controller ErrorTypeBackupFailed ErrorType = "BackupFailed" ErrorTypeRestoreFailed ErrorType = "RestoreFailed" ErrorTypeNeedWaiting ErrorType = "NeedWaiting" // waiting for next reconcile // ErrorType for preflight ErrorTypePreflightCommon = "PreflightCommon" ErrorTypeSkipPreflight = "SkipPreflight" )
type Fetcher ¶
type Fetcher struct { ResourceFetcher[Fetcher] }
func NewResourceFetcher ¶
func NewResourceFetcher(resourceCtx *ResourceCtx) *Fetcher
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 updates Context value, returns parent Context.
type RequeueError ¶
type ResourceCtx ¶
type ResourceFetcher ¶
type ResourceFetcher[T any] struct { *ResourceCtx ClusterObj *appsv1alpha1.Cluster ClusterDefObj *appsv1alpha1.ClusterDefinition ClusterVerObj *appsv1alpha1.ClusterVersion ConfigMapObj *corev1.ConfigMap ConfigurationObj *appsv1alpha1.Configuration ConfigConstraintObj *appsv1alpha1.ConfigConstraint ClusterComObj *appsv1alpha1.ClusterComponentSpec // contains filtered or unexported fields }
func (*ResourceFetcher[T]) Cluster ¶
func (r *ResourceFetcher[T]) Cluster() *T
func (*ResourceFetcher[T]) ClusterComponent ¶
func (r *ResourceFetcher[T]) ClusterComponent() *T
func (*ResourceFetcher[T]) ClusterDef ¶
func (r *ResourceFetcher[T]) ClusterDef() *T
func (*ResourceFetcher[T]) ClusterVer ¶
func (r *ResourceFetcher[T]) ClusterVer() *T
func (*ResourceFetcher[T]) Complete ¶
func (r *ResourceFetcher[T]) Complete() error
func (*ResourceFetcher[T]) ConfigConstraints ¶
func (r *ResourceFetcher[T]) ConfigConstraints(ccName string) *T
func (*ResourceFetcher[T]) ConfigMap ¶
func (r *ResourceFetcher[T]) ConfigMap(configSpec string) *T
func (*ResourceFetcher[T]) Configuration ¶
func (r *ResourceFetcher[T]) Configuration() *T
func (*ResourceFetcher[T]) Init ¶
func (r *ResourceFetcher[T]) Init(ctx *ResourceCtx, object *T) *T
func (*ResourceFetcher[T]) Wrap ¶
func (r *ResourceFetcher[T]) Wrap(fn func() error) (ret *T)
type Result ¶
type Result struct { Phase v1alpha1.ConfigurationPhase `json:"phase"` Revision string `json:"revision"` Policy string `json:"policy"` ExecResult string `json:"execResult"` SucceedCount int32 `json:"succeedCount"` ExpectedCount int32 `json:"expectedCount"` Retry bool `json:"retry"` Failed bool `json:"failed"` Message string `json:"message"` }
type VolumeSnapshotCompatClient ¶
type VolumeSnapshotCompatClient struct { client.Client roclient.ReadonlyClient Ctx context.Context }
VolumeSnapshotCompatClient client is compatible with VolumeSnapshot v1 and v1beta1
func (*VolumeSnapshotCompatClient) CheckResourceExists ¶
func (c *VolumeSnapshotCompatClient) CheckResourceExists(key client.ObjectKey, obj client.Object) (bool, error)
CheckResourceExists checks whether resource exist or not.
func (*VolumeSnapshotCompatClient) Create ¶
func (c *VolumeSnapshotCompatClient) Create(obj client.Object, opts ...client.CreateOption) error
func (*VolumeSnapshotCompatClient) Delete ¶
func (c *VolumeSnapshotCompatClient) Delete(snapshot client.Object) error
func (*VolumeSnapshotCompatClient) List ¶
func (c *VolumeSnapshotCompatClient) List(objList client.ObjectList, opts ...client.ListOption) error
func (*VolumeSnapshotCompatClient) Patch ¶
func (c *VolumeSnapshotCompatClient) Patch(snapshot client.Object, deepCopy client.Object, opts ...client.PatchOption) error