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