config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const EnvClusterIdentifier = "SPOTINST_CLUSTER_IDENTIFIER"

EnvClusterIdentifier specifies the name of the environment variable points to cluster identifier.

Variables

View Source
var ErrNoValidProvidersFoundInChain = errors.New("config: no valid " +
	"configuration providers in chain")

ErrNoValidProvidersFoundInChain Is returned when there are no valid configuration providers in the ChainProvider.

Functions

This section is empty.

Types

type ChainProvider

type ChainProvider struct {
	Providers []Provider
}

ChainProvider will search for a provider which returns configuration and cache that provider until Retrieve is called again.

The ChainProvider provides a way of chaining multiple providers together which will pick the first available using priority order of the Providers in the list.

If none of the Providers retrieve valid configuration, Retrieve() will return the error ErrNoValidProvidersFoundInChain.

If a Provider is found which returns valid configuration, ChainProvider will cache that Provider for all calls until Retrieve is called again.

func (*ChainProvider) Retrieve

func (x *ChainProvider) Retrieve(ctx context.Context) (*Value, error)

Retrieve retrieves and returns the configuration, or error in case of failure.

func (*ChainProvider) String

func (x *ChainProvider) String() string

String returns the string representation of the Chain provider.

type Config

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

Config provides synchronous safe retrieval of configuration.

Config is safe to use across multiple goroutines and will manage the synchronous state so the Providers do not need to implement their own synchronization.

The first Config.Get() will always call Provider.Retrieve() to get the first instance of the configuration. All calls to Get() after that will return the cached configuration.

func NewChainProvider

func NewChainProvider(providers ...Provider) *Config

NewChainProvider returns a new Config object wrapping a chain of providers.

func NewConfig

func NewConfig(provider Provider) *Config

NewConfig returns a new Config with the provider set.

func NewConfigMapProvider

func NewConfigMapProvider(client client.Client, name, namespace string) *Config

NewConfigMapProvider returns a new Config object wrapping the ConfigMap provider.

func NewDefaultProvider

func NewDefaultProvider() *Config

NewDefaultProvider returns a new Config object wrapping the Default provider.

func NewEnvProvider

func NewEnvProvider() *Config

NewEnvProvider returns a new Config object wrapping the Env provider.

func (*Config) Get

func (x *Config) Get(ctx context.Context) (*Value, error)

Get returns the configuration, or error if the configuration failed to be retrieved. Will return the cached configuration. If the configuration is empty the Provider's Retrieve() will be called to refresh the configuration.

func (*Config) Refresh

func (x *Config) Refresh() *Config

Refresh refreshes the configuration and forces it to be retrieved on the next call to Get().

type ConfigMapProvider

type ConfigMapProvider struct {
	Client          client.Client
	Name, Namespace string
}

ConfigMapProvider retrieves configuration from a ConfigMap.

func (*ConfigMapProvider) Retrieve

func (x *ConfigMapProvider) Retrieve(ctx context.Context) (*Value, error)

Retrieve retrieves and returns the configuration, or error in case of failure.

func (*ConfigMapProvider) String

func (x *ConfigMapProvider) String() string

String returns the string representation of the ConfigMap provider.

type DefaultProvider

type DefaultProvider struct{}

DefaultProvider returns the default configuration.

func (*DefaultProvider) Retrieve

func (x *DefaultProvider) Retrieve(context.Context) (*Value, error)

Retrieve retrieves and returns the configuration, or error in case of failure.

func (*DefaultProvider) String

func (x *DefaultProvider) String() string

String returns the string representation of the Default provider.

type EnvProvider

type EnvProvider struct{}

EnvProvider retrieves configuration from the environment variables of the process.

func (*EnvProvider) Retrieve

func (x *EnvProvider) Retrieve(ctx context.Context) (*Value, error)

Retrieve retrieves and returns the configuration, or error in case of failure.

func (*EnvProvider) String

func (x *EnvProvider) String() string

String returns the string representation of the Env provider.

type Provider

type Provider interface {
	fmt.Stringer

	// Retrieve retrieves and returns the configuration, or error in case of failure.
	Retrieve(ctx context.Context) (*Value, error)
}

Provider defines the interface for any component which will provide configuration. The Provider should not need to implement its own mutexes, because that will be managed by Config.

type Value

type Value struct {
	ClusterIdentifier string `json:"clusterIdentifier,omitempty" yaml:"clusterIdentifier,omitempty"`
}

Value represents the operator configuration.

func (*Value) IsComplete

func (v *Value) IsComplete() bool

IsComplete if all fields of a Value are set.

func (*Value) IsEmpty

func (v *Value) IsEmpty() bool

IsEmpty if all fields of a Value are empty.

func (*Value) Merge

func (v *Value) Merge(v2 *Value) *Value

Merge merges the passed in Value into the existing Value object.

Jump to

Keyboard shortcuts

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