Documentation ¶
Index ¶
- Constants
- Variables
- func BackgroundDeleteObject(cli client.Client, ctx context.Context, obj client.Object, ...) error
- func BuildHostPortName(clusterName, compName, containerName, portName string) string
- func BuildImagePullSecrets() []corev1.LocalObjectReference
- func BuildPodHostDNS(pod *corev1.Pod) string
- func CheckAndPatchPayload(item *v1alpha1.ConfigurationItemDetail, payloadID string, payload interface{}) (bool, error)
- func CheckResourceExists(ctx context.Context, cli client.Reader, 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 DeleteOwnedResources[T generics.Object, PT generics.PObject[T], L generics.ObjList[T], ...](ctx context.Context, cli client.Client, owner client.Object, ...) error
- func EnabledRuntimeMetrics() bool
- func GeKubeRestConfig(userAgent string) *rest.Config
- func GenShardingCompSpecList(ctx context.Context, cli client.Reader, cluster *appsv1alpha1.Cluster, ...) ([]*appsv1alpha1.ClusterComponentSpec, 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 GetLorryContainer(containers []corev1.Container) *corev1.Container
- func GetLorryContainerName(pod *corev1.Pod) (string, error)
- func GetLorryGRPCPort(pod *corev1.Pod) (int32, error)
- func GetLorryGRPCPortFromContainers(containers []corev1.Container) (int32, error)
- func GetLorryHTTPPort(pod *corev1.Pod) (int32, error)
- func GetLorryHTTPPortFromContainers(containers []corev1.Container) (int32, error)
- func GetMemorySize(container corev1.Container) int64
- func GetOriginalOrGeneratedComponentSpecByName(ctx context.Context, cli client.Reader, cluster *appsv1alpha1.Cluster, ...) (*appsv1alpha1.ClusterComponentSpec, error)
- func GetPodCondition(status *corev1.PodStatus, conditionType corev1.PodConditionType) *corev1.PodCondition
- func GetPodContainer(pod *corev1.Pod, containerName string) *corev1.Container
- func GetPodContainerWithVolumeMount(podSpec *corev1.PodSpec, volumeName string) []*corev1.Container
- func GetPodListByInstanceSet(ctx context.Context, cli client.Client, its *workloads.InstanceSet) ([]corev1.Pod, error)
- func GetPodRevision(pod *corev1.Pod) string
- func GetPortByPortName(containers []corev1.Container, 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 HandleCRDeletion(reqCtx RequestCtx, r client.Writer, cr client.Object, finalizer string, ...) (*ctrl.Result, error)
- func IgnoreIsAlreadyExists(err error) error
- func InitHostPortManager(cli client.Client) error
- 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 IsPodFailedAndTimedOut(pod *corev1.Pod) (bool, bool, string)
- func IsRequeueError(err error) bool
- func IsRerender(configMap *corev1.ConfigMap, item v1alpha1.ConfigurationItemDetail) bool
- func IsTargetError(err error, errorType ErrorType) bool
- func ListShardingComponents(ctx context.Context, cli client.Reader, cluster *appsv1alpha1.Cluster, ...) ([]appsv1alpha1.Component, error)
- func ManagedByKubeBlocksFilterPredicate(object client.Object) bool
- func MergeAndValidateConfigs(configConstraint appsv1beta1.ConfigConstraintSpec, ...) (map[string]string, error)
- func MergeList[E any](src, dst *[]E, f func(E) func(E) bool)
- func MergeMetadataMapInplace(originalMap map[string]string, targetMap *map[string]string)
- func MergeMetadataMaps(originalMap map[string]string, targetMaps ...map[string]string) map[string]string
- func NewControllerManagedBy(mgr manager.Manager, objs ...client.Object) *builder.Builder
- func NewDelayedRequeueError(after time.Duration, reason string) error
- func NewEncryptor(encryptionKey string) *encryptor
- func NewRequeueError(after time.Duration, reason string) error
- 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 ResolveContainerDefaultFields(container corev1.Container, pcontainer *corev1.Container)
- func ResolvePodSpecDefaultFields(obj corev1.PodSpec, pobj *corev1.PodSpec)
- func ResourcesPayloadForComponent(resources corev1.ResourceRequirements) any
- 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 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 PortManager
- func (pm *PortManager) AllocatePort(key string) (int32, error)
- func (pm *PortManager) GetPort(key string) (int32, error)
- func (pm *PortManager) ReleaseByPrefix(prefix string) error
- func (pm *PortManager) ReleasePort(key string) error
- func (pm *PortManager) ReleasePorts(keys []string) error
- func (pm *PortManager) UsePort(key string, port int32) error
- type PortRange
- 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 Result
Constants ¶
const FeatureGateEnableRuntimeMetrics = "ENABLED_RUNTIME_METRICS"
const (
GenerateNameMaxRetryTimes = 1000000
)
const ( // PodContainerFailedTimeout the timeout for container of pod failures, the component phase will be set to Failed/Abnormal after this time. PodContainerFailedTimeout = 10 * time.Second )
Variables ¶
var ErrFailedToAddFinalizer = errors.New("failed to add finalizer")
Functions ¶
func BackgroundDeleteObject ¶
func BackgroundDeleteObject(cli client.Client, ctx context.Context, obj client.Object, opts ...client.DeleteOption) error
BackgroundDeleteObject deletes the object in the background, usually used in the Reconcile method
func BuildHostPortName ¶ added in v0.8.0
func BuildImagePullSecrets ¶ added in v0.9.1
func BuildImagePullSecrets() []corev1.LocalObjectReference
func BuildPodHostDNS ¶
BuildPodHostDNS builds the host dns of pod. ref: https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/
func CheckAndPatchPayload ¶ added in v0.8.0
func CheckAndPatchPayload(item *v1alpha1.ConfigurationItemDetail, payloadID string, payload interface{}) (bool, error)
func CheckResourceExists ¶
func CheckResourceExists( ctx context.Context, cli client.Reader, 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, configSet []string) error
func CreateOrUpdateVolume ¶
func DeleteOwnedResources ¶ added in v0.8.3
func DeleteOwnedResources[T generics.Object, PT generics.PObject[T], L generics.ObjList[T], PL generics.PObjList[T, L]](ctx context.Context, cli client.Client, owner client.Object, resourceMatchLabels client.MatchingLabels, _ func(T, PT, L, PL)) error
DeleteOwnedResources deletes the matched resources which are owned by the owner.
func EnabledRuntimeMetrics ¶ added in v0.9.0
func EnabledRuntimeMetrics() bool
func GeKubeRestConfig ¶ added in v0.7.4
func GenShardingCompSpecList ¶ added in v0.8.2
func GenShardingCompSpecList(ctx context.Context, cli client.Reader, cluster *appsv1alpha1.Cluster, shardingSpec *appsv1alpha1.ShardingSpec) ([]*appsv1alpha1.ClusterComponentSpec, error)
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 GetLorryContainer ¶ added in v0.8.0
func GetLorryContainerName ¶ added in v0.7.1
GetLorryContainerName gets the lorry container from pod
func GetLorryGRPCPortFromContainers ¶ added in v0.8.0
func GetLorryHTTPPortFromContainers ¶ added in v0.8.0
func GetMemorySize ¶
GetMemorySize gets content of Resources.Limits.memory
func GetOriginalOrGeneratedComponentSpecByName ¶ added in v0.8.2
func GetOriginalOrGeneratedComponentSpecByName(ctx context.Context, cli client.Reader, cluster *appsv1alpha1.Cluster, componentName string) (*appsv1alpha1.ClusterComponentSpec, error)
GetOriginalOrGeneratedComponentSpecByName get an original or generated cluster component spec by componentName.
func GetPodCondition ¶
func GetPodCondition(status *corev1.PodStatus, conditionType corev1.PodConditionType) *corev1.PodCondition
func GetPodContainer ¶ added in v0.9.0
GetPodContainer gets the pod container by name. if containerName is empty, return the first container.
func GetPodContainerWithVolumeMount ¶
GetPodContainerWithVolumeMount searches for containers mounting the volume
func GetPodListByInstanceSet ¶ added in v0.9.0
func GetPodListByInstanceSet(ctx context.Context, cli client.Client, its *workloads.InstanceSet) ([]corev1.Pod, error)
GetPodListByInstanceSet gets ITS pod list.
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 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 InitHostPortManager ¶ added in v0.8.0
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 IsPodFailedAndTimedOut ¶ added in v0.8.2
IsPodFailedAndTimedOut checks if the pod is failed and timed out.
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 ListShardingComponents ¶ added in v0.9.0
func ListShardingComponents(ctx context.Context, cli client.Reader, cluster *appsv1alpha1.Cluster, shardingName string) ([]appsv1alpha1.Component, error)
func ManagedByKubeBlocksFilterPredicate ¶
ManagedByKubeBlocksFilterPredicate provides filter predicate for objects managed by kubeBlocks.
func MergeAndValidateConfigs ¶
func MergeAndValidateConfigs(configConstraint appsv1beta1.ConfigConstraintSpec, baseConfigs map[string]string, cmKey []string, updatedParams []core.ParamPairs) (map[string]string, error)
MergeAndValidateConfigs merges and validates configuration files
func MergeMetadataMapInplace ¶ added in v0.8.2
MergeMetadataMapInplace merges two map[string]string, the targetMap will be updated.
func MergeMetadataMaps ¶ added in v0.8.2
func MergeMetadataMaps(originalMap map[string]string, targetMaps ...map[string]string) map[string]string
MergeMetadataMaps merges targetMaps into originalMap if item not exist in originalMap and return the merged map.
func NewControllerManagedBy ¶ added in v0.9.2
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 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 ResolveContainerDefaultFields ¶ added in v0.8.0
ResolveContainerDefaultFields set default value for some known fields of proto Container @pcontainer.
func ResolvePodSpecDefaultFields ¶ added in v0.8.0
ResolvePodSpecDefaultFields set default value for some known fields of proto PodSpec @pobj.
func ResourcesPayloadForComponent ¶ added in v0.9.0
func ResourcesPayloadForComponent(resources corev1.ResourceRequirements) any
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 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" ErrorIgnoreCancel ErrorType = "IgnoreCancel" // 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" // ErrorTypeExpectedInProcess is used to indicate that the operation is expected to be in process. ErrorTypeExpectedInProcess ErrorType = "ExpectedInProcess" )
type PortManager ¶ added in v0.8.0
func GetPortManager ¶ added in v0.8.0
func GetPortManager() *PortManager
func NewPortManager ¶ added in v0.8.0
func NewPortManager(includes []PortRange, excludes []PortRange, cli client.Client) (*PortManager, error)
NewPortManager creates a new PortManager TODO[ziang] Putting all the port information in one configmap may have performance issues and is not secure enough. There is a risk of accidental deletion leading to the loss of cluster port information.
func (*PortManager) AllocatePort ¶ added in v0.8.0
func (pm *PortManager) AllocatePort(key string) (int32, error)
func (*PortManager) GetPort ¶ added in v0.9.0
func (pm *PortManager) GetPort(key string) (int32, error)
func (*PortManager) ReleaseByPrefix ¶ added in v0.8.0
func (pm *PortManager) ReleaseByPrefix(prefix string) error
func (*PortManager) ReleasePort ¶ added in v0.8.0
func (pm *PortManager) ReleasePort(key string) error
func (*PortManager) ReleasePorts ¶ added in v0.8.0
func (pm *PortManager) ReleasePorts(keys []string) error
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 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"` }