@@ -61,18 +61,15 @@ func (r *Storage) GetGRPCServiceEndpoint() string {
61
61
return fmt .Sprintf ("%s:%d" , host , GRPCPort )
62
62
}
63
63
64
- // +k8s:deepcopy-gen=false
65
- type PartialHostsConfig struct {
66
- Hosts []schema.Host `yaml:"hosts,flow"`
67
- }
68
-
69
64
func (r * Storage ) GetHostFromConfigEndpoint () string {
65
+ configuration := make (map [string ]interface {})
66
+
70
67
// 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 )
73
70
74
71
randNum := rand .Int31n (r .Spec .Nodes ) // #nosec G404
75
- host := hostsConfig . Hosts [randNum ].Host
72
+ host := hostsConfig [randNum ].Host
76
73
return fmt .Sprintf ("%s:%d" , host , GRPCPort )
77
74
}
78
75
@@ -97,15 +94,6 @@ func (r *Storage) IsRemoteNodeSetsOnly() bool {
97
94
return true
98
95
}
99
96
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
-
109
97
// StorageDefaulter mutates Storages
110
98
// +k8s:deepcopy-gen=false
111
99
type StorageDefaulter struct {
@@ -119,6 +107,10 @@ func (r *StorageDefaulter) Default(ctx context.Context, obj runtime.Object) erro
119
107
storage := obj .(* Storage )
120
108
storagelog .Info ("default" , "name" , storage .Name )
121
109
110
+ if ! storage .Spec .OperatorSync {
111
+ return nil
112
+ }
113
+
122
114
if storage .Spec .Image == nil {
123
115
storage .Spec .Image = & PodImage {}
124
116
}
@@ -174,7 +166,7 @@ func (r *StorageDefaulter) Default(ctx context.Context, obj runtime.Object) erro
174
166
if err != nil {
175
167
return err
176
168
}
177
- storage .Spec .Configuration = configuration
169
+ storage .Spec .Configuration = string ( configuration )
178
170
179
171
return nil
180
172
}
@@ -187,23 +179,28 @@ var _ webhook.Validator = &Storage{}
187
179
func (r * Storage ) ValidateCreate () error {
188
180
storagelog .Info ("validate create" , "name" , r .Name )
189
181
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 )
194
192
}
195
193
196
- hostsConfig := PartialHostsConfig {}
197
- err = yaml .Unmarshal ([]byte (r .Spec .Configuration ), & hostsConfig )
194
+ configuration , err = ParseConfig (rawYamlConfiguration )
198
195
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 )
200
197
}
201
198
202
199
var nodesNumber int32
203
- if len (hostsConfig .Hosts ) == 0 {
200
+ if len (configuration .Hosts ) == 0 {
204
201
nodesNumber = r .Spec .Nodes
205
202
} else {
206
- nodesNumber = int32 (len (hostsConfig .Hosts ))
203
+ nodesNumber = int32 (len (configuration .Hosts ))
207
204
}
208
205
209
206
minNodesPerErasure := map [ErasureType ]int32 {
@@ -215,15 +212,11 @@ func (r *Storage) ValidateCreate() error {
215
212
return fmt .Errorf ("erasure type %v requires at least %v storage nodes" , r .Spec .Erasure , minNodesPerErasure [r .Spec .Erasure ])
216
213
}
217
214
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
-
224
215
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
+ }
227
220
}
228
221
229
222
if (authEnabled && r .Spec .OperatorConnection == nil ) || (! authEnabled && r .Spec .OperatorConnection != nil ) {
@@ -285,23 +278,28 @@ func hasUpdatesBesidesFrozen(oldStorage, newStorage *Storage) (bool, string) {
285
278
func (r * Storage ) ValidateUpdate (old runtime.Object ) error {
286
279
storagelog .Info ("validate update" , "name" , r .Name )
287
280
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 )
292
291
}
293
292
294
- hostsConfig := PartialHostsConfig {}
295
- err = yaml .Unmarshal ([]byte (r .Spec .Configuration ), & hostsConfig )
293
+ configuration , err = ParseConfig (rawYamlConfiguration )
296
294
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 )
298
296
}
299
297
300
298
var nodesNumber int32
301
- if len (hostsConfig .Hosts ) == 0 {
299
+ if len (configuration .Hosts ) == 0 {
302
300
nodesNumber = r .Spec .Nodes
303
301
} else {
304
- nodesNumber = int32 (len (hostsConfig .Hosts ))
302
+ nodesNumber = int32 (len (configuration .Hosts ))
305
303
}
306
304
307
305
minNodesPerErasure := map [ErasureType ]int32 {
@@ -313,6 +311,17 @@ func (r *Storage) ValidateUpdate(old runtime.Object) error {
313
311
return fmt .Errorf ("erasure type %v requires at least %v storage nodes" , r .Spec .Erasure , minNodesPerErasure [r .Spec .Erasure ])
314
312
}
315
313
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
+
316
325
if ! r .Spec .OperatorSync {
317
326
oldStorage := old .(* Storage )
318
327
@@ -331,21 +340,6 @@ func (r *Storage) ValidateUpdate(old runtime.Object) error {
331
340
}
332
341
}
333
342
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
-
349
343
if r .Spec .NodeSets != nil {
350
344
var nodesInSetsCount int32
351
345
for _ , nodeSetInline := range r .Spec .NodeSets {
0 commit comments