@@ -61,18 +61,15 @@ func (r *Storage) GetGRPCServiceEndpoint() string {
6161 return fmt .Sprintf ("%s:%d" , host , GRPCPort )
6262}
6363
64- // +k8s:deepcopy-gen=false
65- type PartialHostsConfig struct {
66- Hosts []schema.Host `yaml:"hosts,flow"`
67- }
68-
6964func (r * Storage ) GetHostFromConfigEndpoint () string {
65+ configuration := make (map [string ]interface {})
66+
7067 // skip handle error because we already checked in webhook
71- hostsConfig := PartialHostsConfig {}
72- _ = yaml . Unmarshal ([]byte ( r . Spec . Configuration ), & hostsConfig )
68+ _ = yaml . Unmarshal ([] byte ( r . Spec . Configuration ), & configuration )
69+ hostsConfig := configuration [ "hosts" ]. ([]schema. Host )
7370
7471 randNum := rand .Int31n (r .Spec .Nodes ) // #nosec G404
75- host := hostsConfig . Hosts [randNum ].Host
72+ host := hostsConfig [randNum ].Host
7673 return fmt .Sprintf ("%s:%d" , host , GRPCPort )
7774}
7875
@@ -97,15 +94,6 @@ func (r *Storage) IsRemoteNodeSetsOnly() bool {
9794 return true
9895}
9996
100- // +k8s:deepcopy-gen=false
101- type PartialDomainsConfig struct {
102- DomainsConfig struct {
103- SecurityConfig struct {
104- EnforceUserTokenRequirement bool `yaml:"enforce_user_token_requirement"`
105- } `yaml:"security_config"`
106- } `yaml:"domains_config"`
107- }
108-
10997// StorageDefaulter mutates Storages
11098// +k8s:deepcopy-gen=false
11199type StorageDefaulter struct {
@@ -119,6 +107,10 @@ func (r *StorageDefaulter) Default(ctx context.Context, obj runtime.Object) erro
119107 storage := obj .(* Storage )
120108 storagelog .Info ("default" , "name" , storage .Name )
121109
110+ if ! storage .Spec .OperatorSync {
111+ return nil
112+ }
113+
122114 if storage .Spec .Image == nil {
123115 storage .Spec .Image = & PodImage {}
124116 }
@@ -174,7 +166,7 @@ func (r *StorageDefaulter) Default(ctx context.Context, obj runtime.Object) erro
174166 if err != nil {
175167 return err
176168 }
177- storage .Spec .Configuration = configuration
169+ storage .Spec .Configuration = string ( configuration )
178170
179171 return nil
180172}
@@ -187,23 +179,28 @@ var _ webhook.Validator = &Storage{}
187179func (r * Storage ) ValidateCreate () error {
188180 storagelog .Info ("validate create" , "name" , r .Name )
189181
190- configuration := make (map [string ]interface {})
191- err := yaml .Unmarshal ([]byte (r .Spec .Configuration ), & configuration )
192- if err != nil {
193- return fmt .Errorf ("failed to parse .spec.configuration, error: %w" , err )
182+ var configuration schema.Configuration
183+
184+ rawYamlConfiguration := r .Spec .Configuration
185+ dynconfig , err := ParseDynconfig (r .Spec .Configuration )
186+ if err == nil {
187+ config , err := yaml .Marshal (dynconfig .Config )
188+ if err != nil {
189+ return fmt .Errorf ("failed to parse .config from dynconfig, error: %w" , err )
190+ }
191+ rawYamlConfiguration = string (config )
194192 }
195193
196- hostsConfig := PartialHostsConfig {}
197- err = yaml .Unmarshal ([]byte (r .Spec .Configuration ), & hostsConfig )
194+ configuration , err = ParseConfig (rawYamlConfiguration )
198195 if err != nil {
199- return fmt .Errorf ("failed to parse YAML to determine `hosts` , error: %w" , err )
196+ return fmt .Errorf ("failed to parse .spec.configuration , error: %w" , err )
200197 }
201198
202199 var nodesNumber int32
203- if len (hostsConfig .Hosts ) == 0 {
200+ if len (configuration .Hosts ) == 0 {
204201 nodesNumber = r .Spec .Nodes
205202 } else {
206- nodesNumber = int32 (len (hostsConfig .Hosts ))
203+ nodesNumber = int32 (len (configuration .Hosts ))
207204 }
208205
209206 minNodesPerErasure := map [ErasureType ]int32 {
@@ -215,15 +212,11 @@ func (r *Storage) ValidateCreate() error {
215212 return fmt .Errorf ("erasure type %v requires at least %v storage nodes" , r .Spec .Erasure , minNodesPerErasure [r .Spec .Erasure ])
216213 }
217214
218- yamlConfig := PartialDomainsConfig {}
219- err = yaml .Unmarshal ([]byte (r .Spec .Configuration ), & yamlConfig )
220- if err != nil {
221- return fmt .Errorf ("failed to parse YAML to determine `enforce_user_token_requirement`, error: %w" , err )
222- }
223-
224215 var authEnabled bool
225- if yamlConfig .DomainsConfig .SecurityConfig .EnforceUserTokenRequirement {
226- authEnabled = true
216+ if configuration .DomainsConfig .SecurityConfig != nil {
217+ if configuration .DomainsConfig .SecurityConfig .EnforceUserTokenRequirement != nil {
218+ authEnabled = * configuration .DomainsConfig .SecurityConfig .EnforceUserTokenRequirement
219+ }
227220 }
228221
229222 if (authEnabled && r .Spec .OperatorConnection == nil ) || (! authEnabled && r .Spec .OperatorConnection != nil ) {
@@ -285,23 +278,28 @@ func hasUpdatesBesidesFrozen(oldStorage, newStorage *Storage) (bool, string) {
285278func (r * Storage ) ValidateUpdate (old runtime.Object ) error {
286279 storagelog .Info ("validate update" , "name" , r .Name )
287280
288- configuration := make (map [string ]interface {})
289- err := yaml .Unmarshal ([]byte (r .Spec .Configuration ), & configuration )
290- if err != nil {
291- return fmt .Errorf ("failed to parse .spec.configuration, error: %w" , err )
281+ var configuration schema.Configuration
282+
283+ rawYamlConfiguration := r .Spec .Configuration
284+ dynconfig , err := ParseDynconfig (r .Spec .Configuration )
285+ if err == nil {
286+ config , err := yaml .Marshal (dynconfig .Config )
287+ if err != nil {
288+ return fmt .Errorf ("failed to parse .config from dynconfig, error: %w" , err )
289+ }
290+ rawYamlConfiguration = string (config )
292291 }
293292
294- hostsConfig := PartialHostsConfig {}
295- err = yaml .Unmarshal ([]byte (r .Spec .Configuration ), & hostsConfig )
293+ configuration , err = ParseConfig (rawYamlConfiguration )
296294 if err != nil {
297- return fmt .Errorf ("failed to parse YAML to determine `hosts` , error: %w" , err )
295+ return fmt .Errorf ("failed to parse .spec.configuration , error: %w" , err )
298296 }
299297
300298 var nodesNumber int32
301- if len (hostsConfig .Hosts ) == 0 {
299+ if len (configuration .Hosts ) == 0 {
302300 nodesNumber = r .Spec .Nodes
303301 } else {
304- nodesNumber = int32 (len (hostsConfig .Hosts ))
302+ nodesNumber = int32 (len (configuration .Hosts ))
305303 }
306304
307305 minNodesPerErasure := map [ErasureType ]int32 {
@@ -313,6 +311,17 @@ func (r *Storage) ValidateUpdate(old runtime.Object) error {
313311 return fmt .Errorf ("erasure type %v requires at least %v storage nodes" , r .Spec .Erasure , minNodesPerErasure [r .Spec .Erasure ])
314312 }
315313
314+ var authEnabled bool
315+ if configuration .DomainsConfig .SecurityConfig != nil {
316+ if configuration .DomainsConfig .SecurityConfig .EnforceUserTokenRequirement != nil {
317+ authEnabled = * configuration .DomainsConfig .SecurityConfig .EnforceUserTokenRequirement
318+ }
319+ }
320+
321+ if (authEnabled && r .Spec .OperatorConnection == nil ) || (! authEnabled && r .Spec .OperatorConnection != nil ) {
322+ return fmt .Errorf ("field 'spec.operatorConnection' does not align with config option `enforce_user_token_requirement: %t`" , authEnabled )
323+ }
324+
316325 if ! r .Spec .OperatorSync {
317326 oldStorage := old .(* Storage )
318327
@@ -331,21 +340,6 @@ func (r *Storage) ValidateUpdate(old runtime.Object) error {
331340 }
332341 }
333342
334- yamlConfig := PartialDomainsConfig {}
335- err = yaml .Unmarshal ([]byte (r .Spec .Configuration ), & yamlConfig )
336- if err != nil {
337- return fmt .Errorf ("failed to parse YAML to determine `enforce_user_token_requirement`, error: %w" , err )
338- }
339-
340- var authEnabled bool
341- if yamlConfig .DomainsConfig .SecurityConfig .EnforceUserTokenRequirement {
342- authEnabled = true
343- }
344-
345- if (authEnabled && r .Spec .OperatorConnection == nil ) || (! authEnabled && r .Spec .OperatorConnection != nil ) {
346- return fmt .Errorf ("field 'spec.operatorConnection' does not align with config option `enforce_user_token_requirement: %t`" , authEnabled )
347- }
348-
349343 if r .Spec .NodeSets != nil {
350344 var nodesInSetsCount int32
351345 for _ , nodeSetInline := range r .Spec .NodeSets {
0 commit comments