@@ -171,12 +171,32 @@ func (r *ReconcileMongoDbMultiReplicaSet) Reconcile(ctx context.Context, request
171171 return r .updateStatus (ctx , & mrs , workflow .Failed (err ), log )
172172 }
173173
174+ // If tls is enabled we need to configure the "processes" array in opsManager/Cloud Manager with the
175+ // correct tlsCertPath, with the new tls design, this path has the certHash in it(so that cert can be rotated
176+ // without pod restart).
177+ tlsCertPath := ""
178+ internalClusterCertPath := ""
179+ if mrs .Spec .Security .IsTLSEnabled () {
180+ certSecretName := mrs .Spec .GetSecurity ().MemberCertificateSecretName (mrs .Name )
181+ internalClusterCertSecretName := mrs .Spec .GetSecurity ().InternalClusterAuthSecretName (mrs .Name )
182+ tlsCertHash := enterprisepem .ReadHashFromSecret (ctx , r .SecretClient , mrs .Namespace , certSecretName , "" , log )
183+ internalClusterCertHash := enterprisepem .ReadHashFromSecret (ctx , r .SecretClient , mrs .Namespace , internalClusterCertSecretName , "" , log )
184+
185+ if internalClusterCertHash != "" {
186+ internalClusterCertPath = fmt .Sprintf ("%s%s" , util .InternalClusterAuthMountPath , internalClusterCertHash )
187+ }
188+
189+ if tlsCertHash != "" {
190+ tlsCertPath = fmt .Sprintf ("%s/%s" , util .TLSCertMountPath , tlsCertHash )
191+ }
192+ }
193+
174194 // Recovery prevents some deadlocks that can occur during reconciliation, e.g. the setting of an incorrect automation
175195 // configuration and a subsequent attempt to overwrite it later, the operator would be stuck in Pending phase.
176196 // See CLOUDP-189433 and CLOUDP-229222 for more details.
177197 if recovery .ShouldTriggerRecovery (mrs .Status .Phase != mdbstatus .PhaseRunning , mrs .Status .LastTransition ) {
178198 log .Warnf ("Triggering Automatic Recovery. The MongoDB resource %s/%s is in %s state since %s" , mrs .Namespace , mrs .Name , mrs .Status .Phase , mrs .Status .LastTransition )
179- automationConfigError := r .updateOmDeploymentRs (ctx , conn , mrs , true , log )
199+ automationConfigError := r .updateOmDeploymentRs (ctx , conn , mrs , tlsCertPath , internalClusterCertPath , true , log )
180200 reconcileStatus := r .reconcileMemberResources (ctx , & mrs , log , conn , projectConfig )
181201 if ! reconcileStatus .IsOK () {
182202 log .Errorf ("Recovery failed because of reconcile errors, %v" , reconcileStatus )
@@ -188,7 +208,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) Reconcile(ctx context.Context, request
188208
189209 status := workflow .RunInGivenOrder (publishAutomationConfigFirst ,
190210 func () workflow.Status {
191- if err := r .updateOmDeploymentRs (ctx , conn , mrs , false , log ); err != nil {
211+ if err := r .updateOmDeploymentRs (ctx , conn , mrs , tlsCertPath , internalClusterCertPath , false , log ); err != nil {
192212 return workflow .Failed (err )
193213 }
194214 return workflow .OK ()
@@ -499,7 +519,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) reconcileStatefulSets(ctx context.Cont
499519 mconstruct .WithClusterNum (clusterNum ),
500520 Replicas (replicasThisReconciliation ),
501521 mconstruct .WithStsOverride (& stsOverride ),
502- mconstruct .WithAnnotations (mrs .Name , certHash ),
522+ mconstruct .WithAnnotations (mrs .Name ),
503523 mconstruct .WithServiceName (mrs .MultiHeadlessServiceName (clusterNum )),
504524 PodEnvVars (newPodVars (conn , projectConfig , mrs .Spec .LogLevel )),
505525 CurrentAgentAuthMechanism (currentAgentAuthMode ),
@@ -677,7 +697,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) saveLastAchievedSpec(ctx context.Conte
677697
678698// updateOmDeploymentRs performs OM registration operation for the replicaset. So the changes will be finally propagated
679699// to automation agents in containers
680- func (r * ReconcileMongoDbMultiReplicaSet ) updateOmDeploymentRs (ctx context.Context , conn om.Connection , mrs mdbmultiv1.MongoDBMultiCluster , isRecovering bool , log * zap.SugaredLogger ) error {
700+ func (r * ReconcileMongoDbMultiReplicaSet ) updateOmDeploymentRs (ctx context.Context , conn om.Connection , mrs mdbmultiv1.MongoDBMultiCluster , tlsCertPath , internalClusterCertPath string , isRecovering bool , log * zap.SugaredLogger ) error {
681701 reachableHostnames := make ([]string , 0 )
682702
683703 clusterSpecList , err := mrs .GetClusterSpecItems ()
@@ -725,28 +745,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Conte
725745 }
726746 log .Debugf ("Existing process Ids: %+v" , processIds )
727747
728- certificateFileName := ""
729- internalClusterPath := ""
730-
731- // If tls is enabled we need to configure the "processes" array in opsManager/Cloud Manager with the
732- // correct certFilePath, with the new tls design, this path has the certHash in it(so that cert can be rotated
733- // without pod restart), we can get the cert hash from any of the statefulset, here we pick the statefulset in the first cluster.
734- if mrs .Spec .Security .IsTLSEnabled () {
735- firstStatefulSet , err := r .firstStatefulSet (ctx , & mrs )
736- if err != nil {
737- return err
738- }
739-
740- if hash := firstStatefulSet .Annotations [util .InternalCertAnnotationKey ]; hash != "" {
741- internalClusterPath = fmt .Sprintf ("%s%s" , util .InternalClusterAuthMountPath , hash )
742- }
743-
744- if certificateHash := firstStatefulSet .Annotations [certs .CertHashAnnotationKey ]; certificateHash != "" {
745- certificateFileName = fmt .Sprintf ("%s/%s" , util .TLSCertMountPath , certificateHash )
746- }
747- }
748-
749- processes , err := process .CreateMongodProcessesWithLimitMulti (r .imageUrls [mcoConstruct .MongodbImageEnv ], r .forceEnterprise , mrs , certificateFileName )
748+ processes , err := process .CreateMongodProcessesWithLimitMulti (r .imageUrls [mcoConstruct .MongodbImageEnv ], r .forceEnterprise , mrs , tlsCertPath )
750749 if err != nil && ! isRecovering {
751750 return err
752751 }
@@ -759,7 +758,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Conte
759758 caFilePath := fmt .Sprintf ("%s/ca-pem" , util .TLSCaMountPath )
760759
761760 agentCertSecretName := mrs .GetSecurity ().AgentClientCertificateSecretName (mrs .GetName ())
762- status , additionalReconciliationRequired := r .updateOmAuthentication (ctx , conn , rs .GetProcessNames (), & mrs , agentCertSecretName , caFilePath , internalClusterPath , isRecovering , log )
761+ status , additionalReconciliationRequired := r .updateOmAuthentication (ctx , conn , rs .GetProcessNames (), & mrs , agentCertSecretName , caFilePath , internalClusterCertPath , isRecovering , log )
763762 if ! status .IsOK () && ! isRecovering {
764763 return xerrors .Errorf ("failed to enable Authentication for MongoDB Multi Replicaset" )
765764 }
@@ -768,7 +767,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Conte
768767
769768 err = conn .ReadUpdateDeployment (
770769 func (d om.Deployment ) error {
771- return ReconcileReplicaSetAC (ctx , d , mrs .Spec .DbCommonSpec , lastMongodbConfig , mrs .Name , rs , caFilePath , internalClusterPath , nil , log )
770+ return ReconcileReplicaSetAC (ctx , d , mrs .Spec .DbCommonSpec , lastMongodbConfig , mrs .Name , rs , caFilePath , internalClusterCertPath , nil , log )
772771 },
773772 log ,
774773 )
0 commit comments