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, f.wcClients), wait.WithContext(ctx), wait.WithInterval(10*time.Second), ) if err != nil { return nil, err }
Example using Gomega's `Eventually` with the `IsNumNodesReady` condition ¶
Eventually( wait.IsNumNodesReady(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:
- The success boolean is returned as `true`
- An error is returned from the WaitCondition function
- A timeout occurs, resulting in an error being returned
Index ¶
- Constants
- func For(fn WaitCondition, opts ...Option) error
- type Option
- type Options
- type WaitCondition
- func DoesResourceExist(ctx context.Context, kubeClient *client.Client, resource cr.Object) WaitCondition
- func IsClusterReadyCondition(ctx context.Context, kubeClient *client.Client, clusterName string, ...) WaitCondition
- func IsNumNodesReady(ctx context.Context, kubeClient *client.Client, expectedNodes int, ...) WaitCondition
- func IsResourceDeleted(ctx context.Context, kubeClient *client.Client, resource cr.Object) WaitCondition
Constants ¶
const ( // DefaultTimeout is the default max time to wait before returning an error if a timeout is not provided DefaultTimeout = 1 * time.Hour // DefaultInterval is the polling interval to use if an interval is not provided DefaultInterval = 10 * time.Second )
Variables ¶
This section is empty.
Functions ¶
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
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 ¶
WithContext overrides the context used when waiting. This allows for using a context with a timeout / deadline already set.
func WithInterval ¶
WithInterval overrides the default polling interval when waiting
func WithTimeout ¶
WithTimeout overrides the default timeout when waiting
type WaitCondition ¶
WaitCondition is a function performing a condition check for if we need to keep waiting
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 IsClusterReadyCondition ¶
func IsClusterReadyCondition(ctx context.Context, kubeClient *client.Client, clusterName string, namespace string, clientMap map[string]*client.Client) WaitCondition
IsClusterReadyCondition returns a WaitCondition to check when a cluster is considered ready and accessible
func IsNumNodesReady ¶
func IsNumNodesReady(ctx context.Context, kubeClient *client.Client, expectedNodes int, labels *cr.MatchingLabels) WaitCondition
IsNumNodesReady returns a WaitCondition that checks if the number of ready nodes matching the given labels equals or exceeds the expectedNodes value
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