Documentation
¶
Index ¶
- Constants
- Variables
- func BackgroundDeleteObject(cli client.Client, ctx context.Context, obj client.Object, ...) error
- func BuildImagePullSecrets() []corev1.LocalObjectReference
- func BuildPodHostDNS(pod *corev1.Pod) string
- 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 ComposePVCName(template corev1.PersistentVolumeClaim, itsName, podName string) string
- func CreateVolumeIfNotExist(volumes []corev1.Volume, volumeName string, createFn createVolumeFn) []corev1.Volume
- 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 GetContainerByConfigSpec(podSpec *corev1.PodSpec, configs []appsv1alpha1.ComponentConfigSpec) *corev1.Container
- func GetContainerByName(containers []corev1.Container, name string) (int, *corev1.Container)
- func GetContainersByConfigmap(containers []corev1.Container, volumeName string, cmName string, ...) []string
- func GetCoreNum(container corev1.Container) int64
- func GetKubeRestConfig(userAgent string) *rest.Config
- func GetKubeVersion() (string, error)
- func GetMemorySize(container corev1.Container) int64
- 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 GetPortByName(pod corev1.Pod, cname, pname 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 InitDefaultHostPortManager(cli client.Client) error
- func InjectZeroResourcesLimitsIfEmpty(c *corev1.Container)
- func IsAPIVersionSupported(apiVersion string) bool
- func IsDelayedRequeueError(err error) bool
- func IsInstanceAvailable(inst *workloads.Instance) bool
- func IsInstanceFailure(inst *workloads.Instance) bool
- func IsInstanceReady(inst *workloads.Instance) bool
- func IsInstanceReadyWithRole(inst *workloads.Instance) bool
- func IsInstanceTerminating(inst *workloads.Instance) bool
- func IsMatchConfigVersion(obj client.Object, labelKey string, version string) bool
- func IsNotFound(err error) bool
- func IsPodAvailable(pod *corev1.Pod, minReadySeconds int32) bool
- func IsPodFailedAndTimedOut(pod *corev1.Pod) (bool, bool, string)
- func IsPodReady(pod *corev1.Pod) bool
- func IsRequeueError(err error) bool
- func IsTargetError(err error, errorType ErrorType) bool
- func LoadRegistryConfig() 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) *builder.Builder
- func NewDelayedRequeueError(after time.Duration, reason string) error
- func NewEncryptor(encryptionKey string) *encryptor
- func NewRequeueError(after time.Duration, reason string) error
- func ObjectAPIVersionSupported(obj client.Object) bool
- func PodFQDN(namespace, compName, podName string) string
- func PodIsReadyWithLabel(pod corev1.Pod) bool
- func Reconciled() (reconcile.Result, error)
- func RecordCreatedEvent(r record.EventRecorder, cr client.Object)
- func ReplaceImageRegistry(image string) string
- 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 ResultToP(res reconcile.Result, err error) (*reconcile.Result, error)
- func ServiceFQDN(namespace, serviceName string) string
- 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 ToCoreV1PVCTs(vcts []appsv1.PersistentVolumeClaimTemplate) []corev1.PersistentVolumeClaimTemplate
- func ValidateReferenceCR(reqCtx RequestCtx, cli client.Client, obj client.Object, labelKey string, ...) (*ctrl.Result, error)
- type ByPodName
- type DelayedRequeueError
- type Error
- type ErrorType
- type PortManager
- 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
Constants ¶
const FeatureGateEnableRuntimeMetrics = "ENABLED_RUNTIME_METRICS"
const ( // PodContainerFailedTimeout the timeout for container of pod failures, the component phase will be set to Failed after this time. PodContainerFailedTimeout = 10 * time.Second )
Variables ¶
var ErrFailedToAddFinalizer = errors.New("failed to add finalizer")
var SupportResizeSubResource = supportResizeSubResourceImpl
SupportResizeSubResource is for the ease of tests
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 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 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 ComposePVCName ¶
func ComposePVCName(template corev1.PersistentVolumeClaim, itsName, podName string) string
func CreateVolumeIfNotExist ¶ added in v1.0.0
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 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 GetCoreNum ¶
GetCoreNum gets content of Resources.Limits.cpu
func GetKubeRestConfig ¶ added in v1.0.0
func GetKubeVersion ¶ added in v0.9.5
GetKubeVersion get the version of Kubernetes and return the gitVersion
func GetMemorySize ¶
GetMemorySize gets content of Resources.Limits.memory
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 GetPortByName ¶ added in v1.0.0
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 IsAPIVersionSupported ¶ added in v1.0.0
func IsDelayedRequeueError ¶
func IsInstanceAvailable ¶
IsInstanceAvailable returns true if an instance is ready for at least minReadySeconds
func IsInstanceFailure ¶
func IsInstanceReady ¶
IsInstanceReady returns true if an instance is ready
func IsInstanceReadyWithRole ¶
IsInstanceReadyWithRole checks if an instance is ready with the role observed.
func IsInstanceTerminating ¶
IsInstanceTerminating returns true if instance's DeletionTimestamp has been set
func IsMatchConfigVersion ¶
func IsNotFound ¶
IsNotFound returns true if the specified error is the error type of ErrorTypeNotFound.
func IsPodAvailable ¶ added in v1.0.0
IsPodAvailable returns true if pod is ready for at least minReadySeconds
func IsPodFailedAndTimedOut ¶ added in v0.8.2
IsPodFailedAndTimedOut checks if the pod is failed and timed out.
func IsPodReady ¶ added in v1.0.0
IsPodReady returns true if pod is ready Currently, if pod is being deleted and have a grace period, k8s still considers it ready, which is not what we expect. See https://github.com/kubernetes/kubernetes/issues/129552
func IsRequeueError ¶
IsRequeueError checks if the error is the RequeueError.
func IsTargetError ¶
IsTargetError checks if the error is the target error.
func LoadRegistryConfig ¶ added in v1.0.0
func LoadRegistryConfig() error
func MergeList ¶ added in v0.9.0
MergeList merge src to dst, dst is modified in place. f returns a function that can be passed to slices.IndexFunc(). Items in src will overwrite items in dst, if possible.
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 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 ObjectAPIVersionSupported ¶ added in v0.9.3
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 ReplaceImageRegistry ¶ added in v1.0.0
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 ServiceFQDN ¶ added in v1.0.0
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 ToCoreV1PVCTs ¶ added in v1.0.0
func ToCoreV1PVCTs(vcts []appsv1.PersistentVolumeClaimTemplate) []corev1.PersistentVolumeClaimTemplate
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
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
type PortManager interface {
GetPort(key string) (int32, error)
UsePort(key string, port int32) error
AllocatePort(key string) (int32, error)
ReleaseByPrefix(prefix string) error
PortKey(clusterName, compName, containerName, portName string) string
}
func GetPortManager ¶ added in v0.8.0
func GetPortManager(network *appsv1.ComponentNetwork) PortManager
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.