providers

package
v0.0.0-...-e7fc6ae Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigMap

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

ConfigMap is an implementation of koanf.Provider that reads/loads configuration from a ConfigMap. ConfigMap is capable of watching the ConfigMap in Kubernetes for changes and notifying via a callback.

func ConfigMapProvider

func ConfigMapProvider(k8sClient *kubernetes.Clientset, cmName, cmNamespace string) *ConfigMap

ConfigMapProvider creates and returns a ConfigFile instance to read and watch a ConfigMap in Kubernetes.

func (*ConfigMap) Close

func (c *ConfigMap) Close()

Close gracefully closes a ConfigMap watch if Watch was called. Otherwise, it is a no-op.

func (*ConfigMap) Read

func (c *ConfigMap) Read() (map[string]interface{}, error)

Read reads the key:value data in a ConfigMap and returns it.

func (*ConfigMap) ReadBytes

func (c *ConfigMap) ReadBytes() ([]byte, error)

ReadBytes is not supported by ConfigMap and will always return an error.

func (*ConfigMap) Watch

func (c *ConfigMap) Watch(cb func(event interface{}, err error)) error

Watch sets up a listener to monitor changes in the ConfigMap and invokes the callback upon add or update events. It ensures the method can only be invoked once and blocks until the cache syncs successfully. Returns an error if the watch activation fails or cache synchronization times out.

type ConfigMapFile

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

ConfigMapFile is an implementation of koanf.Provider that reads/loads a config file stored inside a configmap as a key. ConfigMapFile is capable of watching the ConfigMap in Kubernetes for changes and notifying via a callback.

func ConfigMapFileProvider

func ConfigMapFileProvider(k8sClient *kubernetes.Clientset, cmName, cmNamespace, key string) *ConfigMapFile

ConfigMapFileProvider creates and returns a ConfigMapFile instance to read and watch a ConfigMap in Kubernetes.

func (*ConfigMapFile) Close

func (c *ConfigMapFile) Close()

Close gracefully closes a ConfigMap watch if Watch was called. Otherwise, it is a no-op.

func (*ConfigMapFile) Read

func (c *ConfigMapFile) Read() (map[string]interface{}, error)

Read is not supported by ConfigMapFile and will always return an error.

func (*ConfigMapFile) ReadBytes

func (c *ConfigMapFile) ReadBytes() ([]byte, error)

ReadBytes reads and returns the contents of a configuration file stored in a Kubernetes ConfigMap.

func (*ConfigMapFile) Watch

func (c *ConfigMapFile) Watch(cb func(event interface{}, err error)) error

Watch sets up a listener to monitor changes in the ConfigMap and invokes the callback upon add or update events. It ensures the method can only be invoked once and blocks until the cache syncs successfully. Returns an error if the watch activation fails or cache synchronization times out.

type File

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

File is an implementation of koanf.Provider that reads/loads configuration from a file. File is also capable of watching for changes to the configured file and invoking a callback when changes are detected.

func FileProvider

func FileProvider(path string) *File

FileProvider initializes a new File.

func (*File) Close

func (f *File) Close() error

Close gracefully closes and releases any resources File is using.

func (*File) Read

func (f *File) Read() (map[string]interface{}, error)

Read is not implemented for File and will always return an error

func (*File) ReadBytes

func (f *File) ReadBytes() ([]byte, error)

ReadBytes reads the file and returns the raw bytes.

func (*File) Watch

func (f *File) Watch(cb func(event interface{}, err error)) error

Watch monitors the file for changes and invokes the provided callback when changes are detected.

Watch may only be invoked once per instance of File and providing a nil callback will result in a panic.

type MongoDB

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

MongoDB is an implementation of koanf.Provider that reads/loads configuration stored in a Document in MongoDB.

func MongoDBProvider

func MongoDBProvider(client *mongo.Client, db, collection, docId string) *MongoDB

MongoDBProvider initializes and returns a new MongoDB instance.

func (*MongoDB) Close

func (m *MongoDB) Close() error

Close terminates the MongoDB change stream if active and returns any encountered error during closure.

func (*MongoDB) Read

func (m *MongoDB) Read() (map[string]interface{}, error)

Read is not supported by MongoDB and will always return an error.

func (*MongoDB) ReadBytes

func (m *MongoDB) ReadBytes() ([]byte, error)

ReadBytes reads a MongoDB document and returns the data as bytes. The bytes will always be encoded as BSON.

func (*MongoDB) Watch

func (m *MongoDB) Watch(cb func(event interface{}, err error)) error

Watch sets up a change stream to monitor a specific MongoDB document for updates and invokes the callback on changes.

type Redis

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

Redis is an implementation of koanf.Provider that reads/loads configuration stored in Redis as a STRING type. Redis is capable of watching a key in Redis and notifying changes via a callback.

func RedisProvider

func RedisProvider(client *redis.Client, key string) *Redis

RedisProvider initializes and returns a new instance if Redis.

func (*Redis) Close

func (r *Redis) Close() error

Close cleans up any resources and stops the watch if one was active.

func (*Redis) Read

func (r *Redis) Read() (map[string]interface{}, error)

Read is not supported by Redis and will always return an error.

func (*Redis) ReadBytes

func (r *Redis) ReadBytes() ([]byte, error)

ReadBytes retrieves the configuration from Redis for the configured key.

func (*Redis) Watch

func (r *Redis) Watch(cb func(event interface{}, err error)) error

Watch utilizes Redis keyspace events to detect when a key has been modified and invokes the callback.

Since Watch relies on Redis keyspace events ensure it is enabled in the Redis or Watch will not behave as expected.

Directories

Path Synopsis
file module
kubernetes module

Jump to

Keyboard shortcuts

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