pcstore

package
v0.0.0-...-8223eb1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NoPodCluster            error = errors.New("No pod cluster found")
	PodClusterAlreadyExists error = errors.New("Pod cluster already exists")
)

Functions

func IsAlreadyExists

func IsAlreadyExists(err error) bool

func IsNotExist

func IsNotExist(err error) bool

Types

type ConcreteSyncer

type ConcreteSyncer interface {
	// SyncCluster implements a concrete synchronization of the pod cluster to
	// some real world implementation of a load balancer, credential management
	// system, or service discovery implementation.
	//
	// When a ConcreteSyncer is passed to WatchAndSync, SyncCluster is called
	// every time the set of labeled pods change, the pod cluster's metadata
	// changes, or when the long-lived watch on the pod cluster store returns.
	// This function is expected to be idempotent.
	//
	// SyncCluster will be called for every pod cluster present in the store.
	// If this function returns an error, SyncCluster will be called again later
	// with the same cluster and pods, assuming that no changes occur in the intervening
	// period.
	//
	// ConcreteSyncers will be called concurrently and must operate safely.
	SyncCluster(pc *fields.PodCluster, pods []labels.Labeled) error

	// DeleteCluster is called when a pod cluster is observed to have been removed
	// from the store. DeleteCluster can be invoked in two circumstances: first,
	// if the cluster was present in a first watch, then absent in a subsequent watch,
	// then it is assumed it was deleted from the pcstore. Second, if the call
	// to GetInitialClusters() returns a pod cluster ID that is not present in the very
	// first watch result, DeleteCluster will be invoked with that pod cluster.
	//
	// If the passed ID is used to retrieve the pod cluster via store.Get(), it will
	// return ErrNoPodCluster. Clients should track any relevant metadata to the pod
	// cluster ID in the status store or in vendor-specific code.
	DeleteCluster(pc fields.ID) error

	// GetInitialClusters is called at the beginning of the WatchAndSync
	// routine. See DeleteCluster() for an explanation of how its results are
	// used. If the function results in an error, the WatchAndSync function will
	// terminate immediately, forwarding the error.
	GetInitialClusters() ([]fields.ID, error)

	// Used to derive the syncer type from a syncer instance for things
	// like namespacing of metrics
	Type() ConcreteSyncerType
}

type ConcreteSyncerType

type ConcreteSyncerType string

There may be multiple implementations of ConcreteSyncer that are interested in pod cluster updates, and wish to acquire a pod cluster lock to guarantee exclusive right to sync an update. ConcreteSyncerType is used to namespace a lock by implementation type so that two different concrete syncer implementations may sync the same pod cluster at the same time

func (ConcreteSyncerType) String

func (t ConcreteSyncerType) String() string

type ConsulStore

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

func NewConsul

func NewConsul(
	client consulutil.ConsulClient,
	labeler pcLabeler,
	labelAggregationRate time.Duration,
	watcher pcWatcher,
	logger *logging.Logger,
) *ConsulStore

func (*ConsulStore) Create

func (s *ConsulStore) Create(
	podID types.PodID,
	availabilityZone fields.AvailabilityZone,
	clusterName fields.ClusterName,
	podSelector klabels.Selector,
	annotations fields.Annotations,
	allocationStrategy rc_fields.Strategy,
	minHealthPercentage fields.MinHealthPercentage,
	session Session,
) (fields.PodCluster, error)

func (*ConsulStore) Delete

func (s *ConsulStore) Delete(id fields.ID) error

func (*ConsulStore) FindWhereLabeled

func (s *ConsulStore) FindWhereLabeled(podID types.PodID,
	availabilityZone fields.AvailabilityZone,
	clusterName fields.ClusterName) ([]fields.PodCluster, error)

FindWhereLabeled returns a slice of pod clusters that are labeled with the passed information. Although pod clusters should always be unique for this 3-ple, this method will return a slice in cases where duplicates are discovered. It is up to clients to decide how to respond to such situations.

func (*ConsulStore) Get

func (s *ConsulStore) Get(id fields.ID) (fields.PodCluster, error)

func (*ConsulStore) List

func (s *ConsulStore) List() ([]fields.PodCluster, error)

func (*ConsulStore) LockForSync

func (s *ConsulStore) LockForSync(id fields.ID, syncerType ConcreteSyncerType, session Session) (consul.Unlocker, error)

func (*ConsulStore) MutatePC

func (s *ConsulStore) MutatePC(
	id fields.ID,
	mutator func(fields.PodCluster) (fields.PodCluster, error),
) (fields.PodCluster, error)

performs a safe (ie check-and-set) mutation of the pc with the given id, using the given function if the mutator returns an error, it will be propagated out if the returned PC has id="", then it will be deleted

func (*ConsulStore) SetMetricsRegistry

func (s *ConsulStore) SetMetricsRegistry(reg MetricsRegistry)

func (*ConsulStore) Watch

func (s *ConsulStore) Watch(quit <-chan struct{}) <-chan WatchedPodClusters

Watch watches the entire podClusterTree for changes. It will return a blocking channel on which the client can read WatchedPodCluster objects. The goroutine maintaining the watch will block on writing to this channel so it's up to the caller to read it with haste.

func (*ConsulStore) WatchAndSync

func (s *ConsulStore) WatchAndSync(syncer ConcreteSyncer, quit <-chan struct{}) error

WatchAndSync registers a ConcreteSyncer which will have its functions invoked on certain pod cluster changes. See the ConcreteSyncer interface for details on how to use this function

func (*ConsulStore) WatchPodCluster

func (s *ConsulStore) WatchPodCluster(id fields.ID, quit <-chan struct{}) <-chan WatchedPodCluster

WatchPodCluster implements a watch for the Pod cluster at _id_ It will return a blocking channel on which the client can read WatchedPodCluster objects. The goroutine maintaining the watch will block on writing to this channel so it's up to the caller to read it with haste. This function will return ErrNoPodCluster if the podCluster goes away. In this case, the caller should close the quit chan. The caller may shutdown this watch by sending a sentinel on the quitChan.

type MetricsRegistry

type MetricsRegistry interface {
	Get(metricName string) interface{}
	Register(metricName string, metric interface{}) error
}

Subset of metrics.Registry interface

type Session

type Session interface {
	Lock(key string) (consul.Unlocker, error)
}

type WatchedPodCluster

type WatchedPodCluster struct {
	PodCluster *fields.PodCluster
	Err        error
}

WatchedPodCluster is an Either type: it will have 1 one of pc xor err

type WatchedPodClusters

type WatchedPodClusters struct {
	Clusters []*fields.PodCluster
	Err      error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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