Skip to content

Commit

Permalink
[addon-operator] feat: change behavior for statusValues (#484)
Browse files Browse the repository at this point in the history
Signed-off-by: Evsyukov Denis <denis.evsyukov@flant.com>
  • Loading branch information
juev authored Jul 1, 2024
1 parent ddcef11 commit f43723a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 40 deletions.
31 changes: 4 additions & 27 deletions pkg/module_manager/models/modules/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func NewBasicModule(name, path string, order uint32, staticValues utils.Values,
}, nil
}

// WithDependencies unject module dependencies
// WithDependencies inject module dependencies
func (bm *BasicModule) WithDependencies(dep *hooks.HookExecutionDependencyContainer) {
bm.dc = dep
}
Expand Down Expand Up @@ -371,7 +371,7 @@ func (bm *BasicModule) RunHookByName(hookName string, binding sh_op_types.Bindin
return valuesChecksum, newValuesChecksum, nil
}

// RunEnabledScript executate enabled script
// RunEnabledScript execute enabled script
func (bm *BasicModule) RunEnabledScript(tmpDir string, precedingEnabledModules []string, logLabels map[string]string) (bool, error) {
// Copy labels and set 'module' label.
logLabels = utils.MergeLabels(logLabels)
Expand Down Expand Up @@ -761,7 +761,7 @@ func (bm *BasicModule) handleModuleValuesPatch(currentValues utils.Values, value
case utils.Values:
newValues = v
case map[string]interface{}:
newValues = utils.Values(v)
newValues = v
default:
return nil, fmt.Errorf("unknown module values type: %T", v)
}
Expand Down Expand Up @@ -886,17 +886,7 @@ func (bm *BasicModule) Validate() error {
return fmt.Errorf("'%s' name should be in kebab-case and be restorable from camelCase: consider renaming to '%s'", bm.GetName(), restoredName)
}

// load static config from values.yaml
staticValues, err := loadStaticValues(bm.GetName(), bm.GetPath())
if err != nil {
return fmt.Errorf("load values.yaml failed: %v", err)
}

if staticValues != nil {
return fmt.Errorf("please use openapi schema instead of values.yaml")
}

err = bm.ValidateValues()
err := bm.ValidateValues()
if err != nil {
return fmt.Errorf("validate values: %w", err)
}
Expand All @@ -917,19 +907,6 @@ func (bm *BasicModule) ValidateConfigValues() error {
return bm.valuesStorage.validateConfigValues(bm.GetConfigValues(false))
}

// loadStaticValues loads config for module from values.yaml
// Module is enabled if values.yaml is not exists.
func loadStaticValues(moduleName, modulePath string) (utils.Values, error) {
valuesYamlPath := filepath.Join(modulePath, utils.ValuesFileName)

if _, err := os.Stat(valuesYamlPath); os.IsNotExist(err) {
log.Debugf("module %s has no static values", moduleName)
return nil, nil
}

return utils.LoadValuesFileFromDir(modulePath)
}

type ModuleRunPhase string

const (
Expand Down
23 changes: 10 additions & 13 deletions pkg/module_manager/models/modules/values_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
)

/*
Module can contains a few sources of module values:
Module can contain a few sources of module values:
1. /modules/values.yaml - static (never reload)
2. /modules/001-module/values.yaml - static (could be reload on module Dynamic update (deregister + register))
2. /modules/001-module/values.yaml - static (could be reloaded on module Dynamic update (deregister + register))
3. /modules/001-module/openapi/config-values.yaml - dynamic, default values could be rendered differently
4. /modules/001-module/openapi/values.yaml - dynamic, default values
5. ConfigValues from KubeConfigManager - dynamic, get from user settings
Expand All @@ -31,11 +31,11 @@ type ValuesStorage struct {
// because it could be called from concurrent hooks (goroutines) and we will have a deadlock on RW mutex
lock sync.Mutex

// static staticConfigValues from
// static staticValues from
// /modules/values.yaml
// /modules/001-module/values.yaml
// are set only on module init phase
staticConfigValues utils.Values
staticValues utils.Values
// configValues are user defined values from KubeConfigManager (ConfigMap or ModuleConfig)
// without merge with static and openapi values
configValues utils.Values
Expand All @@ -55,9 +55,9 @@ func NewValuesStorage(moduleName string, staticValues utils.Values, configBytes,
}

vs := &ValuesStorage{
staticConfigValues: staticValues,
schemaStorage: schemaStorage,
moduleName: moduleName,
staticValues: staticValues,
schemaStorage: schemaStorage,
moduleName: moduleName,
}
err = vs.calculateResultValues()
if err != nil {
Expand All @@ -78,7 +78,7 @@ func (vs *ValuesStorage) calculateResultValues() error {
merged := mergeLayers(
utils.Values{},
// Init static values (from modules/values.yaml and modules/XXX/values.yaml)
vs.staticConfigValues,
vs.staticValues,

// from openapi config spec
vs.openapiDefaultsTransformer(validation.ConfigValuesSchema),
Expand Down Expand Up @@ -128,14 +128,14 @@ func (vs *ValuesStorage) validateValues(values utils.Values) error {
func (vs *ValuesStorage) getStaticValues() utils.Values {
vs.lock.Lock()
defer vs.lock.Unlock()
return vs.staticConfigValues
return vs.staticValues
}

// applyNewStaticValues sets the module's static values and recalculate the resulting values
func (vs *ValuesStorage) applyNewStaticValues(values utils.Values) error {
vs.lock.Lock()
defer vs.lock.Unlock()
vs.staticConfigValues = values
vs.staticValues = values
return vs.calculateResultValues()
}

Expand Down Expand Up @@ -216,8 +216,6 @@ func (vs *ValuesStorage) GenerateNewConfigValues(configV utils.Values, validate

merged := mergeLayers(
utils.Values{},
// Init static values
vs.staticConfigValues,

// User configured values (ConfigValues)
configV,
Expand All @@ -229,7 +227,6 @@ func (vs *ValuesStorage) GenerateNewConfigValues(configV utils.Values, validate
if validate {
mergedWithOpenapiDefault := mergeLayers(
utils.Values{},
vs.staticConfigValues,
vs.openapiDefaultsTransformer(validation.ConfigValuesSchema),
configV,
)
Expand Down

0 comments on commit f43723a

Please sign in to comment.