-
Notifications
You must be signed in to change notification settings - Fork 14
CLOUDP-290847: Remove cert hash annotations #383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
m1kola
wants to merge
1
commit into
mongodb:master
Choose a base branch
from
m1kola:remove_certs_hash_annotations
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+65
−85
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,12 +171,32 @@ func (r *ReconcileMongoDbMultiReplicaSet) Reconcile(ctx context.Context, request | |
return r.updateStatus(ctx, &mrs, workflow.Failed(err), log) | ||
} | ||
|
||
// If tls is enabled we need to configure the "processes" array in opsManager/Cloud Manager with the | ||
// correct tlsCertPath, with the new tls design, this path has the certHash in it(so that cert can be rotated | ||
// without pod restart). | ||
tlsCertPath := "" | ||
internalClusterCertPath := "" | ||
if mrs.Spec.Security.IsTLSEnabled() { | ||
certSecretName := mrs.Spec.GetSecurity().MemberCertificateSecretName(mrs.Name) | ||
internalClusterCertSecretName := mrs.Spec.GetSecurity().InternalClusterAuthSecretName(mrs.Name) | ||
tlsCertHash := enterprisepem.ReadHashFromSecret(ctx, r.SecretClient, mrs.Namespace, certSecretName, "", log) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that func (r *ReconcileCommonController) tlsCertHashAndPath(ctx, ...) (string, string) {
tlsCertHash := enterprisepem.ReadHashFromSecret(ctx, r.SecretClient, mrs.Namespace, certSecretName, "", log)
if tlsCertHash == "" {
return "", ""
}
return tlsCertHash, fmt.Sprintf("%s/%s", util.TLSCertMountPath, tlsCertHash)
} |
||
internalClusterCertHash := enterprisepem.ReadHashFromSecret(ctx, r.SecretClient, mrs.Namespace, internalClusterCertSecretName, "", log) | ||
|
||
if internalClusterCertHash != "" { | ||
internalClusterCertPath = fmt.Sprintf("%s%s", util.InternalClusterAuthMountPath, internalClusterCertHash) | ||
} | ||
|
||
if tlsCertHash != "" { | ||
tlsCertPath = fmt.Sprintf("%s/%s", util.TLSCertMountPath, tlsCertHash) | ||
} | ||
} | ||
|
||
// Recovery prevents some deadlocks that can occur during reconciliation, e.g. the setting of an incorrect automation | ||
// configuration and a subsequent attempt to overwrite it later, the operator would be stuck in Pending phase. | ||
// See CLOUDP-189433 and CLOUDP-229222 for more details. | ||
if recovery.ShouldTriggerRecovery(mrs.Status.Phase != mdbstatus.PhaseRunning, mrs.Status.LastTransition) { | ||
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) | ||
automationConfigError := r.updateOmDeploymentRs(ctx, conn, mrs, true, log) | ||
automationConfigError := r.updateOmDeploymentRs(ctx, conn, mrs, tlsCertPath, internalClusterCertPath, true, log) | ||
reconcileStatus := r.reconcileMemberResources(ctx, &mrs, log, conn, projectConfig) | ||
if !reconcileStatus.IsOK() { | ||
log.Errorf("Recovery failed because of reconcile errors, %v", reconcileStatus) | ||
|
@@ -188,7 +208,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) Reconcile(ctx context.Context, request | |
|
||
status := workflow.RunInGivenOrder(publishAutomationConfigFirst, | ||
func() workflow.Status { | ||
if err := r.updateOmDeploymentRs(ctx, conn, mrs, false, log); err != nil { | ||
if err := r.updateOmDeploymentRs(ctx, conn, mrs, tlsCertPath, internalClusterCertPath, false, log); err != nil { | ||
return workflow.Failed(err) | ||
} | ||
return workflow.OK() | ||
|
@@ -499,7 +519,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) reconcileStatefulSets(ctx context.Cont | |
mconstruct.WithClusterNum(clusterNum), | ||
Replicas(replicasThisReconciliation), | ||
mconstruct.WithStsOverride(&stsOverride), | ||
mconstruct.WithAnnotations(mrs.Name, certHash), | ||
mconstruct.WithAnnotations(mrs.Name), | ||
mconstruct.WithServiceName(mrs.MultiHeadlessServiceName(clusterNum)), | ||
PodEnvVars(newPodVars(conn, projectConfig, mrs.Spec.LogLevel)), | ||
CurrentAgentAuthMechanism(currentAgentAuthMode), | ||
|
@@ -677,7 +697,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) saveLastAchievedSpec(ctx context.Conte | |
|
||
// updateOmDeploymentRs performs OM registration operation for the replicaset. So the changes will be finally propagated | ||
// to automation agents in containers | ||
func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Context, conn om.Connection, mrs mdbmultiv1.MongoDBMultiCluster, isRecovering bool, log *zap.SugaredLogger) error { | ||
func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Context, conn om.Connection, mrs mdbmultiv1.MongoDBMultiCluster, tlsCertPath, internalClusterCertPath string, isRecovering bool, log *zap.SugaredLogger) error { | ||
reachableHostnames := make([]string, 0) | ||
|
||
clusterSpecList, err := mrs.GetClusterSpecItems() | ||
|
@@ -725,28 +745,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Conte | |
} | ||
log.Debugf("Existing process Ids: %+v", processIds) | ||
|
||
certificateFileName := "" | ||
internalClusterPath := "" | ||
|
||
// If tls is enabled we need to configure the "processes" array in opsManager/Cloud Manager with the | ||
// correct certFilePath, with the new tls design, this path has the certHash in it(so that cert can be rotated | ||
// without pod restart), we can get the cert hash from any of the statefulset, here we pick the statefulset in the first cluster. | ||
if mrs.Spec.Security.IsTLSEnabled() { | ||
firstStatefulSet, err := r.firstStatefulSet(ctx, &mrs) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if hash := firstStatefulSet.Annotations[util.InternalCertAnnotationKey]; hash != "" { | ||
internalClusterPath = fmt.Sprintf("%s%s", util.InternalClusterAuthMountPath, hash) | ||
} | ||
|
||
if certificateHash := firstStatefulSet.Annotations[certs.CertHashAnnotationKey]; certificateHash != "" { | ||
certificateFileName = fmt.Sprintf("%s/%s", util.TLSCertMountPath, certificateHash) | ||
} | ||
} | ||
|
||
processes, err := process.CreateMongodProcessesWithLimitMulti(r.imageUrls[mcoConstruct.MongodbImageEnv], r.forceEnterprise, mrs, certificateFileName) | ||
processes, err := process.CreateMongodProcessesWithLimitMulti(r.imageUrls[mcoConstruct.MongodbImageEnv], r.forceEnterprise, mrs, tlsCertPath) | ||
if err != nil && !isRecovering { | ||
return err | ||
} | ||
|
@@ -759,7 +758,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Conte | |
caFilePath := fmt.Sprintf("%s/ca-pem", util.TLSCaMountPath) | ||
|
||
agentCertSecretName := mrs.GetSecurity().AgentClientCertificateSecretName(mrs.GetName()) | ||
status, additionalReconciliationRequired := r.updateOmAuthentication(ctx, conn, rs.GetProcessNames(), &mrs, agentCertSecretName, caFilePath, internalClusterPath, isRecovering, log) | ||
status, additionalReconciliationRequired := r.updateOmAuthentication(ctx, conn, rs.GetProcessNames(), &mrs, agentCertSecretName, caFilePath, internalClusterCertPath, isRecovering, log) | ||
if !status.IsOK() && !isRecovering { | ||
return xerrors.Errorf("failed to enable Authentication for MongoDB Multi Replicaset") | ||
} | ||
|
@@ -768,7 +767,7 @@ func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Conte | |
|
||
err = conn.ReadUpdateDeployment( | ||
func(d om.Deployment) error { | ||
return ReconcileReplicaSetAC(ctx, d, mrs.Spec.DbCommonSpec, lastMongodbConfig, mrs.Name, rs, caFilePath, internalClusterPath, nil, log) | ||
return ReconcileReplicaSetAC(ctx, d, mrs.Spec.DbCommonSpec, lastMongodbConfig, mrs.Name, rs, caFilePath, internalClusterCertPath, nil, log) | ||
}, | ||
log, | ||
) | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: was this annotation
CertHashAnnotationKey
andInternalCertAnnotationKey
only used internally? User might use it for any reason? Even if not I see this as API change and we should add changelog mentioning that this has gone away + detail the reasoning behind the change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is internal implementation detail. Users do not interact with this annotation: controller takes user proved secret with a certs, generates a concatenated cert and writes into a new secret. And from from that generated secret it calculates the hash which is being written into STS's annotation.
It is not an API change (since users do not interface with it). I do not think it is worth adding a change log about it.