@@ -175,27 +175,28 @@ var _ webhook.Validator = &Storage{}
175175func (r * Storage ) ValidateCreate () error {
176176 storagelog .Info ("validate create" , "name" , r .Name )
177177
178- configuration := make (map [string ]interface {})
179- err := yaml .Unmarshal ([]byte (r .Spec .Configuration ), & configuration )
180- if err != nil {
181- return fmt .Errorf ("failed to parse .spec.configuration, error: %w" , err )
182- }
178+ var configuration schema.Configuration
183179
184- dynConfig , err := ParseDynconfig (r .Spec .Configuration )
180+ rawYamlConfiguration := r .Spec .Configuration
181+ dynconfig , err := ParseDynconfig (r .Spec .Configuration )
185182 if err == nil {
186- configuration = dynConfig .Config
183+ config , err := yaml .Marshal (dynconfig .Config )
184+ if err != nil {
185+ return fmt .Errorf ("failed to parse .config from dynconfig, error: %w" , err )
186+ }
187+ rawYamlConfiguration = string (config )
187188 }
188189
189- hostsConfig , ok := configuration [ "hosts" ].([]schema. Host )
190- if ! ok {
191- return fmt .Errorf ("failed to parse YAML to determine `hosts`" )
190+ configuration , err = ParseConfig ( rawYamlConfiguration )
191+ if err != nil {
192+ return fmt .Errorf ("failed to parse .spec.configuration, error: %w" , err )
192193 }
193194
194195 var nodesNumber int32
195- if len (hostsConfig ) == 0 {
196+ if len (configuration . Hosts ) == 0 {
196197 nodesNumber = r .Spec .Nodes
197198 } else {
198- nodesNumber = int32 (len (hostsConfig ))
199+ nodesNumber = int32 (len (configuration . Hosts ))
199200 }
200201
201202 minNodesPerErasure := map [ErasureType ]int32 {
@@ -207,13 +208,8 @@ func (r *Storage) ValidateCreate() error {
207208 return fmt .Errorf ("erasure type %v requires at least %v storage nodes" , r .Spec .Erasure , minNodesPerErasure [r .Spec .Erasure ])
208209 }
209210
210- domainsConfig , ok := configuration ["domains_config" ].(schema.DomainsConfig )
211- if ! ok {
212- return fmt .Errorf ("failed to parse YAML to determine `domains_config`" )
213- }
214-
215211 var authEnabled bool
216- if domainsConfig .SecurityConfig .EnforceUserTokenRequirement {
212+ if configuration . DomainsConfig .SecurityConfig .EnforceUserTokenRequirement {
217213 authEnabled = true
218214 }
219215
@@ -276,27 +272,28 @@ func hasUpdatesBesidesFrozen(oldStorage, newStorage *Storage) (bool, string) {
276272func (r * Storage ) ValidateUpdate (old runtime.Object ) error {
277273 storagelog .Info ("validate update" , "name" , r .Name )
278274
279- configuration := make (map [string ]interface {})
280- err := yaml .Unmarshal ([]byte (r .Spec .Configuration ), & configuration )
281- if err != nil {
282- return fmt .Errorf ("failed to parse .spec.configuration, error: %w" , err )
283- }
275+ var configuration schema.Configuration
284276
285- dynConfig , err := ParseDynconfig (r .Spec .Configuration )
277+ rawYamlConfiguration := r .Spec .Configuration
278+ dynconfig , err := ParseDynconfig (r .Spec .Configuration )
286279 if err == nil {
287- configuration = dynConfig .Config
280+ config , err := yaml .Marshal (dynconfig .Config )
281+ if err != nil {
282+ return fmt .Errorf ("failed to parse .config from dynconfig, error: %w" , err )
283+ }
284+ rawYamlConfiguration = string (config )
288285 }
289286
290- hostsConfig , ok := configuration [ "hosts" ].([]schema. Host )
291- if ! ok {
292- return fmt .Errorf ("failed to parse YAML to determine `hosts`" )
287+ configuration , err = ParseConfig ( rawYamlConfiguration )
288+ if err != nil {
289+ return fmt .Errorf ("failed to parse .spec.configuration, error: %w" , err )
293290 }
294291
295292 var nodesNumber int32
296- if len (hostsConfig ) == 0 {
293+ if len (configuration . Hosts ) == 0 {
297294 nodesNumber = r .Spec .Nodes
298295 } else {
299- nodesNumber = int32 (len (hostsConfig ))
296+ nodesNumber = int32 (len (configuration . Hosts ))
300297 }
301298
302299 minNodesPerErasure := map [ErasureType ]int32 {
@@ -308,13 +305,8 @@ func (r *Storage) ValidateUpdate(old runtime.Object) error {
308305 return fmt .Errorf ("erasure type %v requires at least %v storage nodes" , r .Spec .Erasure , minNodesPerErasure [r .Spec .Erasure ])
309306 }
310307
311- domainsConfig , ok := configuration ["domains_config" ].(schema.DomainsConfig )
312- if ! ok {
313- return fmt .Errorf ("failed to parse YAML to determine `domains_config`" )
314- }
315-
316308 var authEnabled bool
317- if domainsConfig .SecurityConfig .EnforceUserTokenRequirement {
309+ if configuration . DomainsConfig .SecurityConfig .EnforceUserTokenRequirement {
318310 authEnabled = true
319311 }
320312
0 commit comments