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:
- 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 Consistent(action func() error, attempts int, pollInterval time.Duration) func() error
- func ConsistentWaitCondition(wc WaitCondition, attempts int, pollInterval time.Duration) func() error
- func For(fn WaitCondition, opts ...Option) error
- func IsClusterApiObjectConditionSet(obj clusterApiObject, conditionType capi.ConditionType, ...) (bool, error)
- func WithoutDone(wc WaitCondition) func() error
- type Option
- type Options
- type Range
- type WaitCondition
- func AreAllDaemonSetsReady(ctx context.Context, kubeClient *client.Client) WaitCondition
- func AreAllDeploymentsReady(ctx context.Context, kubeClient *client.Client) WaitCondition
- func AreAllJobsSucceeded(ctx context.Context, kubeClient *client.Client) WaitCondition
- func AreAllPodsInSuccessfulPhase(ctx context.Context, kubeClient *client.Client) WaitCondition
- func AreAllStatefulSetsReady(ctx context.Context, kubeClient *client.Client) WaitCondition
- func AreNumNodesReady(ctx context.Context, kubeClient *client.Client, expectedNodes int, ...) WaitCondition
- func AreNumNodesReadyWithinRange(ctx context.Context, kubeClient *client.Client, expectedNodes Range, ...) WaitCondition
- func DoesResourceExist(ctx context.Context, kubeClient *client.Client, resource cr.Object) WaitCondition
- func IsAllAppDeployed(ctx context.Context, kubeClient *client.Client, ...) WaitCondition
- func IsAllAppStatus(ctx context.Context, kubeClient *client.Client, ...) WaitCondition
- func IsAppDeployed(ctx context.Context, kubeClient *client.Client, appName string, ...) WaitCondition
- func IsAppStatus(ctx context.Context, kubeClient *client.Client, appName string, ...) WaitCondition
- func IsAppVersion(ctx context.Context, kubeClient *client.Client, appName string, ...) WaitCondition
- func IsClusterConditionSet(ctx context.Context, kubeClient *client.Client, clusterName string, ...) WaitCondition
- func IsClusterReadyCondition(ctx context.Context, kubeClient *client.Client, clusterName string, ...) WaitCondition
- func IsKubeadmControlPlaneConditionSet(ctx context.Context, kubeClient *client.Client, clusterName string, ...) 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 = 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
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 ConsistentWaitCondition ¶ added in v1.25.0
func ConsistentWaitCondition(wc WaitCondition, attempts int, pollInterval time.Duration) func() error
ConsistentWaitCondition is like Consistent but takes in a WaitCondition
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.
func WithoutDone ¶ added in v1.25.0
func WithoutDone(wc WaitCondition) func() error
WithoutDone returns a WaitCondition that only returns an error (or nill if condition is met)
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 AreAllDaemonSetsReady ¶ added in v1.25.0
func AreAllDaemonSetsReady(ctx context.Context, kubeClient *client.Client) WaitCondition
AreAllDaemonSetsReady returns a WaitCondition that checks if all DaemonSets found in the cluster have the expected number of replicas ready
func AreAllDeploymentsReady ¶ added in v1.25.0
func AreAllDeploymentsReady(ctx context.Context, kubeClient *client.Client) WaitCondition
AreAllDeploymentsReady returns a WaitCondition that checks if all Deployments found in the cluster have the expected number of replicas ready
func AreAllJobsSucceeded ¶ added in v1.25.0
func AreAllJobsSucceeded(ctx context.Context, kubeClient *client.Client) WaitCondition
AreAllJobsSucceeded returns a WaitCondition that checks if all Jobs found in the cluster have completed successfully
func AreAllPodsInSuccessfulPhase ¶ added in v1.25.0
func AreAllPodsInSuccessfulPhase(ctx context.Context, kubeClient *client.Client) WaitCondition
AreAllPodsInSuccessfulPhase returns a WaitCondition that checks if all Pods found in the cluster are in a successful phase (e.g. running or completed)
func AreAllStatefulSetsReady ¶ added in v1.25.0
func AreAllStatefulSetsReady(ctx context.Context, kubeClient *client.Client) WaitCondition
AreAllStatefulSetsReady returns a WaitCondition that checks if all StatefulSets found in the cluster have the expected number of replicas ready
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