@@ -247,16 +247,24 @@ func (opt *mongoOptions) backupMongoDB(targetRef api_v1beta1.TargetRef) (*restic
247
247
return nil , err
248
248
}
249
249
250
- appBindingSecret , err := opt .kubeClient .CoreV1 ().Secrets (opt .appBindingNamespace ).Get (context .TODO (), appBinding .Spec .Secret .Name , metav1.GetOptions {})
250
+ authSecret , err := opt .kubeClient .CoreV1 ().Secrets (opt .appBindingNamespace ).Get (context .TODO (), appBinding .Spec .Secret .Name , metav1.GetOptions {})
251
251
if err != nil {
252
252
return nil , err
253
253
}
254
254
255
- err = appBinding .TransformSecret (opt .kubeClient , appBindingSecret .Data )
255
+ err = appBinding .TransformSecret (opt .kubeClient , authSecret .Data )
256
256
if err != nil {
257
257
return nil , err
258
258
}
259
259
260
+ var tlsSecret * core.Secret
261
+ if appBinding .Spec .TLSSecret != nil {
262
+ tlsSecret , err = opt .kubeClient .CoreV1 ().Secrets (opt .appBindingNamespace ).Get (context .TODO (), appBinding .Spec .TLSSecret .Name , metav1.GetOptions {})
263
+ if err != nil {
264
+ return nil , err
265
+ }
266
+ }
267
+
260
268
hostname , err := appBinding .Hostname ()
261
269
if err != nil {
262
270
return nil , err
@@ -314,13 +322,17 @@ func (opt *mongoOptions) backupMongoDB(targetRef api_v1beta1.TargetRef) (*restic
314
322
}
315
323
316
324
if appBinding .Spec .ClientConfig .CABundle != nil {
325
+ if tlsSecret == nil {
326
+ return nil , errors .Wrap (err , "spec.tlsSecret needs to be set in appbinding for TLS secured database." )
327
+ }
328
+
317
329
if err := os .WriteFile (filepath .Join (opt .setupOptions .ScratchDir , MongoTLSCertFileName ), appBinding .Spec .ClientConfig .CABundle , os .ModePerm ); err != nil {
318
330
return nil , err
319
331
}
320
332
mongoCreds = []interface {}{
321
333
"--tls" ,
322
334
"--tlsCAFile" , filepath .Join (opt .setupOptions .ScratchDir , MongoTLSCertFileName ),
323
- "--tlsPEMKeyFile " , filepath .Join (opt .setupOptions .ScratchDir , MongoClientPemFileName ),
335
+ "--tlsCertificateKeyFile " , filepath .Join (opt .setupOptions .ScratchDir , MongoClientPemFileName ),
324
336
}
325
337
dumpCreds = []interface {}{
326
338
"--ssl" ,
@@ -331,13 +343,13 @@ func (opt *mongoOptions) backupMongoDB(targetRef api_v1beta1.TargetRef) (*restic
331
343
// get certificate secret to get client certificate
332
344
var pemBytes []byte
333
345
var ok bool
334
- pemBytes , ok = appBindingSecret .Data [MongoClientPemFileName ]
346
+ pemBytes , ok = tlsSecret .Data [MongoClientPemFileName ]
335
347
if ! ok {
336
- crt , ok := appBindingSecret .Data [core .TLSCertKey ]
348
+ crt , ok := tlsSecret .Data [core .TLSCertKey ]
337
349
if ! ok {
338
350
return nil , errors .Wrap (err , "unable to retrieve tls.crt from secret." )
339
351
}
340
- key , ok := appBindingSecret .Data [core .TLSPrivateKeyKey ]
352
+ key , ok := tlsSecret .Data [core .TLSPrivateKeyKey ]
341
353
if ! ok {
342
354
return nil , errors .Wrap (err , "unable to retrieve tls.key from secret." )
343
355
}
@@ -361,8 +373,8 @@ func (opt *mongoOptions) backupMongoDB(targetRef api_v1beta1.TargetRef) (*restic
361
373
362
374
} else {
363
375
userAuth := []interface {}{
364
- fmt .Sprintf ("--username=%s" , appBindingSecret .Data [MongoUserKey ]),
365
- fmt .Sprintf ("--password=%s" , appBindingSecret .Data [MongoPasswordKey ]),
376
+ fmt .Sprintf ("--username=%s" , authSecret .Data [MongoUserKey ]),
377
+ fmt .Sprintf ("--password=%s" , authSecret .Data [MongoPasswordKey ]),
366
378
"--authenticationDatabase" , opt .authenticationDatabase ,
367
379
}
368
380
mongoCreds = append (mongoCreds , userAuth ... )
@@ -662,7 +674,7 @@ func lockConfigServer(configSVRDSN, secondaryHost string) error {
662
674
"config" ,
663
675
"--host" , secondaryHost ,
664
676
"--quiet" ,
665
- "--eval" , "rs.slaveOk (); db.BackupControl.find({ '_id' : 'BackupControlDocument' }).readConcern('majority');" ,
677
+ "--eval" , "rs.secondaryOk (); db.BackupControl.find({ '_id' : 'BackupControlDocument' }).readConcern('majority');" ,
666
678
}, mongoCreds ... )
667
679
668
680
if err := sh .Command (MongoCMD , args ... ).UnmarshalJSON (& v ); err != nil {
0 commit comments