Documentation
¶
Index ¶
- func AlwaysRetry(_ error) bool
- func CreateClientFromKubeConfigBytes(kubeConfigBytes []byte, connectionTimeout time.Duration) (kubernetes.Interface, error)
- func CreateClientSetFromRestConfig(config *rest.Config) (*kubernetes.Clientset, error)
- func CreateScalesGetter(config *rest.Config) (scale.ScalesGetter, error)
- func GetKubeConfigFromSecret(ctx context.Context, namespace, secretName string, client client.Client, ...) ([]byte, error)
- func GetResourceAnnotations(ctx context.Context, client client.Client, namespace string, ...) (map[string]string, error)
- func GetResourceReadyReplicas(ctx context.Context, cli client.Client, namespace string, ...) (int32, error)
- func GetScaleResource(ctx context.Context, client client.Client, scaler scale.ScaleInterface, ...) (*schema.GroupResource, *autoscalingv1.Scale, error)
- func PatchResourceAnnotations(ctx context.Context, cl client.Client, namespace string, ...) error
- func ReadAndUnmarshall[T any](filename string) (*T, error)
- func RetryOnError(ctx context.Context, logger logr.Logger, operation string, ...)
- func RetryUntilPredicate(ctx context.Context, logger logr.Logger, operation string, ...) bool
- func SleepWithContext(ctx context.Context, sleepFor time.Duration) error
- type RetryResult
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AlwaysRetry ¶
AlwaysRetry always returns true irrespective of the error passed.
func CreateClientFromKubeConfigBytes ¶
func CreateClientFromKubeConfigBytes(kubeConfigBytes []byte, connectionTimeout time.Duration) (kubernetes.Interface, error)
CreateClientFromKubeConfigBytes creates a client to connect to the Kube ApiServer using the kubeConfigBytes passed as a parameter It will also set a connection timeout and will disable KeepAlive.
func CreateClientSetFromRestConfig ¶
func CreateClientSetFromRestConfig(config *rest.Config) (*kubernetes.Clientset, error)
CreateClientSetFromRestConfig creates a kubernetes.Clientset from rest.Config.
func CreateScalesGetter ¶
func CreateScalesGetter(config *rest.Config) (scale.ScalesGetter, error)
CreateScalesGetter Creates a new ScalesGetter given the config
func GetKubeConfigFromSecret ¶
func GetKubeConfigFromSecret(ctx context.Context, namespace, secretName string, client client.Client, logger logr.Logger) ([]byte, error)
GetKubeConfigFromSecret extracts kubeconfig from a k8s secret with name secretName in namespace
func GetResourceAnnotations ¶
func GetResourceAnnotations(ctx context.Context, client client.Client, namespace string, resourceRef *autoscalingv1.CrossVersionObjectReference) (map[string]string, error)
GetResourceAnnotations gets the annotations for a resource identified by resourceRef withing the given namespace.
func GetResourceReadyReplicas ¶
func GetResourceReadyReplicas(ctx context.Context, cli client.Client, namespace string, resourceRef *autoscalingv1.CrossVersionObjectReference) (int32, error)
GetResourceReadyReplicas gets spec.replicas for any resource identified via resourceRef withing the given namespace. It is an error if there is no spec.replicas or if there is an error fetching the resource.
func GetScaleResource ¶
func GetScaleResource(ctx context.Context, client client.Client, scaler scale.ScaleInterface, logger logr.Logger, resourceRef *autoscalingv1.CrossVersionObjectReference, timeout time.Duration) (*schema.GroupResource, *autoscalingv1.Scale, error)
GetScaleResource returns a kubernetes scale subresource.
func PatchResourceAnnotations ¶
func PatchResourceAnnotations(ctx context.Context, cl client.Client, namespace string, resourceRef *autoscalingv1.CrossVersionObjectReference, patchBytes []byte) error
PatchResourceAnnotations patches the resource annotation with patchBytes. It uses StrategicMergePatchType strategy so the consumers should only provide changes to the annotations.
func ReadAndUnmarshall ¶
ReadAndUnmarshall reads file and Unmarshall the contents in a generic type
func RetryOnError ¶
func RetryOnError(ctx context.Context, logger logr.Logger, operation string, retriableFn func() error, interval time.Duration)
RetryOnError retries invoking a function till either the invocation of the function does not return an error or the context has timed-out or has been cancelled. The consumers should ensure that the context passed to it has a proper finite timeout set as there is no other timeout taken as a function argument.
func RetryUntilPredicate ¶
func RetryUntilPredicate(ctx context.Context, logger logr.Logger, operation string, predicateFn func() bool, timeout time.Duration, interval time.Duration) bool
RetryUntilPredicate retries an operation with a given `interval` until one of the following condition is met: 1. `predicateFn` returns true. 2. `timeout` expires. 3. `ctx` (context) is cancelled or expires. Returns true if the invocation of the `predicateFn` was successful and false otherwise.
Types ¶
type RetryResult ¶
RetryResult captures the result of a retriable operation.
func Retry ¶
func Retry[T any](ctx context.Context, logger logr.Logger, operation string, fn func() (T, error), numAttempts int, backOff time.Duration, canRetry func(error) bool) RetryResult[T]
Retry retries an operation `fn`, `numAttempts` number of times with a given `backOff` until one of the conditions is met: 1. Invocation of `fn` succeeds. 2. `canRetry` returns false. 3. `numAttempts` have exhausted. 4. `ctx` (context) has either been cancelled or it has expired. The result is captured eventually in `RetryResult`.
type Validator ¶
type Validator struct {
Error error
}
Validator is a struct to store all validation errors.
func (*Validator) MustNotBeEmpty ¶
MustNotBeEmpty checks whether the given value is empty. It returns false if it is empty or nil.
func (*Validator) MustNotBeNil ¶
MustNotBeNil checks whether the given value is nil and returns false if it is nil.
func (*Validator) ResourceRefMustBeValid ¶
func (v *Validator) ResourceRefMustBeValid(resourceRef *autoscalingv1.CrossVersionObjectReference, scheme *runtime.Scheme) bool
ResourceRefMustBeValid validates the given resourceRef by parsing the apiVersion.