Documentation ¶
Index ¶
- Constants
- Variables
- func AlwaysRetry(_ error) bool
- func CreateClientFromKubeConfigBytes(kubeConfigBytes []byte, connectionTimeout time.Duration) (client.Client, error)
- func CreateClientSetFromRestConfig(config *rest.Config) (*kubernetes.Clientset, error)
- func CreateDiscoveryInterfaceFromKubeConfigBytes(kubeConfigBytes []byte, connectionTimeout time.Duration) (discovery.DiscoveryInterface, error)
- func CreateScalesGetter(config *rest.Config) (scale.ScalesGetter, error)
- func EqualOrBeforeNow(expiryTime time.Time) bool
- func GetEffectiveNodeConditionsForWorkers(shoot *v1beta1.Shoot) map[string][]string
- func GetKubeConfigFromSecret(ctx context.Context, namespace, secretName string, client client.Client, ...) ([]byte, error)
- func GetMachineNotInFailedOrTerminatingState(nodeName string, machines []v1alpha1.Machine) *v1alpha1.Machine
- 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 GetSliceOrDefault[T any](val []T, defaultVal []T) []T
- func GetValOrDefault[T any](val *T, defaultVal T) *T
- func GetWorkerUnhealthyNodeConditions(node *corev1.Node, workerNodeConditions map[string][]string) []string
- func IsNodeHealthyByConditions(node *corev1.Node, unhealthyWorkerConditionNames []string) bool
- func IsNodeManagedByMCM(node *corev1.Node) bool
- 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
- func (v *Validator) MustNotBeEmpty(key string, value interface{}) bool
- func (v *Validator) MustNotBeNil(key string, value interface{}) bool
- func (v *Validator) MustNotBeZeroDuration(key string, duration metav1.Duration) bool
- func (v *Validator) ResourceRefMustBeValid(resourceRef *autoscalingv1.CrossVersionObjectReference, scheme *runtime.Scheme) bool
Constants ¶
const (
// WorkerPoolLabel is the label key for the worker pool. It is used to determine the worker pool to which the node belongs.
WorkerPoolLabel = "worker.gardener.cloud/pool"
)
Variables ¶
var DefaultUnhealthyNodeConditions = []string{"KernelDeadlock", "ReadonlyFilesystem", "DiskPressure", "NetworkUnavailable"}
DefaultUnhealthyNodeConditions are the default node conditions which indicate that the node is unhealthy. These conditions are borrowed from MCM where these conditions are used to decide if a node is unhealthy and should be replaced. NOTE: If these default set of node conditions are changed in MCM, make sure to change it here as well.
Functions ¶
func AlwaysRetry ¶
AlwaysRetry always returns true irrespective of the error passed.
func CreateClientFromKubeConfigBytes ¶
func CreateClientFromKubeConfigBytes(kubeConfigBytes []byte, connectionTimeout time.Duration) (client.Client, 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 CreateDiscoveryInterfaceFromKubeConfigBytes ¶ added in v1.3.0
func CreateDiscoveryInterfaceFromKubeConfigBytes(kubeConfigBytes []byte, connectionTimeout time.Duration) (discovery.DiscoveryInterface, error)
CreateDiscoveryInterfaceFromKubeConfigBytes creates a discovery interface 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 CreateScalesGetter ¶
func CreateScalesGetter(config *rest.Config) (scale.ScalesGetter, error)
CreateScalesGetter Creates a new ScalesGetter given the config
func EqualOrBeforeNow ¶ added in v1.2.0
EqualOrBeforeNow returns false if the argument passed is after the current time.
func GetEffectiveNodeConditionsForWorkers ¶ added in v1.3.0
GetEffectiveNodeConditionsForWorkers initializes the node conditions per worker.
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 GetMachineNotInFailedOrTerminatingState ¶ added in v1.3.0
func GetMachineNotInFailedOrTerminatingState(nodeName string, machines []v1alpha1.Machine) *v1alpha1.Machine
GetMachineNotInFailedOrTerminatingState returns the machine corresponding to the node which is not in failed or terminating phase. It will return nil if no machine is found corresponding to the node or if the machine is in failed or terminating phase.
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 GetSliceOrDefault ¶ added in v1.3.0
func GetSliceOrDefault[T any](val []T, defaultVal []T) []T
GetSliceOrDefault assigns the default value if the slice is nil or empty
func GetValOrDefault ¶ added in v1.2.0
func GetValOrDefault[T any](val *T, defaultVal T) *T
GetValOrDefault assigns the default value if the pointer is nil
func GetWorkerUnhealthyNodeConditions ¶ added in v1.3.0
func GetWorkerUnhealthyNodeConditions(node *corev1.Node, workerNodeConditions map[string][]string) []string
GetWorkerUnhealthyNodeConditions returns the configured node conditions for the pool where this node belongs. Worker name is extracted from the node labels.
func IsNodeHealthyByConditions ¶ added in v1.3.0
IsNodeHealthyByConditions determines if a node is healthy by checking that none of the given unhealthyWorkerConditionNames have Status set to true.
func IsNodeManagedByMCM ¶ added in v1.3.0
IsNodeManagedByMCM determines if a node is managed by MCM by checking if the node has the annotation nodeNotManagedByMCMAnnotationKey"node.machine.sapcloud.io/not-managed-by-mcm" set.
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) MustNotBeZeroDuration ¶ added in v1.2.0
MustNotBeZeroDuration checks whether the given duration is zero. It returns false if it is zero.
func (*Validator) ResourceRefMustBeValid ¶
func (v *Validator) ResourceRefMustBeValid(resourceRef *autoscalingv1.CrossVersionObjectReference, scheme *runtime.Scheme) bool
ResourceRefMustBeValid validates the given resourceRef by parsing the apiVersion.