@@ -198,12 +198,13 @@ func (r *ReconcileMongoDbReplicaSet) Reconcile(ctx context.Context, request reco
198
198
}
199
199
}
200
200
201
+ certHash := enterprisepem .ReadHashFromSecret (ctx , r .SecretClient , rs .Namespace , rsCertsConfig .CertSecretName , databaseSecretPath , log )
201
202
internalClusterCertHash := enterprisepem .ReadHashFromSecret (ctx , r .SecretClient , rs .Namespace , rsCertsConfig .InternalClusterSecretName , databaseSecretPath , log )
202
203
203
204
rsConfig := construct .ReplicaSetOptions (
204
205
PodEnvVars (newPodVars (conn , projectConfig , rs .Spec .LogLevel )),
205
206
CurrentAgentAuthMechanism (currentAgentAuthMode ),
206
- CertificateHash (enterprisepem . ReadHashFromSecret ( ctx , r . SecretClient , rs . Namespace , rsCertsConfig . CertSecretName , databaseSecretPath , log ) ),
207
+ CertificateHash (certHash ),
207
208
InternalClusterHash (internalClusterCertHash ),
208
209
PrometheusTLSCertHash (prometheusCertHash ),
209
210
WithVaultConfig (vaultConfig ),
@@ -240,12 +241,17 @@ func (r *ReconcileMongoDbReplicaSet) Reconcile(ctx context.Context, request reco
240
241
internalClusterCertPath = fmt .Sprintf ("%s%s" , util .InternalClusterAuthMountPath , internalClusterCertHash )
241
242
}
242
243
244
+ certPath := ""
245
+ if certHash != "" {
246
+ certPath = fmt .Sprintf ("%s/%s" , util .TLSCertMountPath , certHash )
247
+ }
248
+
243
249
// Recovery prevents some deadlocks that can occur during reconciliation, e.g. the setting of an incorrect automation
244
250
// configuration and a subsequent attempt to overwrite it later, the operator would be stuck in Pending phase.
245
251
// See CLOUDP-189433 and CLOUDP-229222 for more details.
246
252
if recovery .ShouldTriggerRecovery (rs .Status .Phase != mdbstatus .PhaseRunning , rs .Status .LastTransition ) {
247
253
log .Warnf ("Triggering Automatic Recovery. The MongoDB resource %s/%s is in %s state since %s" , rs .Namespace , rs .Name , rs .Status .Phase , rs .Status .LastTransition )
248
- automationConfigStatus := r .updateOmDeploymentRs (ctx , conn , rs .Status .Members , rs , sts , log , caFilePath , internalClusterCertPath , agentCertSecretSelector , prometheusCertHash , true ).OnErrorPrepend ("Failed to create/update (Ops Manager reconciliation phase):" )
254
+ automationConfigStatus := r .updateOmDeploymentRs (ctx , conn , rs .Status .Members , rs , sts , log , caFilePath , certPath , internalClusterCertPath , agentCertSecretSelector , prometheusCertHash , true ).OnErrorPrepend ("Failed to create/update (Ops Manager reconciliation phase):" )
249
255
deploymentError := create .DatabaseInKubernetes (ctx , r .client , * rs , sts , rsConfig , log )
250
256
if deploymentError != nil {
251
257
log .Errorf ("Recovery failed because of deployment errors, %w" , deploymentError )
@@ -261,7 +267,7 @@ func (r *ReconcileMongoDbReplicaSet) Reconcile(ctx context.Context, request reco
261
267
}
262
268
status = workflow .RunInGivenOrder (publishAutomationConfigFirst (ctx , r .client , * rs , lastSpec , rsConfig , log ),
263
269
func () workflow.Status {
264
- return r .updateOmDeploymentRs (ctx , conn , rs .Status .Members , rs , sts , log , caFilePath , internalClusterCertPath , agentCertSecretSelector , prometheusCertHash , false ).OnErrorPrepend ("Failed to create/update (Ops Manager reconciliation phase):" )
270
+ return r .updateOmDeploymentRs (ctx , conn , rs .Status .Members , rs , sts , log , caFilePath , certPath , internalClusterCertPath , agentCertSecretSelector , prometheusCertHash , false ).OnErrorPrepend ("Failed to create/update (Ops Manager reconciliation phase):" )
265
271
},
266
272
func () workflow.Status {
267
273
workflowStatus := create .HandlePVCResize (ctx , r .client , & sts , log )
@@ -422,7 +428,7 @@ func AddReplicaSetController(ctx context.Context, mgr manager.Manager, imageUrls
422
428
423
429
// updateOmDeploymentRs performs OM registration operation for the replicaset. So the changes will be finally propagated
424
430
// to automation agents in containers
425
- func (r * ReconcileMongoDbReplicaSet ) updateOmDeploymentRs (ctx context.Context , conn om.Connection , membersNumberBefore int , rs * mdbv1.MongoDB , set appsv1.StatefulSet , log * zap.SugaredLogger , caFilePath , internalClusterCertPath string , agentCertSecretSelector corev1.SecretKeySelector , prometheusCertHash string , isRecovering bool ) workflow.Status {
431
+ func (r * ReconcileMongoDbReplicaSet ) updateOmDeploymentRs (ctx context.Context , conn om.Connection , membersNumberBefore int , rs * mdbv1.MongoDB , set appsv1.StatefulSet , log * zap.SugaredLogger , caFilePath , certPath , internalClusterCertPath string , agentCertSecretSelector corev1.SecretKeySelector , prometheusCertHash string , isRecovering bool ) workflow.Status {
426
432
log .Debug ("Entering UpdateOMDeployments" )
427
433
// Only "concrete" RS members should be observed
428
434
// - if scaling down, let's observe only members that will remain after scale-down operation
@@ -434,7 +440,7 @@ func (r *ReconcileMongoDbReplicaSet) updateOmDeploymentRs(ctx context.Context, c
434
440
435
441
// If current operation is to Disable TLS, then we should the current members of the Replica Set,
436
442
// this is, do not scale them up or down util TLS disabling has completed.
437
- shouldLockMembers , err := updateOmDeploymentDisableTLSConfiguration (conn , r .imageUrls [mcoConstruct .MongodbImageEnv ], r .forceEnterprise , membersNumberBefore , rs , set , log , caFilePath )
443
+ shouldLockMembers , err := updateOmDeploymentDisableTLSConfiguration (conn , r .imageUrls [mcoConstruct .MongodbImageEnv ], r .forceEnterprise , membersNumberBefore , rs , set , log , caFilePath , certPath )
438
444
if err != nil && ! isRecovering {
439
445
return workflow .Failed (err )
440
446
}
@@ -448,7 +454,7 @@ func (r *ReconcileMongoDbReplicaSet) updateOmDeploymentRs(ctx context.Context, c
448
454
updatedMembers = int (* set .Spec .Replicas )
449
455
}
450
456
451
- replicaSet := replicaset .BuildFromStatefulSetWithReplicas (r .imageUrls [mcoConstruct .MongodbImageEnv ], r .forceEnterprise , set , rs .GetSpec (), updatedMembers , rs .CalculateFeatureCompatibilityVersion ())
457
+ replicaSet := replicaset .BuildFromStatefulSetWithReplicas (r .imageUrls [mcoConstruct .MongodbImageEnv ], r .forceEnterprise , set , rs .GetSpec (), updatedMembers , rs .CalculateFeatureCompatibilityVersion (), certPath )
452
458
processNames := replicaSet .GetProcessNames ()
453
459
454
460
status , additionalReconciliationRequired := r .updateOmAuthentication (ctx , conn , processNames , rs , agentCertSecretSelector , caFilePath , internalClusterCertPath , isRecovering , log )
@@ -512,7 +518,7 @@ func (r *ReconcileMongoDbReplicaSet) updateOmDeploymentRs(ctx context.Context, c
512
518
// updateOmDeploymentDisableTLSConfiguration checks if TLS configuration needs
513
519
// to be disabled. In which case it will disable it and inform to the calling
514
520
// function.
515
- func updateOmDeploymentDisableTLSConfiguration (conn om.Connection , mongoDBImage string , forceEnterprise bool , membersNumberBefore int , rs * mdbv1.MongoDB , set appsv1.StatefulSet , log * zap.SugaredLogger , caFilePath string ) (bool , error ) {
521
+ func updateOmDeploymentDisableTLSConfiguration (conn om.Connection , mongoDBImage string , forceEnterprise bool , membersNumberBefore int , rs * mdbv1.MongoDB , set appsv1.StatefulSet , log * zap.SugaredLogger , caFilePath , certPath string ) (bool , error ) {
516
522
tlsConfigWasDisabled := false
517
523
518
524
err := conn .ReadUpdateDeployment (
@@ -526,7 +532,7 @@ func updateOmDeploymentDisableTLSConfiguration(conn om.Connection, mongoDBImage
526
532
527
533
// configure as many agents/Pods as we currently have, no more (in case
528
534
// there's a scale up change at the same time).
529
- replicaSet := replicaset .BuildFromStatefulSetWithReplicas (mongoDBImage , forceEnterprise , set , rs .GetSpec (), membersNumberBefore , rs .CalculateFeatureCompatibilityVersion ())
535
+ replicaSet := replicaset .BuildFromStatefulSetWithReplicas (mongoDBImage , forceEnterprise , set , rs .GetSpec (), membersNumberBefore , rs .CalculateFeatureCompatibilityVersion (), certPath )
530
536
531
537
lastConfig , err := rs .GetLastAdditionalMongodConfigByType (mdbv1 .ReplicaSetConfig )
532
538
if err != nil {
0 commit comments