client-gok8s.io/client-go/tools/cache/synctrack Index | Files

package synctrack

import "k8s.io/client-go/tools/cache/synctrack"

Package synctrack contains utilities for helping controllers track whether they are "synced" or not, that is, whether they have processed all items from the informer's initial list.

Index

Types

type AsyncTracker

type AsyncTracker[T comparable] struct {
	// contains filtered or unexported fields
}

AsyncTracker helps propagate HasSynced in the face of multiple worker threads. The user has to monitor the upstream "has synced" and notify the tracker when that changes from false to true.

func NewAsyncTracker

func NewAsyncTracker[T comparable](name string) *AsyncTracker[T]

func (*AsyncTracker[T]) Done

func (t *AsyncTracker[T]) Done() <-chan struct{}

Done returns a channel that is closed if the source is synced and every key present in the initial list has been processed. This relies on the source not considering itself synced until *after* it has delivered the notification for the last key, and that notification handler must have called Start.

func (*AsyncTracker[T]) Finished

func (t *AsyncTracker[T]) Finished(key T)

Finished should be called when finished processing a key which was part of the initial list. Since keys are tracked individually, nothing bad happens if you call Finished without a corresponding call to Start. This makes it easier to use this in combination with e.g. queues which don't make it easy to plumb through the isInInitialList boolean.

func (*AsyncTracker[T]) HasSynced

func (t *AsyncTracker[T]) HasSynced() bool

HasSynced returns true if the source is synced and every key present in the initial list has been processed. This relies on the source not considering itself synced until *after* it has delivered the notification for the last key, and that notification handler must have called Start.

func (*AsyncTracker[T]) Name

func (t *AsyncTracker[T]) Name() string

func (*AsyncTracker[T]) Start

func (t *AsyncTracker[T]) Start(key T)

Start should be called prior to processing each key which is part of the initial list.

func (*AsyncTracker[T]) UpstreamHasSynced

func (t *AsyncTracker[T]) UpstreamHasSynced()

UpstreamHasSynced needs to be called at least once as soon as the upstream "has synced" becomes true. It tells AsyncTracker that the source is synced.

Must be called after handing over the initial list to Start.

type Lazy

type Lazy[T any] struct {
	Evaluate func() (T, error)
	// contains filtered or unexported fields
}

Lazy defers the computation of `Evaluate` to when it is necessary. It is possible that Evaluate will be called in parallel from multiple goroutines.

func (*Lazy[T]) Get

func (z *Lazy[T]) Get() (T, error)

Get should be called to get the current result of a call to Evaluate. If the current cached value is stale (due to a call to Notify), then Evaluate will be called synchronously. If subsequent calls to Get happen (without another Notify), they will all wait for the same return value.

Error returns are not cached and will cause multiple calls to evaluate!

func (*Lazy[T]) Notify

func (z *Lazy[T]) Notify()

Notify should be called when something has changed necessitating a new call to Evaluate.

type SingleFileTracker

type SingleFileTracker struct {
	// contains filtered or unexported fields
}

SingleFileTracker helps propagate HasSynced when events are processed in order (i.e. via a queue). The user has to monitor the upstream "has synced" and notify the tracker when that changes from false to true.

func NewSingleFileTracker

func NewSingleFileTracker(name string) *SingleFileTracker

func (*SingleFileTracker) Done

func (t *SingleFileTracker) Done() <-chan struct{}

Done returns a channel that is closed if the source is synced and every key present in the initial list has been processed. This relies on the source not considering itself synced until *after* it has delivered the notification for the last key, and that notification handler must have called Start.

func (*SingleFileTracker) Finished

func (t *SingleFileTracker) Finished()

Finished should be called when finished processing a key which was part of the initial list. You must never call Finished() before (or without) its corresponding Start(), that is a logic error that could cause HasSynced to return a wrong value. To help you notice this should it happen, Finished() will panic if the internal counter goes negative.

func (*SingleFileTracker) HasSynced

func (t *SingleFileTracker) HasSynced() bool

HasSynced returns true if the source is synced and every key present in the initial list has been processed. This relies on the source not considering itself synced until *after* it has delivered the notification for the last key, and that notification handler must have called Start.

func (*SingleFileTracker) Name

func (t *SingleFileTracker) Name() string

func (*SingleFileTracker) Start

func (t *SingleFileTracker) Start()

Start should be called prior to processing each key which is part of the initial list.

func (*SingleFileTracker) UpstreamHasSynced

func (t *SingleFileTracker) UpstreamHasSynced()

UpstreamHasSynced needs to be called at least once as soon as the upstream "has synced" becomes true. It tells SingleFileTracker that the source is synced.

Must be called after handing over the initial list to Start.

Source Files

lazy.go synctrack.go

Version
v0.36.0-beta.0
Published
Mar 20, 2026
Platform
linux/amd64
Imports
4 packages
Last checked
29 minutes ago

Tools for package owners.