@@ -171,12 +171,32 @@ func (r *ReconcileMongoDbMultiReplicaSet) Reconcile(ctx context.Context, request
171
171
return r .updateStatus (ctx , & mrs , workflow .Failed (err ), log )
172
172
}
173
173
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
+
174
194
// Recovery prevents some deadlocks that can occur during reconciliation, e.g. the setting of an incorrect automation
175
195
// configuration and a subsequent attempt to overwrite it later, the operator would be stuck in Pending phase.
176
196
// See CLOUDP-189433 and CLOUDP-229222 for more details.
177
197
if recovery .ShouldTriggerRecovery (mrs .Status .Phase != mdbstatus .PhaseRunning , mrs .Status .LastTransition ) {
178
198
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 )
180
200
reconcileStatus := r .reconcileMemberResources (ctx , & mrs , log , conn , projectConfig )
181
201
if ! reconcileStatus .IsOK () {
182
202
log .Errorf ("Recovery failed because of reconcile errors, %v" , reconcileStatus )
@@ -188,7 +208,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) Reconcile(ctx context.Context, request
188
208
189
209
status := workflow .RunInGivenOrder (publishAutomationConfigFirst ,
190
210
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 {
192
212
return workflow .Failed (err )
193
213
}
194
214
return workflow .OK ()
@@ -499,7 +519,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) reconcileStatefulSets(ctx context.Cont
499
519
mconstruct .WithClusterNum (clusterNum ),
500
520
Replicas (replicasThisReconciliation ),
501
521
mconstruct .WithStsOverride (& stsOverride ),
502
- mconstruct .WithAnnotations (mrs .Name , certHash ),
522
+ mconstruct .WithAnnotations (mrs .Name ),
503
523
mconstruct .WithServiceName (mrs .MultiHeadlessServiceName (clusterNum )),
504
524
PodEnvVars (newPodVars (conn , projectConfig , mrs .Spec .LogLevel )),
505
525
CurrentAgentAuthMechanism (currentAgentAuthMode ),
@@ -677,7 +697,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) saveLastAchievedSpec(ctx context.Conte
677
697
678
698
// updateOmDeploymentRs performs OM registration operation for the replicaset. So the changes will be finally propagated
679
699
// 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 {
681
701
reachableHostnames := make ([]string , 0 )
682
702
683
703
clusterSpecList , err := mrs .GetClusterSpecItems ()
@@ -725,28 +745,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Conte
725
745
}
726
746
log .Debugf ("Existing process Ids: %+v" , processIds )
727
747
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 )
750
749
if err != nil && ! isRecovering {
751
750
return err
752
751
}
@@ -759,7 +758,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Conte
759
758
caFilePath := fmt .Sprintf ("%s/ca-pem" , util .TLSCaMountPath )
760
759
761
760
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 )
763
762
if ! status .IsOK () && ! isRecovering {
764
763
return xerrors .Errorf ("failed to enable Authentication for MongoDB Multi Replicaset" )
765
764
}
@@ -768,7 +767,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Conte
768
767
769
768
err = conn .ReadUpdateDeployment (
770
769
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 )
772
771
},
773
772
log ,
774
773
)
0 commit comments