1 package kpoll 2 3 import ( 4 "context" 5 6 "sigs.k8s.io/controller-runtime/pkg/client" 7 ) 8 9 // CheckOption controls the behavior of a check against a cluster via an instance 10 // of [KPoll]. 11 type CheckOption = func(*checkOpts) 12 13 type checkOpts struct { 14 client client.Client 15 fetch bool 16 ctx context.Context 17 } 18 19 // WithClient sets the client that will be used while evaluating checks. 20 func WithClient(c client.Client) CheckOption { 21 return func(o *checkOpts) { o.client = c } 22 } 23 24 // WithoutFetch causes Checks to be evaluated without fetching latest live state 25 // from API. 26 // 27 // This can be useful if your test logic needs to take full control over the 28 // fetching process, or if you need to write a check based on the error value 29 // returned from Get(): 30 // 31 // k.WaitOn(t, func(t poll.LogT) poll.Result { 32 // // Fetch object with custom Get options, etc 33 // return k.Compare(obj, myComparison, kpoll.WithoutFetch()) 34 // }) 35 func WithoutFetch() CheckOption { 36 return func(o *checkOpts) { o.fetch = false } 37 } 38 39 // WithContext overrides the [context.Context] for the check. By default, the 40 // context used to instantiate the poller is used. 41 func WithContext(ctx context.Context) CheckOption { 42 return func(o *checkOpts) { o.ctx = ctx } 43 } 44