store

package
v0.0.0-...-1a56975 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// example fs:///tmp/testdata/configroot
	FSUrl = "fs"
)

URL types supported by the config store

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is the error to be returned when the given key does not exist in the storage.

View Source
var ErrWatchAlreadyExists = errors.New("watch already exists")

ErrWatchAlreadyExists is the error to report that the watching channel already exists.

Functions

func StartWatch

func StartWatch(s Store) (map[Key]*Resource, <-chan Event, error)

StartWatch registers with store, initiates a watch, and returns the current config state.

func WatchChanges

func WatchChanges(wch <-chan Event, stop <-chan struct{}, watchFlushDuration time.Duration, applyEvents ApplyEventsFn)

WatchChanges watches for changes on a channel and publishes a batch of changes via applyEvents. WatchChanges is started in a goroutine.

Types

type ApplyEventsFn

type ApplyEventsFn func(events []*Event)

ApplyEventsFn is used for testing

type BackEndResource

type BackEndResource struct {
	Kind     string
	Metadata ResourceMeta
	Spec     map[string]interface{}
}

BackEndResource represents a resources with a raw spec

func ParseChunk

func ParseChunk(chunk []byte) (*BackEndResource, error)

ParseChunk parses a YAML formatted bytes into a BackEndResource.

func (*BackEndResource) Key

func (ber *BackEndResource) Key() Key

Key returns the key of the resource in the store.

type Backend

type Backend interface {
	Init(kinds []string) error

	Stop()

	// WaitForSynced blocks and awaits for the caches to be fully populated until timeout.
	WaitForSynced(time.Duration) error

	// Watch creates a channel to receive the events.
	Watch() (<-chan BackendEvent, error)

	// Get returns a resource's spec to the key.
	Get(key Key) (*BackEndResource, error)

	// List returns the whole mapping from key to resource specs in the store.
	List() map[Key]*BackEndResource
}

Backend defines the typeless storage backend for mixer.

type BackendEvent

type BackendEvent struct {
	Key
	Type  ChangeType
	Value *BackEndResource
}

BackendEvent is an event used between Backend and Store.

type BackendValidator

type BackendValidator interface {
	Validate(ev *BackendEvent) error
}

BackendValidator defines the interface to validte unstructured event.

func NewValidator

func NewValidator(ev Validator, kinds map[string]proto.Message) BackendValidator

NewValidator creates a default validator which validates the structure through registered kinds and referential integrity through ev.

type Builder

type Builder func(u *url.URL, gv *schema.GroupVersion, credOptions *creds.Options, ck []string) (Backend, error)

Builder is the type of function to build a Backend.

type ChangeType

type ChangeType int

ChangeType denotes the type of a change

const (
	// Update - change was an update or a create to a key.
	Update ChangeType = iota
	// Delete - key was removed.
	Delete
)

type Event

type Event struct {
	Key
	Type ChangeType

	// Value refers the new value in the updated event. nil if the event type is delete.
	Value *Resource
}

Event represents an event. Used by Store.Watch.

type Key

type Key struct {
	Kind      string
	Namespace string
	Name      string
}

Key represents the key to identify a resource in the store.

func (Key) String

func (k Key) String() string

String is the Istio compatible string representation of the resource. Name.Kind.Namespace At the point of use Namespace can be omitted, and it is assumed to be the namespace of the document.

type RegisterFunc

type RegisterFunc func(map[string]Builder)

RegisterFunc is the type to register a builder for URL scheme.

type Registry

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

Registry keeps the relationship between the URL scheme and the Backend implementation.

func NewRegistry

func NewRegistry(inventory ...RegisterFunc) *Registry

NewRegistry creates a new Registry instance for the inventory.

func (*Registry) NewStore

func (r *Registry) NewStore(
	configURL string,
	groupVersion *schema.GroupVersion,
	credOptions *creds.Options,
	criticalKinds []string) (Store, error)

NewStore creates a new Store instance with the specified backend.

type Resource

type Resource struct {
	Metadata ResourceMeta
	Spec     proto.Message
}

Resource represents a resources with converted spec.

type ResourceMeta

type ResourceMeta struct {
	Name        string
	Namespace   string
	Labels      map[string]string
	Annotations map[string]string
	Revision    string
}

ResourceMeta is the standard metadata associated with a resource.

type Store

type Store interface {
	Init(kinds map[string]proto.Message) error

	Stop()

	// WaitForSynced blocks and awaits for the caches to be fully populated until timeout.
	WaitForSynced(time.Duration) error

	// Watch creates a channel to receive the events. A store can conduct a single
	// watch channel at the same time. Multiple calls lead to an error.
	Watch() (<-chan Event, error)

	// Get returns the resource to the key.
	Get(key Key) (*Resource, error)

	// List returns the whole mapping from key to resource specs in the store.
	List() map[Key]*Resource

	probe.SupportsProbe
}

Store defines the access to the storage for mixer.

func WithBackend

func WithBackend(b Backend) Store

WithBackend creates a new Store with a certain backend. This should be used only by tests.

type Validator

type Validator interface {
	Validate(ev *Event) error
}

Validator defines the interface to validate a new change.

Jump to

Keyboard shortcuts

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