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
- func Checksum(value string) string
- func Load(p string) (map[string]string, error)
- func Parse(data map[string]string, parsers ...ParseFunc) error
- func TypeFilter(ts ...interface{}) func(func(string, interface{})) func(string, interface{})
- func ValidateConstructor(constructor interface{}) error
- type Constructors
- type DefaultingWatcher
- type Logger
- type ManualWatcher
- type Observer
- type ParseFunc
- func AsBool(key string, target *bool) ParseFunc
- func AsDuration(key string, target *time.Duration) ParseFunc
- func AsFloat64(key string, target *float64) ParseFunc
- func AsInt(key string, target *int) ParseFunc
- func AsInt16(key string, target *int16) ParseFunc
- func AsInt32(key string, target *int32) ParseFunc
- func AsInt64(key string, target *int64) ParseFunc
- func AsNamespacedName(key string, target *types.NamespacedName) ParseFunc
- func AsOptionalNamespacedName(key string, target **types.NamespacedName) ParseFunc
- func AsQuantity(key string, target **resource.Quantity) ParseFunc
- func AsString(key string, target *string) ParseFunc
- func AsStringSet(key string, target *sets.Set[string]) ParseFunc
- func AsUint16(key string, target *uint16) ParseFunc
- func AsUint32(key string, target *uint32) ParseFunc
- func CollectMapEntriesWithPrefix(prefix string, target *map[string]string) ParseFunc
- type StaticWatcher
- type UntypedStore
- type Watcher
Constants ¶
const ( // ExampleKey signifies a given example configuration in a ConfigMap. ExampleKey = "_example" // ExampleChecksumAnnotation is the annotation that stores the computed checksum. ExampleChecksumAnnotation = "knative.dev/example-checksum" )
Variables ¶
This section is empty.
Functions ¶
func Checksum ¶
Checksum generates a checksum for the example value to be compared against a respective annotation. Leading and trailing spaces are ignored.
func TypeFilter ¶
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 configmap 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 Logger ¶
type Logger interface { Debugf(string, ...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 // Guards observers sync.RWMutex // contains filtered or unexported fields }
ManualWatcher will notify Observers when a ConfigMap is manually reported as changed
func (*ManualWatcher) ForEach ¶
func (w *ManualWatcher) ForEach(f func(string, []Observer) error) error
ForEach implements Watcher
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 ¶
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 ParseFunc ¶
ParseFunc is a function taking ConfigMap data and applying a parse operation to it.
func AsDuration ¶
AsDuration parses the value at key as a time.Duration into the target, if it exists.
func AsNamespacedName ¶
func AsNamespacedName(key string, target *types.NamespacedName) ParseFunc
AsNamespacedName parses the value at key as a types.NamespacedName into the target, if it exists The namespace and name are both required and expected to be valid DNS labels
func AsOptionalNamespacedName ¶
func AsOptionalNamespacedName(key string, target **types.NamespacedName) ParseFunc
AsOptionalNamespacedName parses the value at key as a types.NamespacedName into the target, if it exists The namespace and name are both required and expected to be valid DNS labels
func AsQuantity ¶
AsQuantity parses the value at key as a *resource.Quantity into the target, if it exists
func AsStringSet ¶
AsStringSet parses the value at key as a sets.Set[string] (split by ',') into the target, if it exists.
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.