diff --git a/pkg/module_manager/models/modules/basic.go b/pkg/module_manager/models/modules/basic.go index b513fe571..c783c6c9f 100644 --- a/pkg/module_manager/models/modules/basic.go +++ b/pkg/module_manager/models/modules/basic.go @@ -576,6 +576,7 @@ func (bm *BasicModule) valuesForEnabledScript(precedingEnabledModules []string) // TODO: ?????? res = mergeLayers( + utils.Values{}, res, utils.Values{ "global": map[string]interface{}{ @@ -716,7 +717,7 @@ func (bm *BasicModule) executeHook(h *hooks.ModuleHook, bindingType sh_op_types. if valuesPatchResult.ValuesChanged { logEntry.Debugf("Module hook '%s': validate module values before update", h.GetName()) // Validate schema for updated module values - validationErr := bm.valuesStorage.PreCommitValues(bm.Name, valuesPatchResult.Values) + validationErr := bm.valuesStorage.PreCommitValues(valuesPatchResult.Values) if validationErr != nil { return multierror.Append( fmt.Errorf("cannot apply values patch for module values"), diff --git a/pkg/module_manager/models/modules/global.go b/pkg/module_manager/models/modules/global.go index bf4892ba9..663daa522 100644 --- a/pkg/module_manager/models/modules/global.go +++ b/pkg/module_manager/models/modules/global.go @@ -224,8 +224,10 @@ func (gm *GlobalModule) executeHook(h *hooks.GlobalHook, bindingType sh_op_types // and no patches for 'global' section — valuesPatchResult will be nil in this case. if valuesPatchResult != nil && valuesPatchResult.ValuesChanged { logEntry.Debugf("Global hook '%s': validate global values before update", h.GetName()) - validationErr := gm.valuesStorage.PreCommitValues(gm.GetName(), valuesPatchResult.Values) + validationErr := gm.valuesStorage.PreCommitValues(valuesPatchResult.Values) if validationErr != nil { + fmt.Println("BEFORE VALUES", gm.GetValues()) + fmt.Println("PATCH", valuesPatchResult.Values) return fmt.Errorf("cannot apply values patch for global values: %w", validationErr) } diff --git a/pkg/module_manager/models/modules/values_storage.go b/pkg/module_manager/models/modules/values_storage.go index 27b46a202..8102c1488 100644 --- a/pkg/module_manager/models/modules/values_storage.go +++ b/pkg/module_manager/models/modules/values_storage.go @@ -61,6 +61,8 @@ type ValuesStorage struct { dirtyConfigValues utils.Values dirtyMergedConfigValues utils.Values + // TODO: acutally, we don't need the validator with all Schemas here, + // we can put a single openapi schema for the specified module validator validator moduleName string } @@ -97,6 +99,7 @@ func (vs *ValuesStorage) openapiDefaultsTransformer(schemaType validation.Schema func (vs *ValuesStorage) calculateResultValues() error { merged := mergeLayers( + utils.Values{}, // Init static values (from modules/values.yaml and modules/XXX/values.yaml) vs.staticConfigValues, @@ -138,6 +141,7 @@ func (vs *ValuesStorage) PreCommitConfigValues(configV utils.Values) error { fmt.Println("STATIC ", vs.staticConfigValues) fmt.Println("NEW ", configV) merged := mergeLayers( + utils.Values{}, // Init static values vs.staticConfigValues, @@ -151,6 +155,8 @@ func (vs *ValuesStorage) PreCommitConfigValues(configV utils.Values) error { vs.dirtyMergedConfigValues = merged vs.dirtyConfigValues = configV + fmt.Println("AFTER", vs.staticConfigValues) + return vs.validateConfigValues(merged) } @@ -188,14 +194,23 @@ func (vs *ValuesStorage) dirtyConfigValuesHasDiff() bool { return false } -func (vs *ValuesStorage) PreCommitValues(moduleName string, v utils.Values) error { - fmt.Println("SET NEW VALUES", moduleName, v) +func (vs *ValuesStorage) PreCommitValues(v utils.Values) error { + if vs.mergedConfigValues == nil { + vs.mergedConfigValues = mergeLayers( + utils.Values{}, + // Init static values + vs.staticConfigValues, - fmt.Println("STATIC ", vs.staticConfigValues) - fmt.Println("CONFIG ", vs.configValues) - fmt.Println("NEW ", v) + // defaults from openapi + vs.openapiDefaultsTransformer(validation.ConfigValuesSchema), + + // User configured values (ConfigValues) + vs.configValues, + ) + } merged := mergeLayers( + utils.Values{}, // Init static values (from modules/values.yaml) vs.mergedConfigValues, diff --git a/pkg/module_manager/models/modules/values_storage_test.go b/pkg/module_manager/models/modules/values_storage_test.go index 2fb11c245..b357e2fda 100644 --- a/pkg/module_manager/models/modules/values_storage_test.go +++ b/pkg/module_manager/models/modules/values_storage_test.go @@ -1,6 +1,7 @@ package modules import ( + "fmt" "testing" "github.com/stretchr/testify/assert" @@ -16,6 +17,8 @@ type: object default: {} additionalProperties: false properties: + xxx: + type: string highAvailability: type: boolean modules: @@ -33,9 +36,19 @@ x-extend: schema: config-values.yaml type: object default: {} +properties: + internal: + type: object + default: {} + properties: + fooBar: + type: string + default: baz ` - initial := utils.Values{} + initial := utils.Values{ + "xxx": "yyy", + } vv := validation.NewValuesValidator() err := vv.SchemaStorage.AddGlobalValuesSchemas([]byte(cfg), []byte(vcfg)) require.NoError(t, err) @@ -48,6 +61,9 @@ default: {} }, } - err = st.PreCommitConfigValues("global", configV) + err = st.PreCommitConfigValues(configV) assert.NoError(t, err) + st.CommitConfigValues() + st.calculateResultValues() + fmt.Println(st.GetValues()) }