Skip to content

Commit d7e8403

Browse files
committed
fixup! WIP: remove cert hash annotations
1 parent b7cfbe3 commit d7e8403

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

controllers/operator/mongodbmultireplicaset_controller.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,23 @@ func (r *ReconcileMongoDbMultiReplicaSet) Reconcile(ctx context.Context, request
171171
return r.updateStatus(ctx, &mrs, workflow.Failed(err), log)
172172
}
173173

174+
certSecretName := mrs.Spec.GetSecurity().MemberCertificateSecretName(mrs.Name)
175+
internalClusterCertSecretName := mrs.Spec.GetSecurity().InternalClusterAuthSecretName(mrs.Name)
176+
certHash := enterprisepem.ReadHashFromSecret(ctx, r.SecretClient, mrs.Namespace, certSecretName, "", log)
177+
internalClusterCertHash := enterprisepem.ReadHashFromSecret(ctx, r.SecretClient, mrs.Namespace, internalClusterCertSecretName, "", log)
178+
174179
// If tls is enabled we need to configure the "processes" array in opsManager/Cloud Manager with the
175-
// correct certFilePath, with the new tls design, this path has the certHash in it(so that cert can be rotated
180+
// correct certPath, with the new tls design, this path has the certHash in it(so that cert can be rotated
176181
// without pod restart).
177-
certificateFileName := ""
178-
internalClusterPath := ""
182+
certPath := ""
183+
internalClusterCertPath := ""
179184
if mrs.Spec.Security.IsTLSEnabled() {
180-
if hash := firstStatefulSet.Annotations[util.InternalCertAnnotationKey]; hash != "" {
181-
internalClusterPath = fmt.Sprintf("%s%s", util.InternalClusterAuthMountPath, hash)
185+
if certHash != "" {
186+
internalClusterCertPath = fmt.Sprintf("%s%s", util.InternalClusterAuthMountPath, certHash)
182187
}
183188

184-
if certificateHash := firstStatefulSet.Annotations[certs.CertHashAnnotationKey]; certificateHash != "" {
185-
certificateFileName = fmt.Sprintf("%s/%s", util.TLSCertMountPath, certificateHash)
189+
if internalClusterCertHash != "" {
190+
certPath = fmt.Sprintf("%s/%s", util.TLSCertMountPath, internalClusterCertHash)
186191
}
187192
}
188193

@@ -191,7 +196,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) Reconcile(ctx context.Context, request
191196
// See CLOUDP-189433 and CLOUDP-229222 for more details.
192197
if recovery.ShouldTriggerRecovery(mrs.Status.Phase != mdbstatus.PhaseRunning, mrs.Status.LastTransition) {
193198
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)
194-
automationConfigError := r.updateOmDeploymentRs(ctx, conn, mrs, true, log)
199+
automationConfigError := r.updateOmDeploymentRs(ctx, conn, mrs, certPath, internalClusterCertPath, true, log)
195200
reconcileStatus := r.reconcileMemberResources(ctx, &mrs, log, conn, projectConfig)
196201
if !reconcileStatus.IsOK() {
197202
log.Errorf("Recovery failed because of reconcile errors, %v", reconcileStatus)
@@ -203,7 +208,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) Reconcile(ctx context.Context, request
203208

204209
status := workflow.RunInGivenOrder(publishAutomationConfigFirst,
205210
func() workflow.Status {
206-
if err := r.updateOmDeploymentRs(ctx, conn, mrs, false, log); err != nil {
211+
if err := r.updateOmDeploymentRs(ctx, conn, mrs, certPath, internalClusterCertPath, false, log); err != nil {
207212
return workflow.Failed(err)
208213
}
209214
return workflow.OK()
@@ -692,7 +697,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) saveLastAchievedSpec(ctx context.Conte
692697

693698
// updateOmDeploymentRs performs OM registration operation for the replicaset. So the changes will be finally propagated
694699
// to automation agents in containers
695-
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, certPath, internalClusterCertPath string, isRecovering bool, log *zap.SugaredLogger) error {
696701
reachableHostnames := make([]string, 0)
697702

698703
clusterSpecList, err := mrs.GetClusterSpecItems()
@@ -740,7 +745,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Conte
740745
}
741746
log.Debugf("Existing process Ids: %+v", processIds)
742747

743-
processes, err := process.CreateMongodProcessesWithLimitMulti(r.imageUrls[mcoConstruct.MongodbImageEnv], r.forceEnterprise, mrs, certificateFileName)
748+
processes, err := process.CreateMongodProcessesWithLimitMulti(r.imageUrls[mcoConstruct.MongodbImageEnv], r.forceEnterprise, mrs, certPath)
744749
if err != nil && !isRecovering {
745750
return err
746751
}
@@ -753,7 +758,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Conte
753758
caFilePath := fmt.Sprintf("%s/ca-pem", util.TLSCaMountPath)
754759

755760
agentCertSecretName := mrs.GetSecurity().AgentClientCertificateSecretName(mrs.GetName())
756-
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)
757762
if !status.IsOK() && !isRecovering {
758763
return xerrors.Errorf("failed to enable Authentication for MongoDB Multi Replicaset")
759764
}
@@ -762,7 +767,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Conte
762767

763768
err = conn.ReadUpdateDeployment(
764769
func(d om.Deployment) error {
765-
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)
766771
},
767772
log,
768773
)

controllers/operator/mongodbreplicaset_controller.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,17 +235,17 @@ func (r *ReconcileMongoDbReplicaSet) Reconcile(ctx context.Context, request reco
235235
agentCertSecretSelector := rs.GetSecurity().AgentClientCertificateSecretName(rs.Name)
236236
agentCertSecretSelector.Name += certs.OperatorGeneratedCertSuffix
237237

238-
internalClusterPath := ""
238+
internalClusterCertPath := ""
239239
if internalClusterCertHash != "" {
240-
internalClusterPath = fmt.Sprintf("%s%s", util.InternalClusterAuthMountPath, internalClusterCertHash)
240+
internalClusterCertPath = fmt.Sprintf("%s%s", util.InternalClusterAuthMountPath, internalClusterCertHash)
241241
}
242242

243243
// Recovery prevents some deadlocks that can occur during reconciliation, e.g. the setting of an incorrect automation
244244
// configuration and a subsequent attempt to overwrite it later, the operator would be stuck in Pending phase.
245245
// See CLOUDP-189433 and CLOUDP-229222 for more details.
246246
if recovery.ShouldTriggerRecovery(rs.Status.Phase != mdbstatus.PhaseRunning, rs.Status.LastTransition) {
247247
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, internalClusterPath, agentCertSecretSelector, prometheusCertHash, true).OnErrorPrepend("Failed to create/update (Ops Manager reconciliation phase):")
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):")
249249
deploymentError := create.DatabaseInKubernetes(ctx, r.client, *rs, sts, rsConfig, log)
250250
if deploymentError != nil {
251251
log.Errorf("Recovery failed because of deployment errors, %w", deploymentError)
@@ -261,7 +261,7 @@ func (r *ReconcileMongoDbReplicaSet) Reconcile(ctx context.Context, request reco
261261
}
262262
status = workflow.RunInGivenOrder(publishAutomationConfigFirst(ctx, r.client, *rs, lastSpec, rsConfig, log),
263263
func() workflow.Status {
264-
return r.updateOmDeploymentRs(ctx, conn, rs.Status.Members, rs, sts, log, caFilePath, internalClusterPath, agentCertSecretSelector, prometheusCertHash, false).OnErrorPrepend("Failed to create/update (Ops Manager reconciliation phase):")
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):")
265265
},
266266
func() workflow.Status {
267267
workflowStatus := create.HandlePVCResize(ctx, r.client, &sts, log)
@@ -422,7 +422,7 @@ func AddReplicaSetController(ctx context.Context, mgr manager.Manager, imageUrls
422422

423423
// updateOmDeploymentRs performs OM registration operation for the replicaset. So the changes will be finally propagated
424424
// 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, internalClusterPath string, agentCertSecretSelector corev1.SecretKeySelector, prometheusCertHash string, isRecovering bool) workflow.Status {
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 {
426426
log.Debug("Entering UpdateOMDeployments")
427427
// Only "concrete" RS members should be observed
428428
// - if scaling down, let's observe only members that will remain after scale-down operation
@@ -451,7 +451,7 @@ func (r *ReconcileMongoDbReplicaSet) updateOmDeploymentRs(ctx context.Context, c
451451
replicaSet := replicaset.BuildFromStatefulSetWithReplicas(r.imageUrls[mcoConstruct.MongodbImageEnv], r.forceEnterprise, set, rs.GetSpec(), updatedMembers, rs.CalculateFeatureCompatibilityVersion())
452452
processNames := replicaSet.GetProcessNames()
453453

454-
status, additionalReconciliationRequired := r.updateOmAuthentication(ctx, conn, processNames, rs, agentCertSecretSelector, caFilePath, internalClusterPath, isRecovering, log)
454+
status, additionalReconciliationRequired := r.updateOmAuthentication(ctx, conn, processNames, rs, agentCertSecretSelector, caFilePath, internalClusterCertPath, isRecovering, log)
455455
if !status.IsOK() && !isRecovering {
456456
return status
457457
}
@@ -471,7 +471,7 @@ func (r *ReconcileMongoDbReplicaSet) updateOmDeploymentRs(ctx context.Context, c
471471

472472
err = conn.ReadUpdateDeployment(
473473
func(d om.Deployment) error {
474-
return ReconcileReplicaSetAC(ctx, d, rs.Spec.DbCommonSpec, lastRsConfig.ToMap(), rs.Name, replicaSet, caFilePath, internalClusterPath, &p, log)
474+
return ReconcileReplicaSetAC(ctx, d, rs.Spec.DbCommonSpec, lastRsConfig.ToMap(), rs.Name, replicaSet, caFilePath, internalClusterCertPath, &p, log)
475475
},
476476
log,
477477
)

0 commit comments

Comments
 (0)