config

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 28 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 (
	// VersionEnabledFeatureKey indicates the configuration key of the version feature gate.
	// If the value is true, the feature is enabled cluster-wide.
	VersionEnabledFeatureKey = "version.enabled"

	// ProxyEnabledFeatureKey indicates the configuration key of the proxy feature gate.
	// If the value is true, the feature is enabled cluster-wide.
	ProxyEnabledFeatureKey = "proxy.enabled"

	// InitializeAllowLocalRequestsFeatureKey indicates the configuration key of.
	// If the value is true, the feature is enabled cluster-wide.
	InitializeAllowLocalRequestsFeatureKey = "plugin.gitlab.allow-local-requests"

	// PrunerDelayAfterCompletedFeatureKey represent taskRun delay configuration key
	PrunerDelayAfterCompletedFeatureKey = "taskRunPruner.delayAfterCompleted"

	// PrunerKeepFeatureKey represent taskRun keep configuration key
	PrunerKeepFeatureKey = "taskRunPruner.keep"

	// BuildMRCheckTimeoutKey represent build merge request status check timeout key
	BuildMRCheckTimeoutKey = "build.mergerequest.checkTimeout"

	// BuildMRCheckTimeoutContinueKey represent build merge request status check timeout continue key
	BuildMRCheckTimeoutContinueKey = "build.mergerequest.checkTimeoutContinue"

	// TemplateRenderCheckTimeoutKey represent templatrender timeout key
	TemplateRenderCheckTimeoutKey = "templateRender.checkTimeout"

	// TemplateRenderRetentionTimeKey represent the config key for how long templatrender will remain
	// retentionTime seems like a better name than delayAfterCompleted so that we use rententionTime here
	TemplateRenderRetentionTimeKey = "templateRender.retentionTime"

	// PolicyRunRetentionTimeKey represent the config key for how long policyRun will remain
	PolicyRunRetentionTimeKey = "policyRun.retentionTime"

	// PolicyCheckEnabledFeatureKey indicates the configuration key of the policy check feature gate.
	// If the value is true, the feature is enabled cluster-wide.
	PolicyCheckEnabledFeatureKey = "policy.check.enabled"

	// ClusterIntegrationSyncPeriodKey indicates the configuration key for clusterintegration synchronization.
	ClusterIntegrationSyncPeriodKey = "clusterIntegration.syncPeriod"

	// IntegrationSyncPeriodKey indicates the configuration key for integration synchronization.
	IntegrationSyncPeriodKey = "integration.syncPeriod"

	// PprofEnabledKey indicates the configuration key of the /debug/pprof debugging api/
	PprofEnabledKey = "pprof.enabled"

	// ClusterTaskDisabledKey specifies the key for the clustertask creation feature.
	// When set to false, the creation of clustertasks is disabled and new clustertasks cannot be created and can only be updated.
	ClusterTaskCreationEnabledKey = "clustertask.creation.enabled"

	// ClusterTaskMigrationEnabledKey specifies the key for the clustertask migration feature.
	ClusterTaskMigrationEnabledKey = "clustertask.migration.enabled"

	// KatanomiSystemNamespaceKey specifies the key for the katanomi system namespace
	KatanomiSystemNamespaceKey = "katanomi.system.namespace"

	// GitSourceResolverFeatureKey indicates the configuration key of the gitsource resolver feature gate.
	GitSourceResolverFeatureKey = "gitsourceResolver.enabled"

	// HubResolverFeatureKey indicates the configuration key of the hub resolver feature gate.
	HubResolverFeatureKey = "hubResolver.enabled"
)

Variables

This section is empty.

Functions

func ConfigFilter added in v0.10.0

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 added in v0.10.0

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 added in v0.9.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.10.0

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"

	// DefaultVersionEnabled indicates the default value of the version feature gate.
	// If the corresponding key does not exist, the default value is returned.
	DefaultVersionEnabled FeatureValue = False

	// DefaultProxyEnabled indicates the default value of the proxy feature gate.
	// If the corresponding key does not exist, the default value is returned.
	DefaultProxyEnabled FeatureValue = False

	// DefaultInitializeAllowLocalRequests indicates the configuration key of.
	// If the corresponding key does not exist, the default value is returned.
	DefaultInitializeAllowLocalRequests FeatureValue = True

	// DefaultPrunerDelayAfterCompleted represent default duration for delay taskRun
	// If the corresponding key does not exist, the default value is returned.
	DefaultPrunerDelayAfterCompleted FeatureValue = "time.Hour"

	// DefaultPrunerKeep represent default keep number for taskRun
	// If the corresponding key does not exist, the default value is returned.
	DefaultPrunerKeep FeatureValue = "10000"

	// DefaultMRCheckTimeout represent default timeout for merge request status check
	DefaultMRCheckTimeout FeatureValue = "10m"

	// DefaultMRCheckTimeoutContinue represent default timeout continue for merge request status check
	DefaultMRCheckTimeoutContinue FeatureValue = True

	// DefaultTemplateRenderCheckTimeout represent default timeout for templaterender check
	DefaultTemplateRenderCheckTimeout FeatureValue = "30s"

	// DefaultTemplateRenderRetentionTime represents default duration how long the templatrender will remain
	DefaultTemplateRenderRetentionTime FeatureValue = "30m"

	// DefaultPolicyRunRetentionTime represents default duration how long the policyRun will remain
	DefaultPolicyRunRetentionTime = "30m"

	// DefaultPolicyCheckEnabled indicates the default value of the policy check feature gate.
	// If the corresponding key does not exist, the default value is returned.
	DefaultPolicyCheckEnabled FeatureValue = True

	// DefaultClusterIntegrationSyncPeriod defines the default time interval of clusterintegration synchronization
	DefaultClusterIntegrationSyncPeriod = "5m"

	// DefaultIntegrationsSyncPeriod defines the default time interval of integration synchronization
	DefaultIntegrationsSyncPeriod = "15m"

	// 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

	// DefaultClusterTaskCreationEnabledKey stores the default value "false" for the feature.
	DefaultClusterTaskCreationEnabledKey FeatureValue = False

	// DefaultClusterTaskMigrationEnabledKey stores the default value "false" for the feature.
	DefaultClusterTaskMigrationEnabledKey FeatureValue = False

	// DefaultKatanomiSystemNamespace defines the default namespace for katanomi system
	DefaultKatanomiSystemNamespace = "katanomi-system"

	// DefaultGitSourceResolverEnabled defines the default value "true" for the "gitsourceResolver.enabled" feature.
	DefaultGitSourceResolverEnabled = True

	// DefaultHubResolverEnabled defines the default value "true" for the "hubResolver.enabled" feature.
	DefaultHubResolverEnabled = True
)

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.

func (*Manager) WatchFeatureFlagChanged

func (manager *Manager) WatchFeatureFlagChanged(ctx context.Context, listFunc ListByFeatureFlagChanged, featureChanged HasFeatureChangedFunc) (source.Source, handler.EventHandler, builder.WatchesOption)

WatchFeatureFlagChanged trigger reconcile when the function switch is changed.

type ManagerInterface added in v0.8.0

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