Skip to content

Commit 86982f3

Browse files
authored
YDBOPS-9635 use configMap from Storage if Database .spec.configuration empty (#199)
1 parent d9edaeb commit 86982f3

File tree

6 files changed

+43
-26
lines changed

6 files changed

+43
-26
lines changed

api/v1alpha1/database_webhook.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,13 @@ func (r *DatabaseDefaulter) Default(ctx context.Context, obj runtime.Object) err
141141
database.Spec.StorageEndpoint = storage.GetStorageEndpointWithProto()
142142
}
143143

144-
configuration, err := buildConfiguration(storage, database)
145-
if err != nil {
146-
return err
144+
if database.Spec.Configuration != "" || (database.Spec.Encryption != nil && database.Spec.Encryption.Enabled) {
145+
configuration, err := buildConfiguration(storage, database)
146+
if err != nil {
147+
return err
148+
}
149+
database.Spec.Configuration = configuration
147150
}
148-
database.Spec.Configuration = configuration
149151

150152
return nil
151153
}

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.5.6
18+
version: 0.5.7
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.5.6"
24+
appVersion: "0.5.7"

internal/controllers/remotedatabasenodeset/controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ var _ = Describe("RemoteDatabaseNodeSet controller tests", func() {
759759

760760
foundConfigMap := corev1.ConfigMap{}
761761
Expect(remoteClient.Get(ctx, types.NamespacedName{
762-
Name: databaseSample.Name,
762+
Name: storageSample.Name,
763763
Namespace: testobjects.YdbNamespace,
764764
}, &foundConfigMap)).Should(Succeed())
765765

@@ -791,7 +791,7 @@ var _ = Describe("RemoteDatabaseNodeSet controller tests", func() {
791791

792792
foundConfigMap := corev1.ConfigMap{}
793793
Expect(remoteClient.Get(ctx, types.NamespacedName{
794-
Name: databaseSample.Name,
794+
Name: storageSample.Name,
795795
Namespace: testobjects.YdbNamespace,
796796
}, &foundConfigMap)).Should(Succeed())
797797

internal/resources/database.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,20 @@ func (b *DatabaseBuilder) GetResourceBuilders(restConfig *rest.Config) []Resourc
7272

7373
var optionalBuilders []ResourceBuilder
7474

75-
optionalBuilders = append(
76-
optionalBuilders,
77-
&ConfigMapBuilder{
78-
Object: b,
75+
if b.Spec.Configuration != "" {
76+
optionalBuilders = append(
77+
optionalBuilders,
78+
&ConfigMapBuilder{
79+
Object: b,
7980

80-
Name: b.GetName(),
81-
Data: map[string]string{
82-
api.ConfigFileName: b.Spec.Configuration,
81+
Name: b.GetName(),
82+
Data: map[string]string{
83+
api.ConfigFileName: b.Spec.Configuration,
84+
},
85+
Labels: databaseLabels,
8386
},
84-
Labels: databaseLabels,
85-
},
86-
)
87+
)
88+
}
8789

8890
if b.Spec.Monitoring != nil && b.Spec.Monitoring.Enabled {
8991
optionalBuilders = append(optionalBuilders,

internal/resources/database_statefulset.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ func (b *DatabaseStatefulSetBuilder) buildPodTemplateSpec() corev1.PodTemplateSp
144144
}
145145

146146
func (b *DatabaseStatefulSetBuilder) buildVolumes() []corev1.Volume {
147-
configMapName := b.Database.Name
147+
configMapName := b.Spec.StorageClusterRef.Name
148+
if b.Spec.Configuration != "" {
149+
configMapName = b.GetName()
150+
}
148151

149152
volumes := []corev1.Volume{
150153
{

internal/resources/remotedatabasenodeset.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,23 @@ func (b *RemoteDatabaseNodeSetResource) GetRemoteObjects(
102102
}
103103

104104
// sync ConfigMap
105-
remoteObjects = append(remoteObjects,
106-
&corev1.ConfigMap{
107-
ObjectMeta: metav1.ObjectMeta{
108-
Name: b.Spec.DatabaseRef.Name,
109-
Namespace: b.Namespace,
110-
},
111-
})
105+
if b.Spec.Configuration != "" {
106+
remoteObjects = append(remoteObjects,
107+
&corev1.ConfigMap{
108+
ObjectMeta: metav1.ObjectMeta{
109+
Name: b.Spec.DatabaseRef.Name,
110+
Namespace: b.Namespace,
111+
},
112+
})
113+
} else {
114+
remoteObjects = append(remoteObjects,
115+
&corev1.ConfigMap{
116+
ObjectMeta: metav1.ObjectMeta{
117+
Name: b.Spec.StorageClusterRef.Name,
118+
Namespace: b.Namespace,
119+
},
120+
})
121+
}
112122

113123
// sync Services
114124
remoteObjects = append(remoteObjects,

0 commit comments

Comments
 (0)