labels

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: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	POD  = Type("pod")
	NODE = Type("node")
	PC   = Type("pod_clusters")
	RC   = Type("replication_controller")
	RU   = Type("rolls")
)

These types (with the exception of RC) are named such that the path to an objects labels is the same as the path to the object but with labelRoot prepended. Example: the labels for /intent/foo.com/slug are at /labels/intent/foo.com/slug. Note: the tree name for RCs is pluralized, while the label is not, so this doesn't hold true for RCs

Variables

View Source
var DefaultAggregationRate = 10 * time.Second

minimum required time between retrievals of label subtrees.

View Source
var InvalidType error = errors.New("Invalid type provided")
View Source
var NoLabelsFound = errors.New("No labels found")

NoLabelsFound represents a 404 error from consul. In most cases the results should be ignored if this error is encountered because under normal operation there should always be labels for most types such as replication controllers. Resources that trend to zero such as rolling updates are an example of a case where this error might be expected under normal operation. The client must know the safety and likelihood of missing labels and decide what to do based on that information.

Functions

func IsNoLabelsFound

func IsNoLabelsFound(err error) bool

func MakePodLabelKey

func MakePodLabelKey(node types.NodeName, podID types.PodID) string

these utility functions are used primarily while we exist in a mutable deployment world. We will need to figure out how to replace these with different datasources to allow RCs and DSs to continue to function correctly in the future.

func NewConsulAggregator

func NewConsulAggregator(
	labelType Type,
	kv consulutil.ConsulLister,
	logger logging.Logger,
	metReg MetricsRegistry,
	aggregationRate time.Duration,
) *consulAggregator

func NewFakeApplicator

func NewFakeApplicator() *fakeApplicator

func NewHTTPApplicator

func NewHTTPApplicator(client *http.Client, matchesEndpoint *url.URL) (*httpApplicator, error)

func NewHTTPLabelServer

func NewHTTPLabelServer(applicator ApplicatorWithoutWatches, batchTime time.Duration, logger logging.Logger) *labelHTTPServer

Construct a new HTTP Applicator server. If batchTime is non-zero, use batching for handling requests that operate over an entire label type (select, list).

func NodeAndPodIDFromPodLabel

func NodeAndPodIDFromPodLabel(labeled Labeled) (types.NodeName, types.PodID, error)

func Nothing

func Nothing() labels.Selector

Nothing returns a selector that cannot match any labels. It is different from klabels.Nothing() in that it can be serialzed as a string and re- parsed as a selector while being in the grammar for selectors.

Types

type Applicator

type Applicator interface {
	// Assign a label to the object identified by the Type and ID
	SetLabel(labelType Type, id, name, value string) error

	// Assign a group of labels in a batched operation
	SetLabels(labelType Type, id string, labels map[string]string) error

	// Remove a label from the identified object
	RemoveLabel(labelType Type, id, name string) error

	// Remove all labels from the identified object
	RemoveAllLabels(labelType Type, id string) error

	// Lists all labels on all objects associated with this type.
	// mostly useful for secondary caching. Do not use directly
	// if you just want to answer a simple query - use GetMatches
	// instead.
	ListLabels(labelType Type) ([]Labeled, error)

	// Get all Labels assigned to the given object
	GetLabels(labelType Type, id string) (Labeled, error)

	// Return all objects of the given type that match the given selector.
	GetMatches(selector labels.Selector, labelType Type) ([]Labeled, error)

	// Return all objects of the given type that match the given selector
	// out of a cache that is refreshed at a rate according to
	// aggregationRate
	GetCachedMatches(selector labels.Selector, labelType Type, aggregationRate time.Duration) ([]Labeled, error)

	// Watch a label selector of a given type and see updates to that set
	// of Labeled over time. If an error occurs, the Applicator implementation
	// is responsible for handling it and recovering gracefully.
	//
	// The watch may be terminated by the underlying implementation without signaling on
	// the quit channel - this will be indicated by the closing of the result channel. For
	// this reason, callers should **always** verify that the channel is closed by checking
	// the "ok" boolean or using `range`.
	WatchMatches(
		selector labels.Selector,
		labelType Type,
		aggregationRate time.Duration,
		quitCh <-chan struct{},
	) (chan []Labeled, error)

	// WatchMatchDiff does a diff on top of the results form the WatchMatches and
	// returns a LabeledChanges structure which contain changes
	WatchMatchDiff(
		selector labels.Selector,
		labelType Type,
		aggregationRate time.Duration,
		quitCh <-chan struct{},
	) <-chan *LabeledChanges
}

General purpose backing store for labels and assignment to P2 objects

type ApplicatorWithoutWatches

type ApplicatorWithoutWatches interface {
	SetLabel(labelType Type, id, name, value string) error
	SetLabels(labelType Type, id string, labels map[string]string) error
	SetLabelsTxn(ctx context.Context, labelType Type, id string, labels map[string]string) error
	RemoveLabel(labelType Type, id, name string) error
	RemoveLabelTxn(ctx context.Context, labelType Type, id, name string) error
	RemoveAllLabels(labelType Type, id string) error
	RemoveLabelsTxn(ctx context.Context, labelType Type, id string, keysToRemove []string) error
	RemoveAllLabelsTxn(ctx context.Context, labelType Type, id string) error
	ListLabels(labelType Type) ([]Labeled, error)
	GetLabels(labelType Type, id string) (Labeled, error)
	GetMatches(selector klabels.Selector, labelType Type) ([]Labeled, error)
	GetCachedMatches(selector klabels.Selector, labelType Type, aggregationRate time.Duration) ([]Labeled, error)
	GetLabelsWithIndex(labelType Type, id string) (Labeled, uint64, error)
}

General purpose backing store for labels and assignment to P2 objects. This is a subset of the labels.Applicator that omits the Watch functions

type Batcher

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

func NewBatcher

func NewBatcher(lister labelLister, holdTime time.Duration) Batcher

func (*Batcher) ForType

func (b *Batcher) ForType(labelType Type) *TypeBatcher

type CASError

type CASError struct {
	Key string
}

func (CASError) Error

func (e CASError) Error() string

type ConsulApplicator

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

func NewConsulApplicator

func NewConsulApplicator(client consulutil.ConsulClient, retries int, watchJitterWindow time.Duration) *ConsulApplicator

func (*ConsulApplicator) GetCachedMatches

func (c *ConsulApplicator) GetCachedMatches(selector labels.Selector, labelType Type, aggregationRate time.Duration) ([]Labeled, error)

func (*ConsulApplicator) GetLabels

func (c *ConsulApplicator) GetLabels(labelType Type, id string) (Labeled, error)

func (*ConsulApplicator) GetLabelsWithIndex

func (c *ConsulApplicator) GetLabelsWithIndex(labelType Type, id string) (Labeled, uint64, error)

func (*ConsulApplicator) GetMatches

func (c *ConsulApplicator) GetMatches(selector labels.Selector, labelType Type) ([]Labeled, error)

func (*ConsulApplicator) ListLabels

func (c *ConsulApplicator) ListLabels(labelType Type) ([]Labeled, error)

func (*ConsulApplicator) RemoveAllLabels

func (c *ConsulApplicator) RemoveAllLabels(labelType Type, id string) error

func (*ConsulApplicator) RemoveAllLabelsTxn

func (c *ConsulApplicator) RemoveAllLabelsTxn(ctx context.Context, labelType Type, id string) error

RemoveAllLabelsTxn is the same as RemoveAllLabels but adds the operation to the passed transaction rather than synchronously making the requisite consul call

func (*ConsulApplicator) RemoveLabel

func (c *ConsulApplicator) RemoveLabel(labelType Type, id, label string) error

func (*ConsulApplicator) RemoveLabelTxn

func (c *ConsulApplicator) RemoveLabelTxn(ctx context.Context, labelType Type, id, label string) error

func (*ConsulApplicator) RemoveLabelsTxn

func (c *ConsulApplicator) RemoveLabelsTxn(ctx context.Context, labelType Type, id string, keysToRemove []string) error

func (*ConsulApplicator) SetLabel

func (c *ConsulApplicator) SetLabel(labelType Type, id, label, value string) error

func (*ConsulApplicator) SetLabelTxn

func (c *ConsulApplicator) SetLabelTxn(ctx context.Context, labelType Type, id, label, value string) error

func (*ConsulApplicator) SetLabels

func (c *ConsulApplicator) SetLabels(labelType Type, id string, labels map[string]string) error

func (*ConsulApplicator) SetLabelsTxn

func (c *ConsulApplicator) SetLabelsTxn(ctx context.Context, labelType Type, id string, labels map[string]string) error

TODO: replace SetLabels() with this implementation. It's just separate right now to make exploring solutions require less code churn

func (*ConsulApplicator) SetMetricsRegistry

func (c *ConsulApplicator) SetMetricsRegistry(metReg MetricsRegistry)

func (*ConsulApplicator) WatchMatchDiff

func (c *ConsulApplicator) WatchMatchDiff(
	selector labels.Selector,
	labelType Type,
	aggregationRate time.Duration,
	quitCh <-chan struct{},
) <-chan *LabeledChanges

func (*ConsulApplicator) WatchMatches

func (c *ConsulApplicator) WatchMatches(selector labels.Selector, labelType Type, aggregationRate time.Duration, quitCh <-chan struct{}) (chan []Labeled, error)

The current schema of labels in Consul is optimized for label retrieval on a single object of a given ID. This layout is less effective when attempting to perform a watch on the results of an arbitrary label selector, which is necessarily un-indexable. This implementation will perform the simplest possible optimization, which is to cache the entire contents of the tree under the given label type and share it with other watches.

Due to the possibility that this tree might change quite frequently in environments with lots of concurrent deployments, the aggregated result from Consul will only be queried by a maximum frequency of once per LabelAggregationCap.

Preparers should not use the consulApplicator's implementation of WatchMatches directly due to the cost of querying for this subtree on any sizeable fleet of machines. Instead, preparers should use the httpApplicator from a server that exposes the results of this (or another) implementation's watch.

type LabelFetcher

type LabelFetcher interface {
	GetLabelsWithIndex(labelType Type, id string) (Labeled, uint64, error)
}

type Labeled

type Labeled struct {
	LabelType Type       `json:"type"`
	ID        string     `json:"id"`
	Labels    labels.Set `json:"labels"`
}

func (Labeled) SameAs

func (l Labeled) SameAs(o Labeled) bool

type LabeledChanges

type LabeledChanges struct {
	Created []Labeled
	Updated []Labeled
	Deleted []Labeled
}

type LabeledWithIndex

type LabeledWithIndex struct {
	Labeled
	Index uint64 `json:"index"`
}

type MetricsRegistry

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

type SetLabelRequest

type SetLabelRequest struct {
	Value string `json:"value"`
}

type SetLabelsRequest

type SetLabelsRequest struct {
	Values map[string]string `json:"values"`
}

type Type

type Type string

the type of the object being labeled.

func AsType

func AsType(v string) (Type, error)

func (Type) String

func (l Type) String() string

type TypeBatcher

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

Batches a single label type

func (*TypeBatcher) Retrieve

func (b *TypeBatcher) Retrieve() ([]Labeled, error)

Jump to

Keyboard shortcuts

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