syncapi

package
v1.13.0-rc.2 Latest Latest
Warning

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

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

Documentation

Overview

Package syncapi defines the contract for mirroring a Kubernetes resource kind.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diff

func Diff[Object client.Object, Row any](
	ctx context.Context,
	reader client.Reader,
	list client.ObjectList,
	rows map[string]Row,
	matches func(Object, Row) (bool, error),
	key func(Row) client.ObjectKey,
) ([]reconcile.Request, error)

Diff compares a database snapshot with a complete Kubernetes list and returns the keys that disagree. Callers must load rows before calling Diff. The reader may be cached, since every returned key is re-read live before it is acted on. Matching is resource-specific; missing rows and orphaned rows are handled here. Live objects come first, in list order, followed by the keys of orphaned rows sorted by name, with no duplicates. Neither the snapshot nor either data source is mutated.

Types

type Syncer

type Syncer interface {
	NewObject() client.Object
	// Sources returns the event sources that push keys for this kind: the
	// kind itself, usually through kube.Objects, and any other kind whose
	// changes must re-sync rows, such as a parent whose identity a row
	// records. The controller adds the periodic Diff after them.
	Sources(cache.Cache) []reconciler.Source[reconcile.Request]
	Sync(context.Context, client.Object) error
	// Delete is called only after Kubernetes confirms that the key is absent.
	Delete(context.Context, client.ObjectKey) error
	// Diff snapshots database rows before obtaining a complete Kubernetes list
	// and returns every key whose mirror needs attention: objects with a
	// missing or differing row, and rows whose object is gone. It performs no
	// writes and returns nothing on a failed or incomplete list. The list may
	// come from the cache: reconciling a returned key reads Kubernetes afresh
	// before upserting or deleting, so a stale entry costs at most one extra
	// reconcile or one more interval, never a wrong write.
	Diff(context.Context) ([]reconcile.Request, error)
}

Syncer owns the resource-specific mapping and storage operations. The shared controller supplies current objects from an uncached Kubernetes reader.

Jump to

Keyboard shortcuts

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