watchersyncer

package
v3.7.0-0.dev+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

watchersyncer package contains a syncer interface that can be used to sync from an arbitrary set of Watchers.

Optional processors may be specified for each watch type that convert between the raw data returned by the watch and the updates returned by the syncer.

The implementation could easily be ported to work on the main client Watcher which would be the preferred approach once all of the entries that we need to watch are defined as resource types.

We implement this as a syncer rather than a "multi-watcher", because the syncer doesn't need to maintain previous values of resources to send delete events (it only needs to maintain keys). This has a smaller footprint that an equivalent multi-watcher would have.

Index

Constants

This section is empty.

Variables

View Source
var (
	ListRetryInterval = 1000 * time.Millisecond
	WatchPollInterval = 5000 * time.Millisecond
)

Functions

func New

func New(client api.Client, resourceTypes []ResourceType, callbacks api.SyncerCallbacks) api.Syncer

New creates a new multiple Watcher-backed api.Syncer.

Types

type ResourceType

type ResourceType struct {
	// ListInterface specifies the resource type to watch\.
	ListInterface model.ListInterface

	// UpdateProcessor converts the raw KVPairs returned from the datastore into the appropriate
	// KVPairs required for the syncer.  This is optional.
	UpdateProcessor SyncerUpdateProcessor
}

ResourceType groups together the watch and conversion information for a specific resource type.

type SyncerUpdateProcessor

type SyncerUpdateProcessor interface {
	// Process is called to process a watch update.  The processor may convert this
	// to zero or more updates.  The processor may use these calls to maintain a local cache
	// if required.  It is safe for the processor to send multiple duplicate adds or deletes
	// since the WatcherSyncer maintains it's own cache and will swallow duplicates.
	// A KVPair with a nil value indicates a delete.  A non nil value indicates an add/modified.
	// The processor may respond with any number of adds or deletes.
	// If the resource cannot be converted then the update processor should treat this as a
	// delete event and return the appropriate delete keys where possible.
	Process(*model.KVPair) ([]*model.KVPair, error)

	// OnSyncerStarting is called when syncer is starting a full sync for the associated resource
	// type.  That means it is first going to list current resources and then watch for any updates.
	// If the processor maintains a private internal cache, then the cache should be cleared at
	// this point since the cache will be re-populated from the sync.
	OnSyncerStarting()
}

SyncerUpdateProcessor is used to convert a Watch update into one or more additional Syncer updates.

Jump to

Keyboard shortcuts

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