config

package
Version: v0.0.0-...-062eff5 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// IstioAPIGroup defines API group name for Istio configuration resources
	IstioAPIGroup = "broker.istio.io"

	// IstioAPIVersion defines API group version
	IstioAPIVersion = "dev"
)

Variables

View Source
var (
	// ServiceClass describes service class
	ServiceClass = Schema{
		Type:        "service-class",
		Plural:      "service-classes",
		MessageName: "istio.broker.dev.ServiceClass",
	}

	// ServicePlan describes service plan
	ServicePlan = Schema{
		Type:        "service-plan",
		Plural:      "service-plans",
		MessageName: "istio.broker.dev.ServicePlan",
	}

	// BrokerConfigTypes lists all types with schemas and validation
	BrokerConfigTypes = Descriptor{
		ServiceClass,
		ServicePlan,
	}
)

Functions

func Key

func Key(typ, name, namespace string) string

Key function for the configuration objects

Types

type BrokerConfigStore

type BrokerConfigStore interface {
	// ServiceClasses lists all service classes.
	ServiceClasses() map[string]*brokerconfig.ServiceClass

	// ServicePlans lists all service plans.
	ServicePlans() map[string]*brokerconfig.ServicePlan

	// ServicePlansByService lists all service plans contains the specified service class
	ServicePlansByService(service string) map[string]*brokerconfig.ServicePlan
}

BrokerConfigStore is a specialized interface to access config store using Broker configuration types.

func MakeBrokerConfigStore

func MakeBrokerConfigStore(store Store) BrokerConfigStore

MakeBrokerConfigStore creates a wrapper around a store

type Descriptor

type Descriptor []Schema

Descriptor defines a group of config types.

func (Descriptor) FromJSON

func (d Descriptor) FromJSON(json JSONConfig) (*Entry, error)

FromJSON deserializes and validates a JSON config object

func (Descriptor) FromYAML

func (d Descriptor) FromYAML(content []byte) (*Entry, error)

FromYAML deserializes and validates a YAML config object

func (Descriptor) GetByMessageName

func (d Descriptor) GetByMessageName(name string) (Schema, bool)

GetByMessageName finds a schema by message name if it is available

func (Descriptor) GetByType

func (d Descriptor) GetByType(name string) (Schema, bool)

GetByType finds a schema by type if it is available

func (Descriptor) ToYAML

func (d Descriptor) ToYAML(entry Entry) (string, error)

ToYAML serializes a config into a YAML form

func (Descriptor) Types

func (d Descriptor) Types() []string

Types lists all known types in the config schema

type Entry

type Entry struct {
	Meta

	// Spec holds the configuration object as a protobuf message
	Spec proto.Message
}

Entry is a configuration unit consisting of the type of configuration, the key identifier that is unique per type, and the content represented as a protobuf message.

func (*Entry) Key

func (entry *Entry) Key() string

Key is the unique identifier for a configuration object

type JSONConfig

type JSONConfig struct {
	Meta

	// Spec is the content of the config
	Spec interface{} `json:"spec,omitempty"`
}

JSONConfig is the JSON serialized form of the config unit

type Meta

type Meta struct {
	// Type is a short configuration name that matches the content message type
	// (e.g. "route-rule")
	Type string `json:"type,omitempty"`

	// Name is a unique immutable identifier in a namespace
	Name string `json:"name,omitempty"`

	// Namespace defines the space for names (optional for some types),
	// applications may choose to use namespaces for a variety of purposes
	// (security domains, fault domains, organizational domains)
	Namespace string `json:"namespace,omitempty"`

	// Namespace where istio control plane is installed
	IstioNamespace string `json:"istioNamespace,omitempty"`

	// Map of string keys and values that can be used to organize and categorize
	// (scope and select) objects.
	Labels map[string]string `json:"labels,omitempty"`

	// Annotations is an unstructured key value map stored with a resource that may be
	// set by external tools to store and retrieve arbitrary metadata. They are not
	// queryable and should be preserved when modifying objects.
	Annotations map[string]string `json:"annotations,omitempty"`

	// ResourceVersion is an opaque identifier for tracking updates to the config registry.
	// The implementation may use a change index or a commit log for the revision.
	// The config client should not make any assumptions about revisions and rely only on
	// exact equality to implement optimistic concurrency of read-write operations.
	//
	// The lifetime of an object of a particular revision depends on the underlying data store.
	// The data store may compactify old revisions in the interest of storage optimization.
	//
	// An empty revision carries a special meaning that the associated object has
	// not been stored and assigned a revision.
	ResourceVersion string `json:"resourceVersion,omitempty"`
}

Meta is metadata attached to each configuration unit. The revision is optional, and if provided, identifies the last update operation on the object.

type Schema

type Schema struct {
	// Type refers to the short configuration type name
	Type string

	// Plural refers to the short plural configuration name
	Plural string

	// MessageName refers to the protobuf message type name corresponding to the type
	MessageName string

	// AdditionalValidate the protobuf message for this type. This is called within schema.Validate()
	// This can be nil.
	AdditionalValidate func(config proto.Message) error
}

Schema provides description of the configuration schema and its key function

func (*Schema) FromJSONMap

func (b *Schema) FromJSONMap(data interface{}) (proto.Message, error)

FromJSONMap converts from a generic map to a proto message using canonical JSON encoding JSON encoding is specified here: https://developers.google.com/protocol-buffers/docs/proto3#json

func (*Schema) ToJSONMap

func (b *Schema) ToJSONMap(msg proto.Message) (map[string]interface{}, error)

ToJSONMap converts a proto message to a generic map using canonical JSON encoding JSON encoding is specified here: https://developers.google.com/protocol-buffers/docs/proto3#json

func (*Schema) Validate

func (b *Schema) Validate(config proto.Message) error

Validate the basic config. Invokes AdditionalValidate() if set.

type Store

type Store interface {
	// ConfigDescriptor exposes the configuration type schema known by the config store.
	// The type schema defines the bidrectional mapping between configuration
	// types and the protobuf encoding schema.
	Descriptor() Descriptor

	// Get retrieves a configuration element by a type and a key
	Get(typ, name, namespace string) (entry *Entry, exists bool)

	// List returns objects by type and namespace.
	// Use "" for the namespace to list across namespaces.
	List(typ, namespace string) ([]Entry, error)

	// Create adds a new configuration object to the store. If an object with the
	// same name and namespace for the type already exists, the operation fails
	// with no side effects.
	Create(entry Entry) (revision string, err error)

	// Update modifies an existing configuration object in the store.  Update
	// requires that the object has been created.  Resource version prevents
	// overriding a value that has been changed between prior _Get_ and _Put_
	// operation to achieve optimistic concurrency. This method returns a new
	// revision if the operation succeeds.
	Update(entry Entry) (newRevision string, err error)

	// Delete removes an object from the store by key
	Delete(typ, name, namespace string) error
}

Store describes a set of platform agnostic APIs that must be supported by the underlying platform to store and retrieve Istio configuration.

Configuration key is defined to be a combination of the type, name, and namespace of the configuration object. The configuration key is guaranteed to be unique in the store.

The storage interface presented here assumes that the underlying storage layer supports _Get_ (list), _Update_ (update), _Create_ (create) and _Delete_ semantics but does not guarantee any transactional semantics.

_Update_, _Create_, and _Delete_ are mutator operations. These operations are asynchronous, and you might not see the effect immediately (e.g. _Get_ might not return the object by key immediately after you mutate the store.) Intermittent errors might occur even though the operation succeeds, so you should always check if the object store has been modified even if the mutating operation returns an error. Objects should be created with _Create_ operation and updated with _Update_ operation.

Resource versions record the last mutation operation on each object. If a mutation is applied to a different revision of an object than what the underlying storage expects as defined by pure equality, the operation is blocked. The client of this interface should not make assumptions about the structure or ordering of the revision identifier.

Object references supplied and returned from this interface should be treated as read-only. Modifying them violates thread-safety.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL