@@ -3,25 +3,15 @@ package storage
3
3
import (
4
4
"context"
5
5
"fmt"
6
- "path"
7
6
8
7
"github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
9
8
"github.com/ydb-platform/ydb-kubernetes-operator/internal/exec"
10
9
"github.com/ydb-platform/ydb-kubernetes-operator/internal/resources"
11
- corev1 "k8s.io/api/core/v1"
12
- "k8s.io/apimachinery/pkg/api/errors"
13
10
"k8s.io/apimachinery/pkg/api/meta"
14
11
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15
- "k8s.io/apimachinery/pkg/types"
16
12
ctrl "sigs.k8s.io/controller-runtime"
17
13
)
18
14
19
- const (
20
- InitStorageScript = "init_storage.bash"
21
- InitRootStorageScript = "init_root_storage.bash"
22
- InitCMSScript = "init_cms.bash"
23
- )
24
-
25
15
func (r * StorageReconciler ) setInitialStatus (ctx context.Context , storage * resources.StorageClusterBuilder ) (bool , ctrl.Result , error ) {
26
16
r .Log .Info ("running step setInitialStatus" )
27
17
var changed bool = false
@@ -43,56 +33,6 @@ func (r *StorageReconciler) setInitialStatus(ctx context.Context, storage *resou
43
33
})
44
34
changed = true
45
35
}
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
- }
96
36
if storage .Status .State != string (Initializing ) {
97
37
storage .Status .State = string (Initializing )
98
38
changed = true
@@ -108,7 +48,12 @@ func (r *StorageReconciler) runInitScripts(ctx context.Context, storage *resourc
108
48
podName := fmt .Sprintf ("%s-0" , storage .Name )
109
49
110
50
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
+ }
112
57
_ , _ , err := exec .ExecInPod (r .Scheme , r .Config , storage .Namespace , podName , "ydb-storage" , cmd )
113
58
if err != nil {
114
59
return Stop , ctrl.Result {RequeueAfter : StorageInitializationRequeueDelay }, err
@@ -122,36 +67,6 @@ func (r *StorageReconciler) runInitScripts(ctx context.Context, storage *resourc
122
67
return r .setState (ctx , storage )
123
68
}
124
69
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
-
155
70
meta .SetStatusCondition (& storage .Status .Conditions , metav1.Condition {
156
71
Type : StorageInitializedCondition ,
157
72
Status : "True" ,
0 commit comments