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, &clientPtr),
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
Additionally IsClusterReadyCondition accepts a pointer to a `client.Client` which will be set to a working workload cluster client once the condition is met. This allows the caller to use the client directly after the condition is met without needing to re-create the client.
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 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 AreNoPodsCrashLooping(ctx context.Context, kubeClient *client.Client, maxRestartCount int32) WaitCondition
- func AreNoPodsCrashLoopingWithFilter(ctx context.Context, kubeClient *client.Client, maxRestartCount int32, ...) 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
- type WaitConditionSlice
- func AreAllAppDeployedSlice(ctx context.Context, kubeClient *client.Client, ...) WaitConditionSlice
- func AreAllAppStatusSlice(ctx context.Context, kubeClient *client.Client, ...) WaitConditionSlice
- func AreAllDaemonSetsReadySlice(ctx context.Context, kubeClient *client.Client) WaitConditionSlice
- func AreAllDeploymentsReadySlice(ctx context.Context, kubeClient *client.Client) WaitConditionSlice
- func AreAllJobsSucceededSlice(ctx context.Context, kubeClient *client.Client) WaitConditionSlice
- func AreAllPodsInSuccessfulPhaseSlice(ctx context.Context, kubeClient *client.Client) WaitConditionSlice
- func AreAllStatefulSetsReadySlice(ctx context.Context, kubeClient *client.Client) WaitConditionSlice
- func ConsistentWaitConditionSlice(action WaitConditionSlice, attempts int, pollInterval time.Duration) WaitConditionSlice
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 ¶
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 ¶
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 ¶
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 IsClusterApiObjectConditionSet ¶
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. Deprecated: Use IsClusterAPIObjectConditionSet instead. nolint // Keep old name for backward compatibility
func WithoutDone ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 AreNoPodsCrashLooping ¶
func AreNoPodsCrashLooping(ctx context.Context, kubeClient *client.Client, maxRestartCount int32) WaitCondition
AreNoPodsCrashLooping checks that all pods within the cluster have fewer than the provided number of restarts
func AreNoPodsCrashLoopingWithFilter ¶
func AreNoPodsCrashLoopingWithFilter(ctx context.Context, kubeClient *client.Client, maxRestartCount int32, filterLabels []string) WaitCondition
AreNoPodsCrashLoopingWithFilter checks that all pods within the cluster have fewer than the provided number of restarts `filterLabels` is a list of label selector string to use to filter the pods to be checked. (e.g. `app.kubernetes.io/name!=cluster-autoscaler-app`)
func AreNumNodesReady ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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, clientPtr **client.Client) WaitCondition
IsClusterReadyCondition returns a WaitCondition to check when a cluster is considered ready and accessible. Additionally IsClusterReadyCondition accepts a pointer to a `client.Client` which will be set to a working workload cluster client once the condition is met. This allows the caller to use the client directly after the condition is met without needing to re-create the client.
func IsKubeadmControlPlaneConditionSet ¶
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
type WaitConditionSlice ¶
WaitConditionSlice is a function performing a condition check for if we need to keep waiting and returns a slice to use as the check
func AreAllAppDeployedSlice ¶
func AreAllAppDeployedSlice(ctx context.Context, kubeClient *client.Client, appNamespacedNames []types.NamespacedName) WaitConditionSlice
AreAllAppDeployedSlice returns a WaitConditionSlice that contains all the Apps not in a deployed state
func AreAllAppStatusSlice ¶
func AreAllAppStatusSlice(ctx context.Context, kubeClient *client.Client, appNamespacedNames []types.NamespacedName, expectedStatus string) WaitConditionSlice
AreAllAppStatusSlice returns a WaitConditionSlice that contains all the resources not in the expected status
func AreAllDaemonSetsReadySlice ¶
func AreAllDaemonSetsReadySlice(ctx context.Context, kubeClient *client.Client) WaitConditionSlice
AreAllDaemonSetsReadySlice returns a WaitConditionSlice that checks if all DaemonSets found in the cluster have the expected number of replicas ready
func AreAllDeploymentsReadySlice ¶
func AreAllDeploymentsReadySlice(ctx context.Context, kubeClient *client.Client) WaitConditionSlice
AreAllDeploymentsReadySlice returns a WaitConditionSlice that checks if all Deployments found in the cluster have the expected number of replicas ready
func AreAllJobsSucceededSlice ¶
func AreAllJobsSucceededSlice(ctx context.Context, kubeClient *client.Client) WaitConditionSlice
AreAllJobsSucceededSlice returns a WaitConditionSlice that checks if all Jobs found in the cluster have completed successfully
func AreAllPodsInSuccessfulPhaseSlice ¶
func AreAllPodsInSuccessfulPhaseSlice(ctx context.Context, kubeClient *client.Client) WaitConditionSlice
AreAllPodsInSuccessfulPhaseSlice returns a WaitConditionSlice that checks if all Pods found in the cluster are in a successful phase (e.g. running or completed)
func AreAllStatefulSetsReadySlice ¶
func AreAllStatefulSetsReadySlice(ctx context.Context, kubeClient *client.Client) WaitConditionSlice
AreAllStatefulSetsReadySlice returns a WaitConditionSlice that checks if all StatefulSets found in the cluster have the expected number of replicas ready
func ConsistentWaitConditionSlice ¶
func ConsistentWaitConditionSlice(action WaitConditionSlice, attempts int, pollInterval time.Duration) WaitConditionSlice
ConsistentSlice 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.