configmap

package
v0.0.0-...-42d1b00 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package configmap exists to facilitate consuming Kubernetes ConfigMap resources in various ways, including:

  • Watching them for changes over time, and
  • Loading them from a VolumeMount.

Index

Constants

View Source
const ExampleKey = "_example"

ExampleKey signifies a given example configuration in a ConfigMap.

Variables

This section is empty.

Functions

func FilterConfigByLabelExists

func FilterConfigByLabelExists(labelKey string) (*labels.Requirement, error)

FilterConfigByLabelExists returns an "exists" label requirement for the given label key.

func Load

func Load(p string) (map[string]string, error)

Load reads the "Data" of a ConfigMap from a particular VolumeMount.

func TypeFilter

func TypeFilter(ts ...interface{}) func(func(string, interface{})) func(string, interface{})

TypeFilter accepts instances of types to check against and returns a function transformer that would only let the call to f through if value is assignable to any one of types of ts. Example:

F := configmap.TypeFilter(&config.Domain{})(f)

The result is a function F(name string, value interface{}) that will call the underlying function f(name, value) iff value is a *config.Domain

func ValidateConstructor

func ValidateConstructor(constructor interface{}) error

ValidateConstructor checks the type of the constructor it evaluates the constructor to be a function with correct signature.

The expectation is for the constructor to receive a single input parameter of type corev1.ConfigMap as the input and return two values with the second value being of type error

Types

type Constructors

type Constructors map[string]interface{}

Constructors is a map for specifying config names to their function constructors

The values of this map must be functions with the definition

func(*k8s.io/api/core/v1.ConfigMap) (... , error)

These functions can return any type along with an error

type DefaultingWatcher

type DefaultingWatcher interface {
	Watcher

	// WatchWithDefault is called to register callbacks to be notified when a named ConfigMap
	// changes. The provided default value is always observed before any real ConfigMap with that
	// name is. If the real ConfigMap with that name is deleted, then the default value is observed.
	WatchWithDefault(cm corev1.ConfigMap, o ...Observer)
}

DefaultingWatcher is similar to Watcher, but if a ConfigMap is absent, then a code provided default will be used.

type InformedWatcher

type InformedWatcher struct {

	// Embedding this struct allows us to reuse the logic
	// of registering and notifying observers. This simplifies the
	// InformedWatcher to just setting up the Kubernetes informer.
	ManualWatcher
	// contains filtered or unexported fields
}

InformedWatcher provides an informer-based implementation of Watcher.

func NewDefaultWatcher deprecated

func NewDefaultWatcher(kc kubernetes.Interface, namespace string) *InformedWatcher

NewDefaultWatcher creates a new default configmap.Watcher instance.

Deprecated: Use NewInformedWatcher

func NewInformedWatcher

func NewInformedWatcher(kc kubernetes.Interface, namespace string, lr ...labels.Requirement) *InformedWatcher

NewInformedWatcher watches a Kubernetes namespace for ConfigMap changes. Optional label requirements allow restricting the list of ConfigMap objects that is tracked by the underlying Informer.

func NewInformedWatcherFromFactory

func NewInformedWatcherFromFactory(sif informers.SharedInformerFactory, namespace string) *InformedWatcher

NewInformedWatcherFromFactory watches a Kubernetes namespace for ConfigMap changes.

func (*InformedWatcher) Start

func (i *InformedWatcher) Start(stopCh <-chan struct{}) error

Start implements Watcher.

func (*InformedWatcher) WatchWithDefault

func (i *InformedWatcher) WatchWithDefault(cm corev1.ConfigMap, o ...Observer)

WatchWithDefault implements DefaultingWatcher.

type Logger

type Logger interface {
	Infof(string, ...interface{})
	Fatalf(string, ...interface{})
	Errorf(string, ...interface{})
}

Logger is the interface that UntypedStore expects its logger to conform to. UntypedStore will log when updates succeed or fail.

type ManualWatcher

type ManualWatcher struct {
	Namespace string
	// contains filtered or unexported fields
}

ManualWatcher will notify Observers when a ConfigMap is manually reported as changed

func (*ManualWatcher) OnChange

func (w *ManualWatcher) OnChange(configMap *corev1.ConfigMap)

OnChange invokes the callbacks of all observers of the given ConfigMap.

func (*ManualWatcher) Start

func (w *ManualWatcher) Start(<-chan struct{}) error

Start implements Watcher

func (*ManualWatcher) Watch

func (w *ManualWatcher) Watch(name string, o ...Observer)

Watch implements Watcher

type Observer

type Observer func(*corev1.ConfigMap)

Observer is the signature of the callbacks that notify an observer of the latest state of a particular configuration. An observer should not modify the provided ConfigMap, and should `.DeepCopy()` it for persistence (or otherwise process its contents).

type StaticWatcher

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

StaticWatcher is a Watcher with static ConfigMaps. Callbacks will occur when Watch is invoked for a specific Observer

func NewStaticWatcher

func NewStaticWatcher(cms ...*corev1.ConfigMap) *StaticWatcher

NewStaticWatcher returns an StaticWatcher that exposes a collection of ConfigMaps.

func (*StaticWatcher) Start

func (di *StaticWatcher) Start(<-chan struct{}) error

Start implements Watcher

func (*StaticWatcher) Watch

func (di *StaticWatcher) Watch(name string, o ...Observer)

Watch implements Watcher

type UntypedStore

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

An UntypedStore is a responsible for storing and constructing configs from Kubernetes ConfigMaps

WatchConfigs should be used with a configmap.Watcher in order for this store to remain up to date

func NewUntypedStore

func NewUntypedStore(
	name string,
	logger Logger,
	constructors Constructors,
	onAfterStore ...func(name string, value interface{})) *UntypedStore

NewUntypedStore creates an UntypedStore with given name, Logger and Constructors

The Logger must not be nil

The values in the Constructors map must be functions with the definition

func(*k8s.io/api/core/v1.ConfigMap) (... , error)

These functions can return any type along with an error. If the function definition differs then NewUntypedStore will panic.

onAfterStore is a variadic list of callbacks to run after the ConfigMap has been transformed (via the appropriate Constructor) and stored. These callbacks run sequentially (in the argument order) in a separate go-routine and are of type func(name string, value interface{}) where name is the config-map name and value is the object that has been constructed from the config-map and stored.

func (*UntypedStore) OnConfigChanged

func (s *UntypedStore) OnConfigChanged(c *corev1.ConfigMap)

OnConfigChanged will invoke the mapped constructor against a Kubernetes ConfigMap. If successful it will be stored. If construction fails during the first appearance the store will log a fatal error. If construction fails while updating the store will log an error message.

func (*UntypedStore) UntypedLoad

func (s *UntypedStore) UntypedLoad(name string) interface{}

UntypedLoad will return the constructed value for a given ConfigMap name

func (*UntypedStore) WatchConfigs

func (s *UntypedStore) WatchConfigs(w Watcher)

WatchConfigs uses the provided configmap.Watcher to setup watches for the config names provided in the Constructors map

type Watcher

type Watcher interface {
	// Watch is called to register callbacks to be notified when a named ConfigMap changes.
	Watch(string, ...Observer)

	// Start is called to initiate the watches and provide a channel to signal when we should
	// stop watching.  When Start returns, all registered Observers will be called with the
	// initial state of the ConfigMaps they are watching.
	Start(<-chan struct{}) error
}

Watcher defines the interface that a configmap implementation must implement.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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