Skip to content

Commit c7ea72e

Browse files
Konstantin Bogdanovthevar1able
Konstantin Bogdanov
authored andcommitted
Use new configuration flow
1 parent bca0dff commit c7ea72e

File tree

11 files changed

+91
-147
lines changed

11 files changed

+91
-147
lines changed

api/v1alpha1/const.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ const (
2121
DiskNumberMaxDigits = 2
2222
DiskFilePath = "/data"
2323

24-
ConfigDir = "/opt/kikimr/cfg"
24+
ConfigDir = "/opt/ydb/cfg"
25+
ConfigFileName = "config.yaml"
26+
27+
BinariesDir = "/opt/ydb/bin"
28+
DaemonBinaryName = "ybdd"
2529

26-
DefaultDomain = "root"
2730
TenantNameFormat = "/%s/%s"
2831
)
2932

api/v1alpha1/database_types.go

+5
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ type DatabaseSpec struct {
1313

1414
// ConfigMap name with custom YDB configuration, where key is config file name and value is config file content.
1515
// +optional
16+
// +deprecated
1617
ClusterConfig string `json:"config,omitempty"`
1718

19+
// YDB configuration in YAML format. Will be applied on top of generated one in internal/configuration
20+
// +optional
21+
Configuration string `json:"configuration"`
22+
1823
// (Optional) Storage services parameter overrides
1924
// Default: (not specified)
2025
// +optional

api/v1alpha1/storage_types.go

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type StorageSpec struct {
1717
ClusterConfig string `json:"config,omitempty"`
1818

1919
// YDB configuration in YAML format. Will be applied on top of generated one in internal/configuration
20+
// +optional
2021
Configuration string `json:"configuration"`
2122

2223
// Data storage mode.

deploy/ydb-operator/crds/database.yaml

+8-1
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,10 @@ spec:
879879
description: ConfigMap name with custom YDB configuration, where key
880880
is config file name and value is config file content.
881881
type: string
882+
configuration:
883+
description: YDB configuration in YAML format. Will be applied on
884+
top of generated one in internal/configuration
885+
type: string
882886
domain:
883887
default: root
884888
description: '(Optional) Name of the root storage domain Default:
@@ -3440,6 +3444,10 @@ spec:
34403444
type: array
34413445
type: object
34423446
type: object
3447+
config:
3448+
description: ConfigMap name with custom YDB configuration, where
3449+
key is config file name and value is config file content.
3450+
type: string
34433451
configuration:
34443452
description: YDB configuration in YAML format. Will be applied
34453453
on top of generated one in internal/configuration
@@ -5195,7 +5203,6 @@ spec:
51955203
of the YDB image Default: ""'
51965204
type: string
51975205
required:
5198-
- configuration
51995206
- dataStore
52005207
- erasure
52015208
- nodes

deploy/ydb-operator/crds/storage.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,10 @@ spec:
875875
type: array
876876
type: object
877877
type: object
878+
config:
879+
description: ConfigMap name with custom YDB configuration, where key
880+
is config file name and value is config file content.
881+
type: string
878882
configuration:
879883
description: YDB configuration in YAML format. Will be applied on
880884
top of generated one in internal/configuration
@@ -2585,7 +2589,6 @@ spec:
25852589
YDB image Default: ""'
25862590
type: string
25872591
required:
2588-
- configuration
25892592
- dataStore
25902593
- erasure
25912594
- nodes

internal/controllers/storage/init.go

+6-91
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,15 @@ package storage
33
import (
44
"context"
55
"fmt"
6-
"path"
76

87
"github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
98
"github.com/ydb-platform/ydb-kubernetes-operator/internal/exec"
109
"github.com/ydb-platform/ydb-kubernetes-operator/internal/resources"
11-
corev1 "k8s.io/api/core/v1"
12-
"k8s.io/apimachinery/pkg/api/errors"
1310
"k8s.io/apimachinery/pkg/api/meta"
1411
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15-
"k8s.io/apimachinery/pkg/types"
1612
ctrl "sigs.k8s.io/controller-runtime"
1713
)
1814

19-
const (
20-
InitStorageScript = "init_storage.bash"
21-
InitRootStorageScript = "init_root_storage.bash"
22-
InitCMSScript = "init_cms.bash"
23-
)
24-
2515
func (r *StorageReconciler) setInitialStatus(ctx context.Context, storage *resources.StorageClusterBuilder) (bool, ctrl.Result, error) {
2616
r.Log.Info("running step setInitialStatus")
2717
var changed bool = false
@@ -43,56 +33,6 @@ func (r *StorageReconciler) setInitialStatus(ctx context.Context, storage *resou
4333
})
4434
changed = true
4535
}
46-
if meta.FindStatusCondition(storage.Status.Conditions, InitCMSStepCondition) == nil {
47-
meta.SetStatusCondition(&storage.Status.Conditions, metav1.Condition{
48-
Type: InitCMSStepCondition,
49-
Status: "False",
50-
Reason: InitCMSStepReasonInProgress,
51-
Message: "InitCMSStep is required",
52-
})
53-
changed = true
54-
}
55-
if meta.FindStatusCondition(storage.Status.Conditions, InitRootStorageStepCondition) == nil {
56-
configMapName := storage.Name
57-
//if storage.Spec.ClusterConfig != "" {
58-
// configMapName = storage.Spec.ClusterConfig
59-
//}
60-
configMap := &corev1.ConfigMap{}
61-
err := r.Get(ctx, types.NamespacedName{
62-
Name: configMapName,
63-
Namespace: storage.Namespace,
64-
}, configMap)
65-
66-
if err != nil {
67-
if !errors.IsNotFound(err) {
68-
r.Recorder.Event(
69-
storage,
70-
corev1.EventTypeNormal,
71-
"Syncing",
72-
fmt.Sprintf("Failed to get ConfigMap: %s", err),
73-
)
74-
}
75-
return Stop, ctrl.Result{RequeueAfter: DefaultRequeueDelay}, err
76-
}
77-
78-
if _, ok := configMap.Data[InitRootStorageScript]; ok {
79-
meta.SetStatusCondition(&storage.Status.Conditions, metav1.Condition{
80-
Type: InitRootStorageStepCondition,
81-
Status: "False",
82-
Reason: InitRootStorageStepReasonInProgress,
83-
Message: fmt.Sprintf("InitRootStorageStep is required, %s script is specified in ConfigMap: %s", InitRootStorageScript, configMapName),
84-
})
85-
changed = true
86-
} else {
87-
meta.SetStatusCondition(&storage.Status.Conditions, metav1.Condition{
88-
Type: InitRootStorageStepCondition,
89-
Status: "True",
90-
Reason: InitRootStorageStepReasonNotRequired,
91-
Message: "InitRootStorageStep is not required",
92-
})
93-
changed = true
94-
}
95-
}
9636
if storage.Status.State != string(Initializing) {
9737
storage.Status.State = string(Initializing)
9838
changed = true
@@ -108,7 +48,12 @@ func (r *StorageReconciler) runInitScripts(ctx context.Context, storage *resourc
10848
podName := fmt.Sprintf("%s-0", storage.Name)
10949

11050
if !meta.IsStatusConditionTrue(storage.Status.Conditions, InitStorageStepCondition) {
111-
cmd := []string{"/bin/bash", path.Join(v1alpha1.ConfigDir, InitStorageScript)}
51+
cmd := []string{
52+
fmt.Sprintf("%s/%s", v1alpha1.BinariesDir, v1alpha1.DaemonBinaryName),
53+
"admin", "blobstorage", "config", "init",
54+
"--yaml-file",
55+
fmt.Sprintf("%s/%s", v1alpha1.ConfigDir, v1alpha1.ConfigFileName),
56+
}
11257
_, _, err := exec.ExecInPod(r.Scheme, r.Config, storage.Namespace, podName, "ydb-storage", cmd)
11358
if err != nil {
11459
return Stop, ctrl.Result{RequeueAfter: StorageInitializationRequeueDelay}, err
@@ -122,36 +67,6 @@ func (r *StorageReconciler) runInitScripts(ctx context.Context, storage *resourc
12267
return r.setState(ctx, storage)
12368
}
12469

125-
if !meta.IsStatusConditionTrue(storage.Status.Conditions, InitRootStorageStepCondition) {
126-
cmd := []string{"/bin/bash", path.Join(v1alpha1.ConfigDir, InitRootStorageScript)}
127-
_, _, err := exec.ExecInPod(r.Scheme, r.Config, storage.Namespace, podName, "ydb-storage", cmd)
128-
if err != nil {
129-
return Stop, ctrl.Result{RequeueAfter: StorageInitializationRequeueDelay}, err
130-
}
131-
meta.SetStatusCondition(&storage.Status.Conditions, metav1.Condition{
132-
Type: InitRootStorageStepCondition,
133-
Status: "True",
134-
Reason: InitRootStorageStepReasonCompleted,
135-
Message: "InitRootStorageStep completed successfully",
136-
})
137-
return r.setState(ctx, storage)
138-
}
139-
140-
if !meta.IsStatusConditionTrue(storage.Status.Conditions, InitCMSStepCondition) {
141-
cmd := []string{"/bin/bash", path.Join(v1alpha1.ConfigDir, InitCMSScript)}
142-
_, _, err := exec.ExecInPod(r.Scheme, r.Config, storage.Namespace, podName, "ydb-storage", cmd)
143-
if err != nil {
144-
return Stop, ctrl.Result{RequeueAfter: StorageInitializationRequeueDelay}, err
145-
}
146-
meta.SetStatusCondition(&storage.Status.Conditions, metav1.Condition{
147-
Type: InitCMSStepCondition,
148-
Status: "True",
149-
Reason: InitCMSStepReasonCompleted,
150-
Message: "InitCMSStep completed successfully",
151-
})
152-
return r.setState(ctx, storage)
153-
}
154-
15570
meta.SetStatusCondition(&storage.Status.Conditions, metav1.Condition{
15671
Type: StorageInitializedCondition,
15772
Status: "True",

internal/controllers/storage/sync.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (r *StorageReconciler) Sync(ctx context.Context, cr *ydbv1alpha1.Storage) (
6363
var result ctrl.Result
6464
var err error
6565

66-
storage := resources.NewCluster(cr, r.Log)
66+
storage := resources.NewCluster(cr)
6767
storage.SetStatusOnFirstReconcile()
6868

6969
stop, result, err = r.handleResourcesSync(ctx, &storage)
@@ -79,7 +79,7 @@ func (r *StorageReconciler) Sync(ctx context.Context, cr *ydbv1alpha1.Storage) (
7979
if stop {
8080
return result, err
8181
}
82-
stop, result, err = r.runSelfCheck(ctx, &storage, true)
82+
stop, result, err = r.runSelfCheck(ctx, &storage, false)
8383
if stop {
8484
return result, err
8585
}
@@ -166,12 +166,12 @@ func (r *StorageReconciler) handleResourcesSync(ctx context.Context, storage *re
166166
r.Log.Info("running step handleResourcesSync")
167167

168168
for _, builder := range storage.GetResourceBuilders() {
169-
new_resource := builder.Placeholder(storage)
169+
newResource := builder.Placeholder(storage)
170170

171-
result, err := resources.CreateOrUpdateIgnoreStatus(ctx, r.Client, new_resource, func() error {
171+
result, err := resources.CreateOrUpdateIgnoreStatus(ctx, r.Client, newResource, func() error {
172172
var err error
173173

174-
err = builder.Build(new_resource)
174+
err = builder.Build(newResource)
175175
if err != nil {
176176
r.Recorder.Event(
177177
storage,
@@ -181,7 +181,7 @@ func (r *StorageReconciler) handleResourcesSync(ctx context.Context, storage *re
181181
)
182182
return err
183183
}
184-
err = ctrl.SetControllerReference(storage.Unwrap(), new_resource, r.Scheme)
184+
err = ctrl.SetControllerReference(storage.Unwrap(), newResource, r.Scheme)
185185
if err != nil {
186186
r.Recorder.Event(
187187
storage,
@@ -195,11 +195,11 @@ func (r *StorageReconciler) handleResourcesSync(ctx context.Context, storage *re
195195
return nil
196196
})
197197

198-
var eventMessage string = fmt.Sprintf(
198+
var eventMessage = fmt.Sprintf(
199199
"Resource: %s, Namespace: %s, Name: %s",
200-
reflect.TypeOf(new_resource),
201-
new_resource.GetNamespace(),
202-
new_resource.GetName(),
200+
reflect.TypeOf(newResource),
201+
newResource.GetNamespace(),
202+
newResource.GetName(),
203203
)
204204
if err != nil {
205205
r.Recorder.Event(

internal/resources/database.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55

66
api "github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
7+
"github.com/ydb-platform/ydb-kubernetes-operator/internal/configuration"
78
"github.com/ydb-platform/ydb-kubernetes-operator/internal/labels"
89
corev1 "k8s.io/api/core/v1"
910
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -59,10 +60,24 @@ func (b *DatabaseBuilder) GetPath() string {
5960
func (b *DatabaseBuilder) GetResourceBuilders() []ResourceBuilder {
6061
ll := labels.DatabaseLabels(b.Unwrap())
6162

63+
var optionalBuilders []ResourceBuilder
64+
65+
cfg, _ := configuration.Build(b.StorageRef)
66+
67+
optionalBuilders = append(
68+
optionalBuilders,
69+
&ConfigMapBuilder{
70+
Object: b,
71+
Data: cfg,
72+
Labels: ll,
73+
},
74+
)
75+
6276
if b.Spec.ServerlessResources != nil {
6377
return []ResourceBuilder{}
6478
}
65-
return []ResourceBuilder{
79+
return append(
80+
optionalBuilders,
6681
&ServiceBuilder{
6782
Object: b,
6883
NameFormat: grpcServiceNameFormat,
@@ -104,5 +119,5 @@ func (b *DatabaseBuilder) GetResourceBuilders() []ResourceBuilder {
104119
IPFamilyPolicy: b.Spec.Service.Status.IPFamilyPolicy,
105120
},
106121
&DatabaseStatefulSetBuilder{Database: b.Unwrap(), Labels: ll},
107-
}
122+
)
108123
}

internal/resources/database_statefulset.go

+14-20
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,17 @@ func (b *DatabaseStatefulSetBuilder) buildPodTemplateSpec() corev1.PodTemplateSp
9494
}
9595

9696
func (b *DatabaseStatefulSetBuilder) buildVolumes() []corev1.Volume {
97-
var volumes []corev1.Volume
97+
configMapName := b.Name
9898

99-
if b.Spec.ClusterConfig != "" {
100-
volumes = append(volumes, corev1.Volume{
99+
volumes := []corev1.Volume{
100+
{
101101
Name: configVolumeName,
102102
VolumeSource: corev1.VolumeSource{
103103
ConfigMap: &corev1.ConfigMapVolumeSource{
104-
LocalObjectReference: corev1.LocalObjectReference{Name: b.Spec.ClusterConfig},
104+
LocalObjectReference: corev1.LocalObjectReference{Name: configMapName},
105105
},
106106
},
107-
})
107+
},
108108
}
109109

110110
if b.Spec.Service.GRPC.TLSConfiguration != nil && b.Spec.Service.GRPC.TLSConfiguration.Enabled {
@@ -182,13 +182,11 @@ func (b *DatabaseStatefulSetBuilder) buildContainer() corev1.Container {
182182
func (b *DatabaseStatefulSetBuilder) buildVolumeMounts() []corev1.VolumeMount {
183183
var volumeMounts []corev1.VolumeMount
184184

185-
if b.Spec.ClusterConfig != "" {
186-
volumeMounts = append(volumeMounts, corev1.VolumeMount{
187-
Name: configVolumeName,
188-
ReadOnly: true,
189-
MountPath: "/opt/kikimr/cfg",
190-
})
191-
}
185+
volumeMounts = append(volumeMounts, corev1.VolumeMount{
186+
Name: configVolumeName,
187+
ReadOnly: true,
188+
MountPath: v1alpha1.ConfigDir,
189+
})
192190

193191
if b.Spec.Service.GRPC.TLSConfiguration.Enabled {
194192
volumeMounts = append(volumeMounts, corev1.VolumeMount{
@@ -210,7 +208,7 @@ func (b *DatabaseStatefulSetBuilder) buildVolumeMounts() []corev1.VolumeMount {
210208
}
211209

212210
func (b *DatabaseStatefulSetBuilder) buildContainerArgs() ([]string, []string) {
213-
command := []string{"/opt/kikimr/bin/kikimr"}
211+
command := []string{fmt.Sprintf("%s/%s", v1alpha1.BinariesDir, v1alpha1.DaemonBinaryName)}
214212

215213
db := NewDatabase(b.DeepCopy())
216214

@@ -225,6 +223,9 @@ func (b *DatabaseStatefulSetBuilder) buildContainerArgs() ([]string, []string) {
225223
"--ic-port",
226224
fmt.Sprintf("%d", v1alpha1.InterconnectPort),
227225

226+
"--yaml-config",
227+
fmt.Sprintf("%s/%s", v1alpha1.ConfigDir, v1alpha1.ConfigFileName),
228+
228229
"--tenant",
229230
tenantName,
230231

@@ -247,13 +248,6 @@ func (b *DatabaseStatefulSetBuilder) buildContainerArgs() ([]string, []string) {
247248
)
248249
}
249250

250-
if b.Spec.ClusterConfig != "" {
251-
command = []string{"/bin/bash"}
252-
args = []string{
253-
"-c",
254-
fmt.Sprintf("export kikimr_tenant='%s' && source /opt/kikimr/cfg/dynamic_server.cfg && exec /opt/kikimr/bin/kikimr ${kikimr_arg}", tenantName),
255-
}
256-
}
257251
return command, args
258252
}
259253

0 commit comments

Comments
 (0)