Start is called by controller-runtime Controller and returns quickly. It cleans up when ctx is cancelled.
( ctx context.Context, q workqueue.TypedRateLimitingInterface[reconcile.Request], )
| 40 | // Start is called by controller-runtime Controller and returns quickly. |
| 41 | // It cleans up when ctx is cancelled. |
| 42 | func (t ticker) Start( |
| 43 | ctx context.Context, q workqueue.TypedRateLimitingInterface[reconcile.Request], |
| 44 | ) error { |
| 45 | ticker := time.NewTicker(t.Duration) |
| 46 | |
| 47 | // Pass t.GenericEvent to h when it is not filtered out by p. |
| 48 | // - https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/source/internal#EventHandler |
| 49 | emit := func() { |
| 50 | t.Handler.Generic(ctx, t.GenericEvent, q) |
| 51 | } |
| 52 | |
| 53 | if t.Immediate { |
| 54 | emit() |
| 55 | } |
| 56 | |
| 57 | // Repeat until ctx is cancelled. |
| 58 | go func() { |
| 59 | defer ticker.Stop() |
| 60 | |
| 61 | for { |
| 62 | select { |
| 63 | case <-ticker.C: |
| 64 | emit() |
| 65 | case <-ctx.Done(): |
| 66 | return |
| 67 | } |
| 68 | } |
| 69 | }() |
| 70 | |
| 71 | return nil |
| 72 | } |
no outgoing calls