Documentation ¶
Index ¶
- Constants
- Variables
- func LoadRawConfig(src map[string]string) (cfg string, ns string, err error)
- func LoadingMiddleware() router.MiddlewareFunc
- func LoadingMiddlewareWithLoader(loader ConfigLoader) router.MiddlewareFunc
- func MustLoadMiddleware() router.MiddlewareFunc
- func MustLoadMiddlewareWithLoader(loader ConfigLoader) router.MiddlewareFunc
- func WithContext(ctx context.Context, val NamespacedConfig) context.Context
- type CachingLoader
- type ChecksumLoader
- type ConfigLoader
- type Initializer
- type Loader
- type NamespacedConfig
Constants ¶
const ( // KeyConfig is the key in secureJsonData used for looking up kubeconfig. KeyConfig = "kubeconfig" // KeyNamespace is the key in secureJsonData used for looking up kube namespace. KeyNamespace = "kubenamespace" )
Variables ¶
var ( // ErrConfigMissing is the error returned when secureJsonData // does not contain serialized kubeconfig value. ErrConfigMissing = errors.New("config is missing from secureJsonData") )
var ( // ErrContextValueMissing is an error that's returned // when trying to fetch a Config from a context that doesn't have one. ErrContextValueMissing = errors.New("context does not contain the kubeconfig value") )
Functions ¶
func LoadRawConfig ¶
LoadRawConfig loads raw config data from decrypted secureJsonData.
func LoadingMiddleware ¶
func LoadingMiddleware() router.MiddlewareFunc
LoadingMiddleware returns a new middleware that can be used on a router for automatically extracting, loading and storing a Config into the context. The middleware does not return an error if Config cannot be loaded. The middleware uses a default loader.
func LoadingMiddlewareWithLoader ¶
func LoadingMiddlewareWithLoader(loader ConfigLoader) router.MiddlewareFunc
LoadingMiddlewareWithLoader returns a new middleware that can be used on a router for automatically extracting, loading and storing a Config into the context. The middleware does not return an error if Config cannot be loaded. The middleware will use loader for loading the Config from secureJsonData.
func MustLoadMiddleware ¶
func MustLoadMiddleware() router.MiddlewareFunc
MustLoadMiddleware returns a new middleware that can be used on a router for automatically extracting, loading and storing a Config into the context. The middleware will return an error response if it fails to extract and load a Config from request. The middleware uses a default loader.
func MustLoadMiddlewareWithLoader ¶
func MustLoadMiddlewareWithLoader(loader ConfigLoader) router.MiddlewareFunc
MustLoadMiddlewareWithLoader returns a new middleware that can be used on a router for automatically extracting, loading and storing a Config into the context. The middleware will return an error response if it fails to extract and load a Config from request. The middleware will use loader for loading the Config from secureJsonData.
func WithContext ¶
func WithContext(ctx context.Context, val NamespacedConfig) context.Context
WithContext returns a new Context that contains Config inside.
Types ¶
type CachingLoader ¶
type CachingLoader struct {
// contains filtered or unexported fields
}
CachingLoader is a ConfigLoader that loads NamespacedConfig from serialized config and namespace values and caches the result for the next calls.
Caching is done based on a CRC32 of the config.
The loader is safe for concurrent use, but MUST NOT be copied after initialization.
func NewCachingLoader ¶
func NewCachingLoader() *CachingLoader
NewCachingLoader returns a new CachingLoader with an empty cache.
func NewCustomCachingLoader ¶
func NewCustomCachingLoader(loader ChecksumLoader) *CachingLoader
NewCustomCachingLoader returns a new CachingLoader that uses loader for loading configs.
func (*CachingLoader) CRC32 ¶
func (c *CachingLoader) CRC32(config, namespace string) (uint32, error)
CRC32 returns the CRC 32 value of config and namespace strings.
func (*CachingLoader) Load ¶
func (c *CachingLoader) Load(config, namespace string, dst *NamespacedConfig) error
Load tries to load the Config from the passed values. The result will be written to dst and an error will be returned upon any failures (e.g. missing or malformed data). Load IS NOT guaranteed to clear dst - the caller is responsible for that.
func (*CachingLoader) LoadFromSettings ¶
func (c *CachingLoader) LoadFromSettings(set backend.AppInstanceSettings, dst *NamespacedConfig) error
LoadFromSettings loads the config from the AppInstanceSettings.
type ChecksumLoader ¶
type ChecksumLoader interface { ConfigLoader CRC32(config, namespace string) (uint32, error) }
ChecksumLoader is a ConfigLoader that can also compute a CRC32 of serialized values.
type ConfigLoader ¶
type ConfigLoader interface { Load(config, namespace string, dst *NamespacedConfig) error LoadFromSettings(set backend.AppInstanceSettings, dst *NamespacedConfig) error }
ConfigLoader loads NamespacedConfig from serialized config and namespace values.
type Initializer ¶
type Initializer[T any] func(cfg NamespacedConfig) (T, error)
Initializer is a function that initializes some value T that depends on a Config.
func CachingInitializer ¶
func CachingInitializer[T any](ini Initializer[T]) Initializer[T]
CachingInitializer returns an Initializer that caches values returned from ini.
Caching is based on the Config passed to ini, i.e. calling a CachingInitializer multiple times with the same Config will only call ini once and return cached value for all calls but the first one.
Only one value is cached at any given time. Passing a different Config will replace cached value, i.e. with calls like `ini(config1), ini(config2), ini(config1)` the third call will not be cached.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader is a ConfigLoader that loads NamespacedConfig from serialized config and namespace values.
The loader is safe for concurrent use, but MUST NOT be copied after initialization.
func (*Loader) Load ¶
func (c *Loader) Load(config, namespace string, dst *NamespacedConfig) error
Load loads the NamespacedConfig into dst. An error will be returned upon any failures (e.g. missing or malformed data). Load IS NOT guaranteed to clear dst - the caller is responsible for that.
func (*Loader) LoadFromSettings ¶
func (c *Loader) LoadFromSettings(set backend.AppInstanceSettings, dst *NamespacedConfig) error
LoadFromSettings loads the config from the AppInstanceSettings.
type NamespacedConfig ¶
type NamespacedConfig struct { // CRC32 is used for equality checks. CRC32 uint32 // RestConfig contains the Kubernetes rest.Config for creating API clients. RestConfig rest.Config // Namespace contains the namespace in which the resources should be stored and retrieved from. Namespace string }
NamespacedConfig is the configuration for a Kubernetes client. It contains a rest.Config, as well as the Kubernetes namespace to use when interacting with resources.
func FromContext ¶
func FromContext(ctx context.Context) (NamespacedConfig, error)
FromContext extracts a Config from provided Context. If the Config is missing an error will be returned.
func MustFromContext ¶
func MustFromContext(ctx context.Context) NamespacedConfig
MustFromContext extracts a Config from provided Context. If the Config is missing the call will panic.
func (NamespacedConfig) Equals ¶
func (c NamespacedConfig) Equals(other NamespacedConfig) bool
Equals returns true if Config is equal to other.