Skip to content

Commit f4fefa7

Browse files
committed
[feature] inject module registry to values
Signed-off-by: Stepan Paksashvili <stepan.paksashvili@flant.com>
1 parent bf0654f commit f4fefa7

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

pkg/module_manager/models/modules/values_storage.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ func (vs *ValuesStorage) InjectRegistryValue(registry *Registry) {
183183
vs.lock.Lock()
184184
defer vs.lock.Unlock()
185185

186+
vs.schemaStorage.InjectRegistrySpec()
187+
186188
vs.resultValues["registry"] = registry
187189
}
188190

pkg/values/validation/schemas.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ func validateObject(dataObj interface{}, s *spec.Schema, rootName string) error
119119
return fmt.Errorf("validate config: schema is not provided")
120120
}
121121

122-
injectRegistryProperty(s)
123-
124122
validator := validate.NewSchemaValidator(s, nil, rootName, strfmt.Default) // , validate.DisableObjectArrayTypeCheck(true)
125123

126124
switch v := dataObj.(type) {
@@ -162,18 +160,19 @@ func validateObject(dataObj interface{}, s *spec.Schema, rootName string) error
162160
return allErrs.ErrorOrNil()
163161
}
164162

165-
// injectRegistryProperty mutates the module schema to add a strict-typed "registry" field
166-
func injectRegistryProperty(s *spec.Schema) {
167-
if len(s.Properties) == 0 {
163+
// InjectRegistrySpec mutates the module schema to add a strict-typed "registry" field
164+
func (st *SchemaStorage) InjectRegistrySpec() {
165+
scheme := st.Schemas[ValuesSchema]
166+
if scheme == nil || len(scheme.Properties) == 0 {
168167
return
169168
}
170169

171170
// skip if already present
172-
if _, exists := s.Properties["registry"]; exists {
171+
if _, exists := scheme.Properties["registry"]; exists {
173172
return
174173
}
175174

176-
s.Properties["registry"] = spec.Schema{
175+
scheme.Properties["registry"] = spec.Schema{
177176
SchemaProps: spec.SchemaProps{
178177
Type: spec.StringOrArray{"object"},
179178
AdditionalProperties: &spec.SchemaOrBool{Allows: false},
@@ -301,8 +300,6 @@ func PrepareSchemas(configBytes, valuesBytes []byte) (map[SchemaType]*spec.Schem
301300
&schema.CopyTransformer{},
302301
// Transform x-required-for-helm
303302
&schema.RequiredForHelmTransformer{},
304-
// Allow unknown fields (e.g., "registry") to pass validation
305-
&schema.AdditionalPropertiesTransformer{},
306303
)
307304
}
308305

0 commit comments

Comments
 (0)