wait4

package
v1.20.2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TimeoutShort covers routine status changes on an already-running
	// operator and rgw: condition waits, deletions, field updates.
	TimeoutShort = 40 * time.Second
	// TimeoutMedium covers resource creation that needs a full reconcile,
	// such as a CephBucketTopic becoming Ready with its ARN set.
	TimeoutMedium = time.Minute
	// TimeoutLong covers first-reconcile waits that may race rgw startup,
	// such as CephObjectStoreUser creation right after the store comes up.
	TimeoutLong = 2 * time.Minute
)

Default timeouts for waiting on operator reconciliation in the object tests. Bespoke waits (e.g. the shared store's multi-minute teardown ladder) still pass explicit durations.

Variables

This section is empty.

Functions

func AssertAbsent

func AssertAbsent[T, L runtime.Object](
	ctx context.Context,
	t *testing.T,
	client NamespacedWatcher[T, L],
	name string,
	timeout time.Duration,
	msgAndArgs ...interface{},
) bool

AssertAbsent waits for a named resource to disappear without deleting it itself, reporting failures via assert.Fail (non-fatal). Use it for resources removed as a side effect of another action — e.g. an ObjectBucket that is garbage-collected when its ObjectBucketClaim is deleted. To delete and wait, use AssertDelete/RequireDelete.

func AssertCondition

func AssertCondition[T, L runtime.Object](
	ctx context.Context,
	t *testing.T,
	client NamespacedWatcher[T, L],
	name string,
	cond func(T) bool,
	timeout time.Duration,
	msgAndArgs ...interface{},
) (T, bool)

AssertCondition waits for the named resource to satisfy cond, reporting failures (including timeout) via assert.Fail (non-fatal). It returns the matching object and true on success. Use it to wait on an already-created resource — e.g. an OBC reaching Bound, or a status field changing after an update; for the create-and-wait case use AssertCreate/RequireCreate.

func AssertCreate

func AssertCreate[T, L runtime.Object](
	ctx context.Context,
	t *testing.T,
	client NamespacedReadyWaiter[T, L],
	obj T,
	ready func(T) bool,
	timeout time.Duration,
	msgAndArgs ...interface{},
) (T, bool)

AssertCreate creates obj and waits for the ready predicate, reporting failures (including timeout) via assert.Fail (non-fatal) like AssertDelete. It returns the live object and true on success. Prefer this for cleanup/best-effort creation where the test should continue on failure; for setup preconditions use RequireCreate.

func AssertDelete

func AssertDelete[T, L runtime.Object](
	ctx context.Context,
	t *testing.T,
	client NamespacedDeleter[T, L],
	name string,
	timeout time.Duration,
	msgAndArgs ...interface{},
) bool

AssertDelete deletes a single named resource and blocks until it is gone, reporting failures (including timeout) via assert.Fail (non-fatal). It returns true on success. Prefer this for teardown/cleanup, so a stuck finalizer on one resource does not prevent cleanup of the rest; use RequireDelete when later steps depend on the deletion having completed.

func AssertEventually

func AssertEventually(ctx context.Context, t *testing.T, timeout time.Duration, desc string, cond func(context.Context) error) bool

AssertEventually polls cond until it returns nil or the timeout elapses, reporting failure via assert.Fail (non-fatal). It is for state the Kubernetes API cannot watch (the rgw admin API, S3, SNS); k8s resources should use the watch-based helpers above. The poll loop is utils.Eventually; this adds the assert-flavored, non-fatal reporting that pairs with the AssertCreate/AssertDelete/AssertCondition family.

cond must not call assert or require: report transient failures by returning an error (which is surfaced in the timeout message), and make assertions on captured state after the wait. cond receives a context bounded by the wait deadline; thread it into the reads it performs.

func AssertPodLog

func AssertPodLog(
	ctx context.Context,
	t *testing.T,
	k8sh *utils.K8sHelper,
	namespace string,
	selector labels.Selector,
	timeout time.Duration,
	match func(line string) bool,
	msgAndArgs ...interface{},
) bool

AssertPodLog follows the logs of the first pod matching selector and reports failure via assert.Fail (non-fatal) if no line satisfies match before the timeout. It is for log-based state the Kubernetes API cannot watch (e.g. an operator logging a reconcile error); for a setup precondition use RequirePodLog.

func BucketTopic

func BucketTopic(bt *cephv1.CephBucketTopic) bool

BucketTopic reports whether a CephBucketTopic has been reconciled to Ready with its ARN populated. Note that .status.ARN is nil while .status.phase == Reconciling, so the phase check alone is not sufficient.

func BucketTopicPhase

func BucketTopicPhase(phase string) func(*cephv1.CephBucketTopic) bool

BucketTopicPhase returns a predicate reporting whether a CephBucketTopic's .status.phase matches phase. The parameter is a plain string because the cephv1 phase constants are a mix of ConditionType and ConditionReason (e.g. string(cephv1.ReconcileFailed)).

func OBBound

func OBBound(ob *bktv1alpha1.ObjectBucket) bool

OBBound reports whether an ObjectBucket has reached the Bound phase.

func OBCBound

func OBCBound(obc *bktv1alpha1.ObjectBucketClaim) bool

OBCBound reports whether an ObjectBucketClaim has reached the Bound phase.

func ObjectStore

func ObjectStore(os *cephv1.CephObjectStore) bool

ObjectStore reports whether a CephObjectStore has been reconciled to Ready.

func ObjectStoreUser

func ObjectStoreUser(u *cephv1.CephObjectStoreUser) bool

ObjectStoreUser reports whether a CephObjectStoreUser has been reconciled to Ready.

func ObjectStoreUserPhase

func ObjectStoreUserPhase(phase string) func(*cephv1.CephObjectStoreUser) bool

ObjectStoreUserPhase returns a predicate reporting whether a CephObjectStoreUser's .status.phase matches phase. The parameter is a plain string because the cephv1 phase constants are a mix of ConditionType and ConditionReason (e.g. string(cephv1.ReconcileFailed)).

func RequireAbsent

func RequireAbsent[T, L runtime.Object](
	ctx context.Context,
	t *testing.T,
	client NamespacedWatcher[T, L],
	name string,
	timeout time.Duration,
	msgAndArgs ...interface{},
)

RequireAbsent is the fatal counterpart of AssertAbsent.

func RequireCondition

func RequireCondition[T, L runtime.Object](
	ctx context.Context,
	t *testing.T,
	client NamespacedWatcher[T, L],
	name string,
	cond func(T) bool,
	timeout time.Duration,
	msgAndArgs ...interface{},
) T

RequireCondition is the fatal counterpart of AssertCondition.

func RequireCreate

func RequireCreate[T, L runtime.Object](
	ctx context.Context,
	t *testing.T,
	client NamespacedReadyWaiter[T, L],
	obj T,
	ready func(T) bool,
	timeout time.Duration,
	msgAndArgs ...interface{},
) T

RequireCreate is the fatal counterpart of AssertCreate: it stops the test (FailNow) if the resource cannot be created or does not become ready, and returns the live object. This is the common case for setup preconditions, so the call site needs no follow-up require.True.

func RequireDelete

func RequireDelete[T, L runtime.Object](
	ctx context.Context,
	t *testing.T,
	client NamespacedDeleter[T, L],
	name string,
	timeout time.Duration,
	msgAndArgs ...interface{},
)

RequireDelete is the fatal counterpart of AssertDelete: it stops the test (FailNow) if the resource cannot be deleted or is not gone before the timeout.

func RequireEventually

func RequireEventually(ctx context.Context, t *testing.T, timeout time.Duration, desc string, cond func(context.Context) error)

RequireEventually is the fatal counterpart of AssertEventually: it stops the test (FailNow) if cond does not succeed before the timeout. Use it when subsequent statements consume the polled result.

func RequirePodLog

func RequirePodLog(
	ctx context.Context,
	t *testing.T,
	k8sh *utils.K8sHelper,
	namespace string,
	selector labels.Selector,
	timeout time.Duration,
	match func(line string) bool,
	msgAndArgs ...interface{},
)

RequirePodLog is the fatal counterpart of AssertPodLog.

Types

type NamespacedDeleter

type NamespacedDeleter[T, L runtime.Object] interface {
	NamespacedWatcher[T, L]
	Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error
}

NamespacedDeleter is a NamespacedWatcher that can also delete by name.

type NamespacedReadyWaiter

type NamespacedReadyWaiter[T, L runtime.Object] interface {
	NamespacedWatcher[T, L]
	Create(ctx context.Context, obj T, opts metav1.CreateOptions) (T, error)
}

NamespacedReadyWaiter is a NamespacedWatcher that can also create.

type NamespacedWatcher

type NamespacedWatcher[T, L runtime.Object] interface {
	Get(ctx context.Context, name string, opts metav1.GetOptions) (T, error)
	List(ctx context.Context, opts metav1.ListOptions) (L, error)
	Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error)
}

NamespacedWatcher is satisfied by any typed namespaced client (corev1 ServiceInterface, cephv1 CephObjectStoreUserInterface, etc.). T is the resource's pointer type and L its list type, both inferred at the call site from the client's Get/List return types.

Jump to

Keyboard shortcuts

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