func Deleted(ctx context.Context, c client.Client, objs ...client.Object) poll.Check
Deleted checks that none of the provided objs exist on the cluster.
edge-infra.dev/pkg/k8s/object.IsDeleted is used to determine object existence.
func Exists(ctx context.Context, c client.Client, objs ...client.Object) poll.Check
Exists checks that all objs exist on the cluster.
edge-infra.dev/pkg/k8s/object.IsDeleted is used to determine object existence.
func InventoryExists(ctx context.Context, c client.Client, exp *inventory.ResourceInventory) poll.Check
InventoryExists checks that all the objects in the inventory exist on the cluster.
TODO(aw185176): Could probably use ListMeta() and additional elbow grease to avoid full parsing of unstructured objects and the multiple slice allocations for type massaging
func InventoryPruned(ctx context.Context, c client.Client, curr, old *inventory.ResourceInventory) poll.Check
InventoryPruned checks that the difference between the current and old inventory no longer exists on the cluster.
edge-infra.dev/pkg/k8s/object.IsDeleted is used to determine object existence.
func JoinResults(results ...poll.Result) poll.Result
JoinResults combines one or more polling results into a single gotest.tools/v3/poll.Result.
At least one poll.Result must be provided. If a single poll.Result is passed in, it is returned directly.
If any results contain an error, it is immediately returned. Otherwise, all unfinished results have their messages combined into a single gotest.tools/v3/poll.Continue call. If all results indicate they are done, gotest.tools/v3/poll.Success is returned.
TODO(aw18576): Consider generalizing this
CheckOption controls the behavior of a check against a cluster via an instance of KPoll.
type CheckOption = func(*checkOpts)
func WithClient(c client.Client) CheckOption
WithClient sets the client that will be used while evaluating checks.
func WithContext(ctx context.Context) CheckOption
WithContext overrides the context.Context for the check. By default, the context used to instantiate the poller is used.
func WithoutFetch() CheckOption
WithoutFetch causes Checks to be evaluated without fetching latest live state from API.
This can be useful if your test logic needs to take full control over the fetching process, or if you need to write a check based on the error value returned from Get():
k.WaitOn(t, func(t poll.LogT) poll.Result { // Fetch object with custom Get options, etc return k.Compare(obj, myComparison, kpoll.WithoutFetch()) })
KPoll allows asserting K8s Objects against a live cluster's state with default polling options and provides access to common assertions for K8s objects.
KPoll should be treated like other assertion helpers: instantiated for each individual test.
When instantiated as part of a test hook, this ensures that all assertions use a consistent and configurable timeout by default.
type KPoll struct {
// contains filtered or unexported fields
}
func New(ctx context.Context, c client.Client, timeout, tick time.Duration) *KPoll
func (k *KPoll) Check(o client.Object, c kmp.Komparison, options ...CheckOption) poll.Check
Check creates a gotest.tools/v3/poll.Check which evaluates Object o using Komparison c on each interval of a KPoll.WaitOn call. It uses KPoll.Compare to wrap the Komparison into a function that produces a polling result so that the check is always executed against the cluster's live state.
func (k *KPoll) CheckAll(objs []client.Object, c kmp.Komparison, options ...CheckOption) poll.Check
CheckAll is KPoll.Check for sets of objects.
func (k *KPoll) Compare(o client.Object, c kmp.Komparison, options ...CheckOption) poll.Result
Compare returns a gotest.tools/v3/poll.Result by evaluating Object o against Komparison c. The Object is re-fetched on each polling loop, allowing a standard edge-infra.dev/pkg/k8s/testing/kmp.Komparison to be continually evaluated against a cluster's state.
The poll.Result return can be used to wrap a Komparison with additional logic in an inline poll.Check:
kwait.On(t, func(t poll.LogT) poll.Result { // Evaluate check precondition // Perform comparison as polling step return kwait.Compare(ctx, obj, myComparison) })
func (k *KPoll) CompareAll(objs []client.Object, c kmp.Komparison, options ...CheckOption) poll.Result
CompareAll is KPoll.Compare for sets of objects. The comparison results are aggregated to produce the overall result.
func (k *KPoll) InventoryExists(exp *inventory.ResourceInventory, options ...CheckOption) poll.Check
InventoryExists checks that all member objects of the expected inventory exist on the cluster.
edge-infra.dev/pkg/k8s/object.IsDeleted is used to determine object existence.
func (k *KPoll) InventoryPruned(curr, old *inventory.ResourceInventory, options ...CheckOption) poll.Check
func (k *KPoll) ObjDeleted(o client.Object, options ...CheckOption) poll.Check
ObjDeleted checks that a single object doesn't exist on the cluster.
edge-infra.dev/pkg/k8s/object.IsDeleted is used to determine object existence.
func (k *KPoll) ObjExists(o client.Object, options ...CheckOption) poll.Check
ObjExists checks that a single object exists on the cluster.
edge-infra.dev/pkg/k8s/object.IsDeleted is used to determine object existence.
func (k *KPoll) ObjsDeleted(objs []client.Object, options ...CheckOption) poll.Check
ObjsDeleted checks that none of the provided objects exist on the cluster.
edge-infra.dev/pkg/k8s/object.IsDeleted is used to determine object existence.
func (k *KPoll) ObjsExist(objs []client.Object, options ...CheckOption) poll.Check
ObjsExist checks that all objects exist on the cluster.
edge-infra.dev/pkg/k8s/object.IsDeleted is used to determine object existence.
func (k *KPoll) WaitOn(t *testing.T, c poll.Check, opts ...poll.SettingOp)
WaitOn wraps gotest.tools/v3/poll.WaitOn with default options based on the KPoll configuration.