@@ -25,7 +25,7 @@ func hash(text string) string {
25
25
return fmt .Sprintf ("%x" , h .Sum (nil ))
26
26
}
27
27
28
- func generate (cr * v1alpha1.Storage , crDB * v1alpha1.Database ) schema.Configuration {
28
+ func generateSomeDefaults (cr * v1alpha1.Storage , crDB * v1alpha1.Database ) schema.Configuration {
29
29
var hosts []schema.Host
30
30
31
31
for i := 0 ; i < int (cr .Spec .Nodes ); i ++ {
@@ -67,23 +67,41 @@ func generate(cr *v1alpha1.Storage, crDB *v1alpha1.Database) schema.Configuratio
67
67
}
68
68
}
69
69
70
+ func tryFillMissingSections (
71
+ resultConfig map [string ]interface {},
72
+ generatedConfig schema.Configuration ,
73
+ ) {
74
+ if resultConfig ["hosts" ] == nil {
75
+ resultConfig ["hosts" ] = generatedConfig .Hosts
76
+ }
77
+ if generatedConfig .KeyConfig != nil {
78
+ resultConfig ["key_config" ] = generatedConfig .KeyConfig
79
+ }
80
+ }
81
+
70
82
func Build (cr * v1alpha1.Storage , crDB * v1alpha1.Database ) (map [string ]string , error ) {
71
- crdConfig := make (map [string ]interface {})
72
- generatedConfig := generate (cr , crDB )
83
+ config := make (map [string ]interface {})
84
+
85
+ // If any kind of configuration exists on Database object, then
86
+ // it will be used to fully override storage object.
87
+ // This is a temporary solution that should go away when it would
88
+ // be possible to override Database configuration partially.
89
+ var rawYamlConfiguration string
90
+ if crDB != nil && crDB .Spec .Configuration != "" {
91
+ rawYamlConfiguration = crDB .Spec .Configuration
92
+ } else {
93
+ rawYamlConfiguration = cr .Spec .Configuration
94
+ }
73
95
74
- err := yaml .Unmarshal ([]byte (cr . Spec . Configuration ), & crdConfig )
96
+ err := yaml .Unmarshal ([]byte (rawYamlConfiguration ), & config )
75
97
if err != nil {
76
98
return nil , err
77
99
}
78
100
79
- if crdConfig ["hosts" ] == nil {
80
- crdConfig ["hosts" ] = generatedConfig .Hosts
81
- }
82
- if generatedConfig .KeyConfig != nil {
83
- crdConfig ["key_config" ] = generatedConfig .KeyConfig
84
- }
101
+ generatedConfig := generateSomeDefaults (cr , crDB )
102
+ tryFillMissingSections (config , generatedConfig )
85
103
86
- data , err := yaml .Marshal (crdConfig )
104
+ data , err := yaml .Marshal (config )
87
105
if err != nil {
88
106
return nil , err
89
107
}
0 commit comments