@@ -1191,6 +1191,154 @@ var _ = Describe("Sidecars", Ordered, func() {
1191
1191
Expect (sidecar .Command ).To (Equal ([]string {"repohost-cmd" }))
1192
1192
Expect (sidecar .Image ).To (Equal ("repohost-image" ))
1193
1193
})
1194
+
1195
+ It ("should update PerconaPGCluster with multiple sidecars" , func () {
1196
+ Expect (k8sClient .Get (ctx , client .ObjectKeyFromObject (cr ), cr )).Should (Succeed ())
1197
+
1198
+ for i := range cr .Spec .InstanceSets {
1199
+ i := & cr .Spec .InstanceSets [i ]
1200
+ i .Sidecars = []corev1.Container {
1201
+ {
1202
+ Name : "instance-sidecar-2" ,
1203
+ Command : []string {"instance-cmd-2" },
1204
+ Image : "instance-image-2" ,
1205
+ },
1206
+ {
1207
+ Name : "instance-sidecar" ,
1208
+ Command : []string {"instance-cmd" },
1209
+ Image : "instance-image" ,
1210
+ },
1211
+ }
1212
+ }
1213
+ cr .Spec .Proxy .PGBouncer .Sidecars = []corev1.Container {
1214
+ {
1215
+ Name : "pgbouncer-sidecar" ,
1216
+ Command : []string {"pgbouncer-cmd" },
1217
+ Image : "pgbouncer-image" ,
1218
+ },
1219
+ {
1220
+ Name : "pgbouncer-sidecar-2" ,
1221
+ Command : []string {"pgbouncer-cmd-2" },
1222
+ Image : "pgbouncer-image-2" ,
1223
+ },
1224
+ {
1225
+ Name : "pgbouncer-sidecar-3" ,
1226
+ Command : []string {"pgbouncer-cmd-3" },
1227
+ Image : "pgbouncer-image-3" ,
1228
+ },
1229
+ }
1230
+ cr .Spec .Backups .PGBackRest .RepoHost .Sidecars = []corev1.Container {
1231
+ {
1232
+ Name : "repohost-sidecar-2" ,
1233
+ Command : []string {"repohost-cmd-2" },
1234
+ Image : "repohost-image-2" ,
1235
+ },
1236
+ {
1237
+ Name : "repohost-sidecar" ,
1238
+ Command : []string {"repohost-cmd" },
1239
+ Image : "repohost-image" ,
1240
+ },
1241
+ {
1242
+ Name : "repohost-sidecar-3" ,
1243
+ Command : []string {"repohost-cmd-3" },
1244
+ Image : "repohost-image-3" ,
1245
+ },
1246
+ }
1247
+ Expect (k8sClient .Update (ctx , cr )).Should (Succeed ())
1248
+ })
1249
+
1250
+ It ("should reconcile" , func () {
1251
+ _ , err := reconciler (cr ).Reconcile (ctx , ctrl.Request {NamespacedName : crNamespacedName })
1252
+ Expect (err ).NotTo (HaveOccurred ())
1253
+ _ , err = crunchyReconciler ().Reconcile (ctx , ctrl.Request {NamespacedName : crNamespacedName })
1254
+ Expect (err ).NotTo (HaveOccurred ())
1255
+ })
1256
+
1257
+ It ("Instances should have multiple sidecars" , func () {
1258
+ stsList := & appsv1.StatefulSetList {}
1259
+ labels := map [string ]string {
1260
+ "postgres-operator.crunchydata.com/data" : "postgres" ,
1261
+ "postgres-operator.crunchydata.com/cluster" : crName ,
1262
+ }
1263
+ err = k8sClient .List (ctx , stsList , client .InNamespace (cr .Namespace ), client .MatchingLabels (labels ))
1264
+ Expect (err ).NotTo (HaveOccurred ())
1265
+ Expect (stsList .Items ).NotTo (BeEmpty ())
1266
+
1267
+ for _ , sts := range stsList .Items {
1268
+ l := len (sts .Spec .Template .Spec .Containers )
1269
+ sidecar := sts .Spec .Template .Spec .Containers [l - 4 ]
1270
+ Expect (sidecar ).NotTo (BeNil ())
1271
+ Expect (sidecar .Name ).To (Equal ("instance-sidecar-2" ))
1272
+ Expect (sidecar .Command ).To (Equal ([]string {"instance-cmd-2" }))
1273
+ Expect (sidecar .Image ).To (Equal ("instance-image-2" ))
1274
+
1275
+ sidecar = sts .Spec .Template .Spec .Containers [l - 3 ]
1276
+ Expect (sidecar ).NotTo (BeNil ())
1277
+ Expect (sidecar .Name ).To (Equal ("instance-sidecar" ))
1278
+ Expect (sidecar .Command ).To (Equal ([]string {"instance-cmd" }))
1279
+ Expect (sidecar .Image ).To (Equal ("instance-image" ))
1280
+ }
1281
+ })
1282
+
1283
+ It ("PgBouncer should have multiple sidecars" , func () {
1284
+ deployment := & appsv1.Deployment {
1285
+ ObjectMeta : metav1.ObjectMeta {
1286
+ Name : crName + "-pgbouncer" ,
1287
+ Namespace : cr .Namespace ,
1288
+ },
1289
+ }
1290
+ err = k8sClient .Get (ctx , client .ObjectKeyFromObject (deployment ), deployment )
1291
+ Expect (err ).NotTo (HaveOccurred ())
1292
+
1293
+ l := len (deployment .Spec .Template .Spec .Containers )
1294
+ sidecar := deployment .Spec .Template .Spec .Containers [l - 3 ]
1295
+ Expect (sidecar ).NotTo (BeNil ())
1296
+ Expect (sidecar .Name ).To (Equal ("pgbouncer-sidecar" ))
1297
+ Expect (sidecar .Command ).To (Equal ([]string {"pgbouncer-cmd" }))
1298
+ Expect (sidecar .Image ).To (Equal ("pgbouncer-image" ))
1299
+
1300
+ sidecar = deployment .Spec .Template .Spec .Containers [l - 2 ]
1301
+ Expect (sidecar ).NotTo (BeNil ())
1302
+ Expect (sidecar .Name ).To (Equal ("pgbouncer-sidecar-2" ))
1303
+ Expect (sidecar .Command ).To (Equal ([]string {"pgbouncer-cmd-2" }))
1304
+ Expect (sidecar .Image ).To (Equal ("pgbouncer-image-2" ))
1305
+
1306
+ sidecar = deployment .Spec .Template .Spec .Containers [l - 1 ]
1307
+ Expect (sidecar ).NotTo (BeNil ())
1308
+ Expect (sidecar .Name ).To (Equal ("pgbouncer-sidecar-3" ))
1309
+ Expect (sidecar .Command ).To (Equal ([]string {"pgbouncer-cmd-3" }))
1310
+ Expect (sidecar .Image ).To (Equal ("pgbouncer-image-3" ))
1311
+ })
1312
+
1313
+ It ("PgBackrest Repo should have multiple sidecars" , func () {
1314
+ sts := & appsv1.StatefulSet {
1315
+ ObjectMeta : metav1.ObjectMeta {
1316
+ Name : crName + "-repo-host" ,
1317
+ Namespace : cr .Namespace ,
1318
+ },
1319
+ }
1320
+ err = k8sClient .Get (ctx , client .ObjectKeyFromObject (sts ), sts )
1321
+ Expect (err ).NotTo (HaveOccurred ())
1322
+
1323
+ l := len (sts .Spec .Template .Spec .Containers )
1324
+ sidecar := sts .Spec .Template .Spec .Containers [l - 3 ]
1325
+ Expect (sidecar ).NotTo (BeNil ())
1326
+ Expect (sidecar .Name ).To (Equal ("repohost-sidecar-2" ))
1327
+ Expect (sidecar .Command ).To (Equal ([]string {"repohost-cmd-2" }))
1328
+ Expect (sidecar .Image ).To (Equal ("repohost-image-2" ))
1329
+
1330
+ sidecar = sts .Spec .Template .Spec .Containers [l - 2 ]
1331
+ Expect (sidecar ).NotTo (BeNil ())
1332
+ Expect (sidecar .Name ).To (Equal ("repohost-sidecar" ))
1333
+ Expect (sidecar .Command ).To (Equal ([]string {"repohost-cmd" }))
1334
+ Expect (sidecar .Image ).To (Equal ("repohost-image" ))
1335
+
1336
+ sidecar = sts .Spec .Template .Spec .Containers [l - 1 ]
1337
+ Expect (sidecar ).NotTo (BeNil ())
1338
+ Expect (sidecar .Name ).To (Equal ("repohost-sidecar-3" ))
1339
+ Expect (sidecar .Command ).To (Equal ([]string {"repohost-cmd-3" }))
1340
+ Expect (sidecar .Image ).To (Equal ("repohost-image-3" ))
1341
+ })
1194
1342
})
1195
1343
1196
1344
var _ = Describe ("Operator-created sidecar container resources" , Ordered , func () {
0 commit comments