Skip to content

Commit 2ac943b

Browse files
authored
Support override with Database.configuration (#93)
* feat: support db overwrite * refactor: better naming for config generation * chore: bump up chart version * refactor: concise Build signature * tweak: slightly increase timeout limits on e2e
1 parent 8b1a171 commit 2ac943b

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

.github/workflows/e2e.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ jobs:
7777
# TODO namespace and labels are hardcoded in the next command, that is duplication.
7878
# We should get the label and its value from ./e2e/manifests/*.yaml
7979
kubectl wait --timeout=15m --for=condition=storageinitialized=true storage -n ydb ycydb
80-
kubectl wait --timeout=5m --for=condition=ready pod -n ydb -l ydb-cluster=kind-storage
80+
kubectl wait --timeout=10m --for=condition=ready pod -n ydb -l ydb-cluster=kind-storage
8181
82-
kubectl wait --timeout=5m --for=condition=tenantinitialized=true database -n ydb database
83-
kubectl wait --timeout=5m --for=condition=ready pod -n ydb -l ydb-cluster=kind-database
82+
kubectl wait --timeout=10m --for=condition=tenantinitialized=true database -n ydb database
83+
kubectl wait --timeout=10m --for=condition=ready pod -n ydb -l ydb-cluster=kind-database
8484
8585
# Something as a reference for a more complicated check later. Be careful with the yaml indentation!
8686
# while true; do

deploy/ydb-operator/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.4.17
18+
version: 0.4.18
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
2323
# It is recommended to use it with quotes.
24-
appVersion: "0.4.17"
24+
appVersion: "0.4.18"

internal/configuration/configuration.go

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func hash(text string) string {
2525
return fmt.Sprintf("%x", h.Sum(nil))
2626
}
2727

28-
func generate(cr *v1alpha1.Storage, crDB *v1alpha1.Database) schema.Configuration {
28+
func generateSomeDefaults(cr *v1alpha1.Storage, crDB *v1alpha1.Database) schema.Configuration {
2929
var hosts []schema.Host
3030

3131
for i := 0; i < int(cr.Spec.Nodes); i++ {
@@ -67,23 +67,41 @@ func generate(cr *v1alpha1.Storage, crDB *v1alpha1.Database) schema.Configuratio
6767
}
6868
}
6969

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+
7082
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+
}
7395

74-
err := yaml.Unmarshal([]byte(cr.Spec.Configuration), &crdConfig)
96+
err := yaml.Unmarshal([]byte(rawYamlConfiguration), &config)
7597
if err != nil {
7698
return nil, err
7799
}
78100

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)
85103

86-
data, err := yaml.Marshal(crdConfig)
104+
data, err := yaml.Marshal(config)
87105
if err != nil {
88106
return nil, err
89107
}

0 commit comments

Comments
 (0)