Skip to content

Commit 2739013

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

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

pkg/module_manager/models/modules/basic.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,10 @@ func (bm *BasicModule) GetConfigValues(withPrefix bool) utils.Values {
12151215
return bm.valuesStorage.GetConfigValues(withPrefix)
12161216
}
12171217

1218+
func (bm *BasicModule) InjectRegistryValue(registry *Registry) {
1219+
bm.valuesStorage.InjectRegistryValue(registry)
1220+
}
1221+
12181222
// Synchronization xxx
12191223
// TODO: don't like this honestly, i think we can remake it
12201224
func (bm *BasicModule) Synchronization() *SynchronizationState {

pkg/module_manager/models/modules/values_storage.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ type ValuesStorage struct {
4444
// result of the merging all input values
4545
resultValues utils.Values
4646
}
47+
type Registry struct {
48+
Base string `json:"base" yaml:"base"`
49+
DockerCfg string `json:"dockercfg" yaml:"dockercfg"`
50+
Scheme string `json:"scheme" yaml:"scheme"`
51+
CA string `json:"ca,omitempty" yaml:"ca,omitempty"`
52+
}
4753

4854
// NewValuesStorage build a new storage for module values
4955
//
@@ -173,6 +179,15 @@ func (vs *ValuesStorage) GetValues(withPrefix bool) utils.Values {
173179
return vs.resultValues
174180
}
175181

182+
func (vs *ValuesStorage) InjectRegistryValue(registry *Registry) {
183+
vs.lock.Lock()
184+
defer vs.lock.Unlock()
185+
186+
vs.schemaStorage.InjectRegistrySpec()
187+
188+
vs.resultValues["registry"] = registry
189+
}
190+
176191
// GetConfigValues returns only user defined values
177192
func (vs *ValuesStorage) GetConfigValues(withPrefix bool) utils.Values {
178193
vs.lock.Lock()

pkg/values/validation/schemas.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,36 @@ func validateObject(dataObj interface{}, s *spec.Schema, rootName string) error
160160
return allErrs.ErrorOrNil()
161161
}
162162

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 {
167+
return
168+
}
169+
170+
scheme.Properties["registry"] = spec.Schema{
171+
SchemaProps: spec.SchemaProps{
172+
Type: spec.StringOrArray{"object"},
173+
AdditionalProperties: &spec.SchemaOrBool{Allows: false},
174+
Properties: map[string]spec.Schema{
175+
"base": {
176+
SchemaProps: spec.SchemaProps{Type: spec.StringOrArray{"string"}, MinLength: swag.Int64(1)},
177+
},
178+
"dockercfg": {
179+
SchemaProps: spec.SchemaProps{Type: spec.StringOrArray{"string"}},
180+
},
181+
"scheme": {
182+
SchemaProps: spec.SchemaProps{Type: spec.StringOrArray{"string"}},
183+
},
184+
"ca": {
185+
SchemaProps: spec.SchemaProps{Type: spec.StringOrArray{"string"}},
186+
},
187+
},
188+
Required: []string{"base", "scheme"},
189+
},
190+
}
191+
}
192+
163193
// ModuleSchemasDescription describes which schemas are present in storage for the module.
164194
func (st *SchemaStorage) ModuleSchemasDescription() string {
165195
types := availableSchemaTypes(st.Schemas)

0 commit comments

Comments
 (0)