config

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package config stores katanomi configuration manager which watch configmap and work immediately if configmap changed

Index

Constants

View Source
const (
	// PprofEnabledKey indicates the configuration key of the /debug/pprof debugging api/
	PprofEnabledKey = "pprof.enabled"
)

Variables

This section is empty.

Functions

func ConfigFilter

func ConfigFilter(ctx context.Context, manager *Manager, configKey string, expectedKeyValueFunc ConfigKeyExpectedValueFunc) func(*restful.Request, *restful.Response, *restful.FilterChain)

ConfigFilter adds a restful filter to manager to watch configmap and and custom validation according a specific key value pair.

func ConfigFilterNotFoundWhenNotTrue

func ConfigFilterNotFoundWhenNotTrue(ctx context.Context, req *restful.Request, key string, value FeatureValue) (err error)

ConfigFilterNotFoundWhenNotTrue is a helper ConfigKeyExpectedValue implementation that checks if the value is a boolean true value, if not true will return a standard 404 not found error

func GetDurationConfig

func GetDurationConfig(ctx context.Context, key string, defaultDuration time.Duration) time.Duration

GetDurationConfig return duration configuration store in manager and return default if not exist

func Name

func Name() string

Name return config name for configuration

func WithKatanomiConfigManager

func WithKatanomiConfigManager(ctx context.Context, manager *Manager) context.Context

WithKatanomiConfigManager sets a Config Manager instance into a context

Types

type Config

type Config struct {
	Data map[string]string
}

Config store katanomi configuration

func (Config) GetBool

func (c Config) GetBool(key string) (*bool, error)

GetBool will parse value in Config.Data["key"] to bool if the key not exist, it will return nil if the value is not a valid bool string, it will return error

func (Config) GetObject

func (c Config) GetObject(key string, object interface{}) error

GetObject will parse value in Config.Data["key"] to object it expects the value should be yaml content

type ConfigKeyExpectedValueFunc

type ConfigKeyExpectedValueFunc func(ctx context.Context, req *restful.Request, key string, value FeatureValue) (err error)

ConfigKeyExpectedValueFunc is a helper function to check if configmap has expected value If the value is not as expected, an error is expected to be returned

type FeatureFlags

type FeatureFlags struct {
	Data map[string]string
}

FeatureFlags holds the features configurations

func (*FeatureFlags) FeatureValue

func (f *FeatureFlags) FeatureValue(flag string) FeatureValue

FeatureValue returns the value of the implemented feature flag, or the default if not found.

type FeatureValue

type FeatureValue string

FeatureValue definition of FeatureValue feature value

const (
	// True represents the value "true" for the feature switch.
	True FeatureValue = "true"

	// False represents the value "false" for the feature switch.
	False FeatureValue = "false"

	// DefaultPprofEnabled stores the default value "false" for the "pprof.enabled" /debug/pprof debugging api.
	// If the corresponding key does not exist, the default value is returned.
	DefaultPprofEnabled FeatureValue = False
)

func (FeatureValue) AsBool

func (f FeatureValue) AsBool() (bool, error)

AsBool returns as a Bool, or false if the conversion fails.

func (FeatureValue) AsDuration

func (f FeatureValue) AsDuration() (time.Duration, error)

AsBool returns as a Duration, or 0 if the conversion fails.

func (FeatureValue) AsInt

func (f FeatureValue) AsInt() (int, error)

AsInt returned as an integer, or -1 if the conversion fails.

func (FeatureValue) String

func (f FeatureValue) String() string

String returned as a string

type HasFeatureChangedFunc

type HasFeatureChangedFunc func(new *FeatureFlags, old *FeatureFlags) bool

HasFeatureChangedFunc check whether the function switch of interest has changed.

type ListByFeatureFlagChanged

type ListByFeatureFlagChanged func(ctx context.Context) []metav1.Object

ListByFeatureFlagChanged when the function switch is changed, get the object function that triggers reconile.

type Manager

type Manager struct {
	Informer watcher.DefaultingWatcherWithOnChange
	Logger   *zap.SugaredLogger

	*Config
	// contains filtered or unexported fields
}

Manager will manage katanomi configuration and store in Config

func KatanomiConfigManager

func KatanomiConfigManager(ctx context.Context) *Manager

KatanomiConfigManager returns a Config Manager, returns nil if not found

func NewManager

func NewManager(informer watcher.DefaultingWatcherWithOnChange, logger *zap.SugaredLogger, cmName string) *Manager

NewManager will instantiate a manager that watch configmap for core component configuration

func (*Manager) AddWatcher

func (manager *Manager) AddWatcher(w Watcher)

AddWatcher add a watcher to manager the watcher will be called when the configmap is changed

func (*Manager) GetConfig

func (manager *Manager) GetConfig() *Config

GetConfig will return the config of manager

func (*Manager) GetFeatureFlag

func (manager *Manager) GetFeatureFlag(flag string) FeatureValue

GetFeatureFlag get the function switch data, if the function switch is not set, return the default value of the switch.

func (*Manager) GetFeatureFlagByClient

func (manager *Manager) GetFeatureFlagByClient(ctx context.Context, flag string) FeatureValue

GetFeatureFlagByClient get the config configuration by requesting configmap from the client. prioritize the use of GetFeatureFlag, and use the current function in scenarios that require high real-time data.

type ManagerInterface

type ManagerInterface interface {
	GetConfig() *Config
	GetFeatureFlag(flag string) FeatureValue
}

type WatchFunc

type WatchFunc func(*Config)

WatchFunc is the callback function for config watcher

type Watcher

type Watcher interface {
	Watch(config *Config)
}

Watcher describes the interface for config watcher

func NewConfigWatcher

func NewConfigWatcher(cb WatchFunc) Watcher

NewConfigWatcher constructs a new config watcher please note that the callback should be processed quickly and should not block

Directories

Path Synopsis
Package fake provide fake manager for config
Package fake provide fake manager for config

Jump to

Keyboard shortcuts

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