|
7 | 7 |
|
8 | 8 | "github.com/google/go-cmp/cmp" |
9 | 9 | "github.com/google/go-cmp/cmp/cmpopts" |
10 | | - "gopkg.in/yaml.v3" |
11 | 10 | corev1 "k8s.io/api/core/v1" |
12 | 11 | "k8s.io/apimachinery/pkg/runtime" |
13 | 12 | "k8s.io/utils/strings/slices" |
@@ -62,15 +61,12 @@ func (r *Storage) GetGRPCServiceEndpoint() string { |
62 | 61 | } |
63 | 62 |
|
64 | 63 | func (r *Storage) GetHostFromConfigEndpoint() string { |
65 | | - configuration := make(map[string]interface{}) |
| 64 | + var configuration schema.Configuration |
66 | 65 |
|
67 | 66 | // skip handle error because we already checked in webhook |
68 | | - _ = yaml.Unmarshal([]byte(r.Spec.Configuration), &configuration) |
69 | | - hostsConfig := configuration["hosts"].([]schema.Host) |
70 | | - |
71 | | - randNum := rand.Int31n(r.Spec.Nodes) // #nosec G404 |
72 | | - host := hostsConfig[randNum].Host |
73 | | - return fmt.Sprintf("%s:%d", host, GRPCPort) |
| 67 | + configuration, _ = ParseConfiguration(r.Spec.Configuration) |
| 68 | + randNum := rand.Intn(len(configuration.Hosts)) // #nosec G404 |
| 69 | + return fmt.Sprintf("%s:%d", configuration.Hosts[randNum].Host, GRPCPort) |
74 | 70 | } |
75 | 71 |
|
76 | 72 | func (r *Storage) IsStorageEndpointSecure() bool { |
@@ -181,19 +177,9 @@ func (r *Storage) ValidateCreate() error { |
181 | 177 |
|
182 | 178 | var configuration schema.Configuration |
183 | 179 |
|
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) |
192 | | - } |
193 | | - |
194 | | - configuration, err = ParseConfig(rawYamlConfiguration) |
| 180 | + configuration, err := ParseConfiguration(r.Spec.Configuration) |
195 | 181 | if err != nil { |
196 | | - return fmt.Errorf("failed to parse .spec.configuration, error: %w", err) |
| 182 | + return fmt.Errorf("failed to parse configuration, error: %w", err) |
197 | 183 | } |
198 | 184 |
|
199 | 185 | var nodesNumber int32 |
@@ -278,21 +264,9 @@ func hasUpdatesBesidesFrozen(oldStorage, newStorage *Storage) (bool, string) { |
278 | 264 | func (r *Storage) ValidateUpdate(old runtime.Object) error { |
279 | 265 | storagelog.Info("validate update", "name", r.Name) |
280 | 266 |
|
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) |
291 | | - } |
292 | | - |
293 | | - configuration, err = ParseConfig(rawYamlConfiguration) |
| 267 | + configuration, err := ParseConfiguration(r.Spec.Configuration) |
294 | 268 | if err != nil { |
295 | | - return fmt.Errorf("failed to parse .spec.configuration, error: %w", err) |
| 269 | + return fmt.Errorf("failed to parse configuration, error: %w", err) |
296 | 270 | } |
297 | 271 |
|
298 | 272 | var nodesNumber int32 |
|
0 commit comments