wait

package
v1.24.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2024 License: Apache-2.0 Imports: 17 Imported by: 4

Documentation

Overview

package wait provides functions to help with waiting for certain conditions to be true.

A `For` function is provided that can handle polling a given `WaitCondition` until it results in true or errors (either through a problem or a timeout condition).

A collection of conditions are also included that can be used with either the provided `For` function or or with the `Eventually` function from Gomega

Example using `For` with the `IsClusterReadyCondition` condition

err := wait.For(
	wait.IsClusterReadyCondition(ctx, f.MC(), clusterName, namespace),
	wait.WithContext(ctx),
	wait.WithInterval(10*time.Second),
)
if err != nil {
	return nil, err
}

Example using Gomega's `Eventually` with the `AreNumNodesReady` condition

Eventually(
	wait.AreNumNodesReady(ctx, client, 3, &cr.MatchingLabels{"node-role.kubernetes.io/control-plane": ""}),
	20*time.Minute,
	30*time.Second,
).Should(BeTrue())

The WaitCondition functions return a success boolean and an error. The polling of the condition will continue until one of three things occurs:

  1. The success boolean is returned as `true`
  2. An error is returned from the WaitCondition function
  3. A timeout occurs, resulting in an error being returned

Index

Constants

View Source
const (
	// DefaultTimeout is the default max time to wait before returning an error if a timeout is not provided
	DefaultTimeout = 30 * time.Minute
	// DefaultInterval is the polling interval to use if an interval is not provided
	DefaultInterval = 10 * time.Second
)

Variables

This section is empty.

Functions

func Consistent added in v0.0.9

func Consistent(action func() error, attempts int, pollInterval time.Duration) func() error

Consistent is a modifier for functions. It will return a function that will perform the provided action and return an error if that action doesn't consistently pass. You can configure the attempts and interval between attempts. This can be used in Ginkgo's Eventually to verify that something will eventually be consistent.

func For

func For(fn WaitCondition, opts ...Option) error

For continuously polls the provided WaitCondition function until either the timeout is reached or the function returns as done

func IsClusterApiObjectConditionSet added in v1.2.0

func IsClusterApiObjectConditionSet(obj clusterApiObject, conditionType capi.ConditionType, expectedStatus corev1.ConditionStatus, expectedReason string) (bool, error)

IsClusterApiObjectConditionSet checks if a cluster has the specified condition with the expected status.

Types

type Option

type Option func(*Options)

Option is a function that can be optionally provided to override default options of a wait condition

func WithContext

func WithContext(context context.Context) Option

WithContext overrides the context used when waiting. This allows for using a context with a timeout / deadline already set.

func WithInterval

func WithInterval(interval time.Duration) Option

WithInterval overrides the default polling interval when waiting

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout overrides the default timeout when waiting

type Options

type Options struct {
	Context  context.Context
	Interval time.Duration
	Timeout  time.Duration
}

Options are the options available when waiting

type Range added in v0.0.10

type Range struct {
	Min int
	Max int
}

Range is a wrapper for min and max values

type WaitCondition

type WaitCondition func() (done bool, err error)

WaitCondition is a function performing a condition check for if we need to keep waiting

func AreNumNodesReady added in v0.0.10

func AreNumNodesReady(ctx context.Context, kubeClient *client.Client, expectedNodes int, listOptions ...cr.ListOption) WaitCondition

AreNumNodesReady returns a WaitCondition that checks if the number of ready nodes equals or exceeds the expectedNodes value. It also receives a variadic arguments for list options

func AreNumNodesReadyWithinRange added in v0.0.10

func AreNumNodesReadyWithinRange(ctx context.Context, kubeClient *client.Client, expectedNodes Range, listOptions ...cr.ListOption) WaitCondition

AreNumNodesReadyWithinRange returns a WaitCondition that checks if the number of ready nodes are within the expected range. It also receives a variadic arguments for list options

func DoesResourceExist

func DoesResourceExist(ctx context.Context, kubeClient *client.Client, resource cr.Object) WaitCondition

DoesResourceExist returns a WaitCondition that checks if the given resource exists in the cluster

func IsAllAppDeployed added in v0.4.0

func IsAllAppDeployed(ctx context.Context, kubeClient *client.Client, appNamespacedNames []types.NamespacedName) WaitCondition

IsAllAppDeployed returns a WaitCondition that checks if all the apps provided have a deployed status

func IsAllAppStatus added in v0.4.0

func IsAllAppStatus(ctx context.Context, kubeClient *client.Client, appNamespacedNames []types.NamespacedName, expectedStatus string) WaitCondition

IsAllAppStatus returns a WaitCondition that checks if all the apps provided currently have the provided expected status

func IsAppDeployed added in v0.4.0

func IsAppDeployed(ctx context.Context, kubeClient *client.Client, appName string, appNamespace string) WaitCondition

IsAppDeployed returns a WaitCondition that checks if an app has a deployed status

func IsAppStatus added in v0.1.0

func IsAppStatus(ctx context.Context, kubeClient *client.Client, appName string, appNamespace string, expectedStatus string) WaitCondition

IsAppStatus returns a WaitCondition that checks if an app has the expected release status

func IsAppVersion added in v0.1.0

func IsAppVersion(ctx context.Context, kubeClient *client.Client, appName string, appNamespace string, expectedVersion string) WaitCondition

IsAppVersion returns a WaitCondition that checks if an app has the expected release status. This check ignores any `v` prefix on the version.

func IsClusterConditionSet added in v0.18.0

func IsClusterConditionSet(ctx context.Context, kubeClient *client.Client, clusterName string, clusterNamespace string, conditionType capi.ConditionType, expectedStatus corev1.ConditionStatus, expectedReason string) WaitCondition

IsClusterConditionSet returns a WaitCondition that checks if a Cluster resource has the specified condition with the expected status.

func IsClusterReadyCondition

func IsClusterReadyCondition(ctx context.Context, kubeClient *client.Client, clusterName string, namespace string) WaitCondition

IsClusterReadyCondition returns a WaitCondition to check when a cluster is considered ready and accessible

func IsKubeadmControlPlaneConditionSet added in v0.18.0

func IsKubeadmControlPlaneConditionSet(ctx context.Context, kubeClient *client.Client, clusterName string, clusterNamespace string, conditionType capi.ConditionType, expectedStatus corev1.ConditionStatus, expectedReason string) WaitCondition

IsKubeadmControlPlaneConditionSet returns a WaitCondition that checks if a KubeadmControlPlane resource has the specified condition with the expected status.

func IsResourceDeleted

func IsResourceDeleted(ctx context.Context, kubeClient *client.Client, resource cr.Object) WaitCondition

IsResourceDeleted returns a WaitCondition that checks if the given resource has been deleted from the cluster yet

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL