-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathconfiguration.go
55 lines (44 loc) · 1.16 KB
/
configuration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package configuration
import (
"fmt"
"strconv"
"github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
"github.com/ydb-platform/ydb-kubernetes-operator/internal/configuration/schema"
"gopkg.in/yaml.v3"
)
func generate(cr *v1alpha1.Storage) schema.Configuration {
var hosts []schema.Host
for i := 0; i < int(cr.Spec.Nodes); i++ {
hosts = append(hosts, schema.Host{
Host: fmt.Sprintf("%v-%d", cr.GetName(), i),
HostConfigID: 1, // TODO
NodeID: i + 1,
Port: v1alpha1.InterconnectPort,
WalleLocation: schema.WalleLocation{
Body: 12340 + i,
DataCenter: "az-1",
Rack: strconv.Itoa(i),
},
})
}
return schema.Configuration{
Hosts: hosts,
}
}
func Build(cr *v1alpha1.Storage) (map[string]string, error) {
var crdConfig map[string]interface{}
generatedConfig := generate(cr)
err := yaml.Unmarshal([]byte(cr.Spec.Configuration), &crdConfig)
if err != nil {
return nil, err
}
crdConfig["hosts"] = generatedConfig.Hosts
data, err := yaml.Marshal(crdConfig)
if err != nil {
return nil, err
}
result := string(data)
return map[string]string{
v1alpha1.ConfigFileName: result,
}, nil
}