@@ -3,7 +3,9 @@ package database_test
3
3
import (
4
4
"context"
5
5
"errors"
6
+ "fmt"
6
7
"path/filepath"
8
+ "reflect"
7
9
"strings"
8
10
"testing"
9
11
@@ -142,5 +144,77 @@ var _ = Describe("Database controller medium tests", func() {
142
144
}
143
145
}
144
146
})
147
+
148
+ By ("Check encryption for Database..." )
149
+ foundDatabase := v1alpha1.Database {}
150
+ Expect (k8sClient .Get (ctx , types.NamespacedName {
151
+ Name : databaseSample .Name ,
152
+ Namespace : testobjects .YdbNamespace ,
153
+ }, & foundDatabase ))
154
+
155
+ By ("Update Database and enable encryption..." )
156
+ foundDatabase .Spec .Encryption = & v1alpha1.EncryptionConfig {Enabled : true }
157
+ Expect (k8sClient .Update (ctx , & foundDatabase )).Should (Succeed ())
158
+
159
+ By ("Check that encryption secret was created..." )
160
+ encryptionSecret := corev1.Secret {}
161
+ Eventually (func () error {
162
+ return k8sClient .Get (ctx , types.NamespacedName {
163
+ Name : databaseSample .Name ,
164
+ Namespace : testobjects .YdbNamespace ,
165
+ }, & encryptionSecret )
166
+ }, test .Timeout , test .Interval ).ShouldNot (HaveOccurred ())
167
+ encryptionData := encryptionSecret .Data
168
+
169
+ By ("Check that arg `--key-file` was added to StatefulSet..." )
170
+ databaseStatefulSet = appsv1.StatefulSet {}
171
+ Eventually (func () error {
172
+ Expect (k8sClient .List (ctx ,
173
+ & foundStatefulSets ,
174
+ client .InNamespace (testobjects .YdbNamespace ),
175
+ )).ShouldNot (HaveOccurred ())
176
+ for idx , statefulSet := range foundStatefulSets .Items {
177
+ if statefulSet .Name == testobjects .DatabaseName {
178
+ databaseStatefulSet = foundStatefulSets .Items [idx ]
179
+ break
180
+ }
181
+ }
182
+ podContainerArgs := databaseStatefulSet .Spec .Template .Spec .Containers [0 ].Args
183
+ encryptionKeyConfigPath := fmt .Sprintf ("%s/%s" , v1alpha1 .ConfigDir , v1alpha1 .DatabaseEncryptionKeyConfigFile )
184
+ for idx , arg := range podContainerArgs {
185
+ if arg == "--key-file" {
186
+ if podContainerArgs [idx + 1 ] == encryptionKeyConfigPath {
187
+ return nil
188
+ }
189
+ return fmt .Errorf (
190
+ "Found arg `--key-file=%s` for encryption does not match with expected path: %s" ,
191
+ podContainerArgs [idx + 1 ],
192
+ encryptionKeyConfigPath ,
193
+ )
194
+ }
195
+ }
196
+ return errors .New ("Failed to find arg `--key-file` for encryption in StatefulSet" )
197
+ }, test .Timeout , test .Interval ).ShouldNot (HaveOccurred ())
198
+
199
+ By ("Update Database encryption pin..." )
200
+ Expect (k8sClient .Get (ctx , types.NamespacedName {
201
+ Name : databaseSample .Name ,
202
+ Namespace : testobjects .YdbNamespace ,
203
+ }, & foundDatabase ))
204
+ pin := "Ignore"
205
+ foundDatabase .Spec .Encryption = & v1alpha1.EncryptionConfig {
206
+ Enabled : true ,
207
+ Pin : & pin ,
208
+ }
209
+ Expect (k8sClient .Update (ctx , & foundDatabase )).Should (Succeed ())
210
+
211
+ By ("Check that Secret for encryption was not changed..." )
212
+ Consistently (func (g Gomega ) bool {
213
+ g .Expect (k8sClient .Get (ctx , types.NamespacedName {
214
+ Name : databaseSample .Name ,
215
+ Namespace : testobjects .YdbNamespace ,
216
+ }, & encryptionSecret ))
217
+ return reflect .DeepEqual (encryptionData , encryptionSecret .Data )
218
+ }, test .Timeout , test .Interval ).Should (BeTrue ())
145
219
})
146
220
})
0 commit comments