configuration

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: AGPL-3.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Unconfirmed int32 = -1
	NotStarted  int32 = 0
)
View Source
const (
	ReconfigureCreatedPhase    = "created"
	ReconfigureNoChangeType    = "noChange"
	ReconfigureAutoReloadPhase = string(appsv1alpha1.AutoReload)
	ReconfigureSimplePhase     = string(appsv1alpha1.NormalPolicy)
	ReconfigureParallelPhase   = string(appsv1alpha1.RestartPolicy)
	ReconfigureRollingPhase    = string(appsv1alpha1.RollingPolicy)
)
View Source
const (
	StoreUnit = 1024

	KByte = 1 * StoreUnit
	MByte = KByte * StoreUnit
	GByte = MByte * StoreUnit
	TByte = GByte * StoreUnit
	PByte = TByte * StoreUnit
	EByte = PByte * StoreUnit
	ZByte = EByte * StoreUnit
	YByte = ZByte * StoreUnit
)
View Source
const (
	Millisecond = time.Duration(1)
	Second      = 1000 * Millisecond
	Minute      = 60 * Second
	Hour        = 60 * Minute
	Day         = 24 * Hour
)

Variables

View Source
var (
	ConfigEventHandlerMap = make(map[string]ConfigEventHandler)
)

Functions

func ApplyConfigPatch

func ApplyConfigPatch(baseCfg []byte, updatedParameters map[string]string, formatConfig *appsv1alpha1.FormatterConfig) (string, error)

func CueValidate

func CueValidate(cueTpl string) error

CueValidate validates cue file

func FromCMKeysSelector

func FromCMKeysSelector(keys []string) *set.LinkedHashSetString

func FromStringMap

func FromStringMap(m map[string]string) map[string]interface{}

FromStringMap converts a map[string]string to a map[string]interface{}

func GenerateConstraintsUniqLabelKeyWithConfig

func GenerateConstraintsUniqLabelKeyWithConfig(configKey string) string

GenerateConstraintsUniqLabelKeyWithConfig generates uniq key for configure template reference: docs/img/reconfigure-cr-relationship.drawio.png

func GenerateOpenAPISchema

func GenerateOpenAPISchema(cueTpl string, schemaType string) (*apiextv1.JSONSchemaProps, error)

GenerateOpenAPISchema generates openapi schema from cue type Definitions.

func GenerateTPLUniqLabelKeyWithConfig

func GenerateTPLUniqLabelKeyWithConfig(configKey string) string

GenerateTPLUniqLabelKeyWithConfig generates uniq key for configuration template reference: docs/img/reconfigure-cr-relationship.drawio.png

func GenerateUniqKeyWithConfig

func GenerateUniqKeyWithConfig(label string, configKey string) string

GenerateUniqKeyWithConfig is similar to getInstanceCfgCMName, generates uniq label/annotations for configuration template

func GetComponentCfgName

func GetComponentCfgName(clusterName, componentName, tplName string) string

GetComponentCfgName is similar to getInstanceCfgCMName, while without statefulSet object.

func GetConfigTemplatesFromComponent

func GetConfigTemplatesFromComponent(
	cComponents []appsv1alpha1.ClusterComponentSpec,
	dComponents []appsv1alpha1.ClusterComponentDefinition,
	aComponents []appsv1alpha1.ClusterComponentVersion,
	componentName string) ([]appsv1alpha1.ComponentConfigSpec, error)

GetConfigTemplatesFromComponent returns ConfigTemplate list used by the component

func GetInstanceCMName

func GetInstanceCMName(obj client.Object, tpl *appsv1alpha1.ComponentTemplateSpec) string

GetInstanceCMName {{statefull.Name}}-{{clusterVersion.Name}}-{{tpl.Name}}-"config"

func GetParameterFromConfiguration

func GetParameterFromConfiguration(configMap *corev1.ConfigMap, allFiles bool, fieldPath ...string) ([]string, error)

GetParameterFromConfiguration gets configure parameter ctx: apiserver context cli: apiserver client cluster: appsv1alpha1.Cluster component: component name

func GetReloadOptions added in v0.6.0

func IsNotUserReconfigureOperation

func IsNotUserReconfigureOperation(cm *corev1.ConfigMap) bool

IsNotUserReconfigureOperation checks if the parameters are updated from operation

func IsParametersUpdateFromManager

func IsParametersUpdateFromManager(cm *corev1.ConfigMap) bool

IsParametersUpdateFromManager checks if the parameters are updated from manager

func IsSchedulableConfigResource

func IsSchedulableConfigResource(object client.Object) bool

func IsSupportConfigFileReconfigure added in v0.6.0

func IsSupportConfigFileReconfigure(configTemplateSpec appsv1alpha1.ComponentConfigSpec, configFileKey string) bool

func IsUpdateDynamicParameters

func IsUpdateDynamicParameters(cc *appsv1alpha1.ConfigConstraintSpec, cfg *ConfigPatchInfo) (bool, error)

IsUpdateDynamicParameters checks if the changed parameters require a restart

func IsWatchModuleForShellTrigger added in v0.6.0

func IsWatchModuleForShellTrigger(trigger *appsv1alpha1.ShellTrigger) bool

func IsWatchModuleForTplTrigger added in v0.6.0

func IsWatchModuleForTplTrigger(trigger *appsv1alpha1.TPLScriptTrigger) bool

func LoadConfigObjectFromContent added in v0.6.0

func LoadConfigObjectFromContent(cfgType appsv1alpha1.CfgFileFormat, rawData string) (map[string]interface{}, error)

func LoadRawConfigObject

func LoadRawConfigObject(data map[string]string, formatConfig *appsv1alpha1.FormatterConfig, keys []string) (map[string]unstructured.ConfigObject, error)

func MakeError

func MakeError(formatMsg string, args ...interface{}) error

func MergeAndValidateConfigs

func MergeAndValidateConfigs(configConstraint appsv1alpha1.ConfigConstraintSpec, baseConfigs map[string]string, cmKey []string, updatedParams []ParamPairs) (map[string]string, error)

MergeAndValidateConfigs merges and validates configuration files

func MergeConfigTemplates

func MergeConfigTemplates(cvConfigSpecs []appsv1alpha1.ComponentConfigSpec,
	cdConfigSpecs []appsv1alpha1.ComponentConfigSpec) []appsv1alpha1.ComponentConfigSpec

MergeConfigTemplates merges ClusterVersion.ComponentDefs[*].ConfigTemplateRefs and ClusterDefinition.ComponentDefs[*].ConfigTemplateRefs

func MergeUpdatedConfig added in v0.6.0

func MergeUpdatedConfig(baseMap, updatedMap map[string]string) map[string]string

MergeUpdatedConfig replaces the file content of the changed key. baseMap is the original configuration file, updatedMap is the updated configuration file

func NeedReloadVolume added in v0.6.0

func NeedReloadVolume(config appsv1alpha1.ComponentConfigSpec) bool

func NestedPrefixField

func NestedPrefixField(formatConfig *appsv1alpha1.FormatterConfig) string

func NewConfigLoader

func NewConfigLoader(option CfgOption) (*dataConfig, error)

func SetParametersUpdateSource

func SetParametersUpdateSource(cm *corev1.ConfigMap, source string)

SetParametersUpdateSource sets the parameters' update source manager: parameter only updated from manager external-template: parameter only updated from template ops: parameter updated from operation

func TransformConfigFileToKeyValueMap

func TransformConfigFileToKeyValueMap(fileName string, formatterConfig *appsv1alpha1.FormatterConfig, configData []byte) (map[string]string, error)

TransformConfigFileToKeyValueMap transforms a config file in appsv1alpha1.CfgFileFormat format to a map in which the key is config name and the value is config value sectionName means the desired section of config file, such as [mysqld] section. If config file has no section structure, sectionName should be default to get all values in this config file.

func ValidateConfigPatch added in v0.6.0

func ValidateConfigPatch(patch *ConfigPatchInfo, formatCfg *appsv1alpha1.FormatterConfig) error

ValidateConfigPatch Verifies if the changed parameters have been removed

func ValidateConfigurationWithCue

func ValidateConfigurationWithCue(cueTpl string, cfgType appsv1alpha1.CfgFileFormat, rawData string) error

func WrapError

func WrapError(err error, formatMsg string, args ...interface{}) error

Types

type CfgOpOption

type CfgOpOption struct {
	// optional
	VolumeName string
	// optional
	FileName string

	// option
	// for all configuration
	AllSearch bool

	// optional
	IniContext *IniContext
	// optional
	XMLContext *XMLContext
}

func NewCfgOptions

func NewCfgOptions(filename string, options ...Option) CfgOpOption

type CfgOption

type CfgOption struct {
	Type ConfigType
	Log  logr.Logger

	// formatter
	CfgType appsv1alpha1.CfgFileFormat

	// Path for CfgLocalType test
	Path    string
	RawData []byte

	// ConfigResource for k8s resource
	ConfigResource *ConfigResource
}

type ConfigEventContext

type ConfigEventContext struct {
	Client  client.Client
	ReqCtx  intctrlutil.RequestCtx
	Cluster *appsv1alpha1.Cluster

	ClusterComponent *appsv1alpha1.ClusterComponentSpec
	Component        *appsv1alpha1.ClusterComponentDefinition
	ComponentUnits   []appv1.StatefulSet
	DeploymentUnits  []appv1.Deployment

	ConfigSpecName   string
	ConfigPatch      *ConfigPatchInfo
	ConfigMap        *corev1.ConfigMap
	ConfigConstraint *appsv1alpha1.ConfigConstraintSpec

	PolicyStatus PolicyExecStatus
}

type ConfigEventHandler

type ConfigEventHandler interface {
	Handle(eventContext ConfigEventContext, lastOpsRequest string, phase appsv1alpha1.OpsPhase, err error) error
}

type ConfigLoaderProvider

type ConfigLoaderProvider func(option CfgOption) (*cfgWrapper, error)

type ConfigOperator

type ConfigOperator interface {
	// MergeFrom updates parameter in key-value
	MergeFrom(params map[string]interface{}, option CfgOpOption) error

	// Query gets parameter
	Query(jsonpath string, option CfgOpOption) ([]byte, error)

	// ToCfgContent to configuration file content
	ToCfgContent() (map[string]string, error)
}

type ConfigPatchInfo

type ConfigPatchInfo struct {
	IsModify bool
	// new config
	AddConfig map[string]interface{}

	// delete config
	DeleteConfig map[string]interface{}

	// update config
	// patch json
	UpdateConfig map[string][]byte

	Target      *cfgWrapper
	LastVersion *cfgWrapper
}

func CreateConfigPatch

func CreateConfigPatch(oldVersion, newVersion map[string]string, format appsv1alpha1.CfgFileFormat, keys []string, comparableAllFiles bool) (*ConfigPatchInfo, bool, error)

CreateConfigPatch creates a patch for configuration files with different version.

func CreateMergePatch

func CreateMergePatch(oldVersion, newVersion interface{}, option CfgOption) (*ConfigPatchInfo, error)

func TransformConfigPatchFromData added in v0.6.0

func TransformConfigPatchFromData(data map[string]string, format appsv1alpha1.CfgFileFormat, keys []string) (*ConfigPatchInfo, error)

type ConfigResource

type ConfigResource struct {
	CfgKey         client.ObjectKey
	ResourceReader GetResourceFn

	// configmap data
	ConfigData map[string]string
	CMKeys     *set.LinkedHashSetString
}

func FromConfigData

func FromConfigData(data map[string]string, cmKeys *set.LinkedHashSetString) *ConfigResource

type ConfigType

type ConfigType string
const (
	CfgCmType    ConfigType = "configmap"
	CfgTplType   ConfigType = "configConstraint"
	CfgLocalType ConfigType = "local"
	CfgRawType   ConfigType = "raw"
)

type ConfigValidator

type ConfigValidator interface {
	Validate(data map[string]string) error
}

func NewConfigValidator

func NewConfigValidator(configConstraint *appsv1alpha1.ConfigConstraintSpec, options ...ValidatorOptions) ConfigValidator

type CueType

type CueType string

CueType defines cue type +enum

const (
	NullableType            CueType = "nullable"
	FloatType               CueType = "float"
	IntType                 CueType = "integer"
	BoolType                CueType = "boolean"
	StringType              CueType = "string"
	StructType              CueType = "object"
	ListType                CueType = "array"
	K8SQuantityType         CueType = "quantity"
	ClassicStorageType      CueType = "storage"
	ClassicTimeDurationType CueType = "timeDuration"
)

type CueWalkVisitor

type CueWalkVisitor interface {
	Visit(val cue.Value)
}

type GetResourceFn

type GetResourceFn func(key client.ObjectKey) (map[string]string, error)

type IniContext

type IniContext struct {
	SectionName string
}

type Option

type Option func(ctx *CfgOpOption)

Option for operator

func WithFormatterConfig

func WithFormatterConfig(formatConfig *appsv1alpha1.FormatterConfig) Option

type ParamPairs

type ParamPairs struct {
	Key           string
	UpdatedParams map[string]interface{}
}

type ParameterPair

type ParameterPair struct {
	Key   string
	Value string
}

type ParameterUpdateType

type ParameterUpdateType string

ParameterUpdateType describes how to update the parameters. +enum

const (
	AddedType   ParameterUpdateType = "add"
	DeletedType ParameterUpdateType = "delete"
	UpdatedType ParameterUpdateType = "update"
)

type PolicyExecStatus

type PolicyExecStatus struct {
	PolicyName string
	ExecStatus string
	Status     string

	SucceedCount  int32
	ExpectedCount int32
}

type RawConfig

type RawConfig struct {
	// formatter
	Type appsv1alpha1.CfgFileFormat

	RawData string
}

type ReconfiguringProgress

type ReconfiguringProgress int32

ReconfiguringProgress defines the progress percentage. range: 0~100 Unconfirmed(-1) describes an uncertain progress, e.g: fsm is failed. +enum

type ValidatorOptions

type ValidatorOptions = func(key string) bool

func WithKeySelector

func WithKeySelector(keys []string) ValidatorOptions

type VisualizedParam

type VisualizedParam struct {
	Key        string
	UpdateType ParameterUpdateType
	Parameters []ParameterPair
}

func GenerateVisualizedParamsList

func GenerateVisualizedParamsList(configPatch *ConfigPatchInfo, formatConfig *appsv1alpha1.FormatterConfig, sets *set.LinkedHashSetString) []VisualizedParam

type XMLContext

type XMLContext struct {
}

XMLContext TODO(zt) Support Xml config

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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