Skip to content

Commit ca1a717

Browse files
committed
Merge branch 'fealebenpae/enterprise-search' into fealebenpae/enterprise-search-snippets
2 parents d7906ba + 46f721b commit ca1a717

34 files changed

+273
-177
lines changed

.evergreen-functions.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ functions:
456456
content_type: text/plain
457457
- command: attach.xunit_results
458458
params:
459+
continue_on_err: true
459460
file: "src/github.com/mongodb/mongodb-kubernetes/logs/myreport.xml"
460461

461462
upload_e2e_logs_gotest:

.evergreen.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ buildvariants:
14461446
run_on:
14471447
- rhel9-power-small
14481448
- rhel9-power-large
1449-
allowed_requesters: [ "patch", "github_tag" ]
1449+
allowed_requesters: [ "patch", "github_tag" , "commit"]
14501450
depends_on:
14511451
- name: build_operator_ubi
14521452
variant: init_test_run
@@ -1469,7 +1469,7 @@ buildvariants:
14691469
run_on:
14701470
- rhel9-zseries-small
14711471
- rhel9-zseries-large
1472-
allowed_requesters: [ "patch", "github_tag" ]
1472+
allowed_requesters: [ "patch", "github_tag", "commit"]
14731473
depends_on:
14741474
- name: build_operator_ubi
14751475
variant: init_test_run
@@ -1491,7 +1491,7 @@ buildvariants:
14911491
tags: [ "e2e_test_suite", "e2e_smoke_release_test_suite" ]
14921492
run_on:
14931493
- ubuntu2204-arm64-large
1494-
allowed_requesters: [ "patch", "github_tag" ]
1494+
allowed_requesters: [ "patch", "github_tag", "commit"]
14951495
<<: *base_no_om_image_dependency
14961496
tasks:
14971497
- name: e2e_smoke_arm_task_group
@@ -1501,7 +1501,7 @@ buildvariants:
15011501
tags: [ "e2e_test_suite", "e2e_smoke_release_test_suite", "static" ]
15021502
run_on:
15031503
- ubuntu2204-arm64-large
1504-
allowed_requesters: [ "patch", "github_tag" ]
1504+
allowed_requesters: [ "patch", "github_tag", "commit"]
15051505
<<: *base_no_om_image_dependency
15061506
tasks:
15071507
- name: e2e_smoke_arm_task_group
@@ -1512,7 +1512,7 @@ buildvariants:
15121512
run_on:
15131513
- rhel9-zseries-small
15141514
- rhel9-zseries-large
1515-
allowed_requesters: [ "patch", "github_tag" ]
1515+
allowed_requesters: [ "patch", "github_tag", "commit"]
15161516
depends_on:
15171517
- name: build_operator_ubi
15181518
variant: init_test_run
@@ -1535,7 +1535,7 @@ buildvariants:
15351535
run_on:
15361536
- rhel9-power-small
15371537
- rhel9-power-large
1538-
allowed_requesters: [ "patch", "github_tag" ]
1538+
allowed_requesters: [ "patch", "github_tag", "commit"]
15391539
depends_on:
15401540
- name: build_operator_ubi
15411541
variant: init_test_run

config/manager/manager.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ spec:
8787
- name: OPS_MANAGER_IMAGE_PULL_POLICY
8888
value: Always
8989
- name: AGENT_IMAGE
90-
value: "quay.io/mongodb/mongodb-agent:108.0.2.8729-1"
90+
value: "quay.io/mongodb/mongodb-agent:108.0.12.8846-1"
9191
- name: MDB_AGENT_IMAGE_REPOSITORY
9292
value: "quay.io/mongodb/mongodb-agent"
9393
- name: MONGODB_IMAGE

controllers/operator/authentication_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ func TestUpdateOmAuthentication_NoAuthenticationEnabled(t *testing.T) {
9191

9292
kubeClient, omConnectionFactory := mock.NewDefaultFakeClient(rs)
9393
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
94-
r.updateOmAuthentication(ctx, conn, processNames, rs, "", "", "", false, zap.S())
94+
agentCertSecretSelector := rs.GetSecurity().AgentClientCertificateSecretName(rs.Name)
95+
r.updateOmAuthentication(ctx, conn, processNames, rs, agentCertSecretSelector, "", "", false, zap.S())
9596

9697
ac, _ := conn.ReadAutomationConfig()
9798

@@ -112,7 +113,8 @@ func TestUpdateOmAuthentication_EnableX509_TlsNotEnabled(t *testing.T) {
112113

113114
kubeClient, omConnectionFactory := mock.NewDefaultFakeClient(rs)
114115
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
115-
status, isMultiStageReconciliation := r.updateOmAuthentication(ctx, conn, []string{"my-rs-0", "my-rs-1", "my-rs-2"}, rs, "", "", "", false, zap.S())
116+
agentCertSecretSelector := rs.GetSecurity().AgentClientCertificateSecretName(rs.Name)
117+
status, isMultiStageReconciliation := r.updateOmAuthentication(ctx, conn, []string{"my-rs-0", "my-rs-1", "my-rs-2"}, rs, agentCertSecretSelector, "", "", false, zap.S())
116118

117119
assert.True(t, status.IsOK(), "configuring both options at once should not result in a failed status")
118120
assert.True(t, isMultiStageReconciliation, "configuring both tls and x509 at once should result in a multi stage reconciliation")
@@ -124,7 +126,8 @@ func TestUpdateOmAuthentication_EnableX509_WithTlsAlreadyEnabled(t *testing.T) {
124126
omConnectionFactory := om.NewCachedOMConnectionFactoryWithInitializedConnection(om.NewMockedOmConnection(deployment.CreateFromReplicaSet("fake-mongoDBImage", false, rs)))
125127
kubeClient := mock.NewDefaultFakeClientWithOMConnectionFactory(omConnectionFactory, rs)
126128
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
127-
status, isMultiStageReconciliation := r.updateOmAuthentication(ctx, omConnectionFactory.GetConnection(), []string{"my-rs-0", "my-rs-1", "my-rs-2"}, rs, "", "", "", false, zap.S())
129+
agentCertSecretSelector := rs.GetSecurity().AgentClientCertificateSecretName(rs.Name)
130+
status, isMultiStageReconciliation := r.updateOmAuthentication(ctx, omConnectionFactory.GetConnection(), []string{"my-rs-0", "my-rs-1", "my-rs-2"}, rs, agentCertSecretSelector, "", "", false, zap.S())
128131

129132
assert.True(t, status.IsOK(), "configuring x509 when tls has already been enabled should not result in a failed status")
130133
assert.False(t, isMultiStageReconciliation, "if tls is already enabled, we should be able to configure x509 is a single reconciliation")
@@ -140,7 +143,8 @@ func TestUpdateOmAuthentication_AuthenticationIsNotConfigured_IfAuthIsNotSet(t *
140143
kubeClient := mock.NewDefaultFakeClientWithOMConnectionFactory(omConnectionFactory, rs)
141144
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
142145

143-
status, _ := r.updateOmAuthentication(ctx, omConnectionFactory.GetConnection(), []string{"my-rs-0", "my-rs-1", "my-rs-2"}, rs, "", "", "", false, zap.S())
146+
agentCertSecretSelector := rs.GetSecurity().AgentClientCertificateSecretName(rs.Name)
147+
status, _ := r.updateOmAuthentication(ctx, omConnectionFactory.GetConnection(), []string{"my-rs-0", "my-rs-1", "my-rs-2"}, rs, agentCertSecretSelector, "", "", false, zap.S())
144148
assert.True(t, status.IsOK(), "no authentication should have been configured")
145149

146150
ac, _ := omConnectionFactory.GetConnection().ReadAutomationConfig()
@@ -211,7 +215,8 @@ func TestUpdateOmAuthentication_EnableX509_FromEmptyDeployment(t *testing.T) {
211215
r := newReplicaSetReconciler(ctx, kubeClient, nil, "", "", false, false, omConnectionFactory.GetConnectionFunc)
212216
createAgentCSRs(t, ctx, 1, r.client, certsv1.CertificateApproved)
213217

214-
status, isMultiStageReconciliation := r.updateOmAuthentication(ctx, omConnectionFactory.GetConnection(), []string{"my-rs-0", "my-rs-1", "my-rs-2"}, rs, "", "", "", false, zap.S())
218+
agentCertSecretSelector := rs.GetSecurity().AgentClientCertificateSecretName(rs.Name)
219+
status, isMultiStageReconciliation := r.updateOmAuthentication(ctx, omConnectionFactory.GetConnection(), []string{"my-rs-0", "my-rs-1", "my-rs-2"}, rs, agentCertSecretSelector, "", "", false, zap.S())
215220
assert.True(t, status.IsOK(), "configuring x509 and tls when there are no processes should not result in a failed status")
216221
assert.False(t, isMultiStageReconciliation, "if we are enabling tls and x509 at once, this should be done in a single reconciliation")
217222
}

controllers/operator/common_controller.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ func getSubjectFromCertificate(cert string) (string, error) {
407407
// enables/disables authentication. If the authentication can't be fully configured, a boolean value indicating that
408408
// an additional reconciliation needs to be queued up to fully make the authentication changes is returned.
409409
// Note: updateOmAuthentication needs to be called before reconciling other auth related settings.
410-
func (r *ReconcileCommonController) updateOmAuthentication(ctx context.Context, conn om.Connection, processNames []string, ar authentication.AuthResource, agentCertSecretName string, caFilepath string, clusterFilePath string, isRecovering bool, log *zap.SugaredLogger) (status workflow.Status, multiStageReconciliation bool) {
410+
func (r *ReconcileCommonController) updateOmAuthentication(ctx context.Context, conn om.Connection, processNames []string, ar authentication.AuthResource, agentCertSecretSelector corev1.SecretKeySelector, caFilepath string, clusterFilePath string, isRecovering bool, log *zap.SugaredLogger) (status workflow.Status, multiStageReconciliation bool) {
411411
// don't touch authentication settings if resource has not been configured with them
412412
if ar.GetSecurity() == nil || ar.GetSecurity().Authentication == nil {
413413
return workflow.OK(), false
@@ -480,17 +480,13 @@ func (r *ReconcileCommonController) updateOmAuthentication(ctx context.Context,
480480

481481
log.Debugf("Using authentication options %+v", authentication.Redact(authOpts))
482482

483-
agentSecretSelector := ar.GetSecurity().AgentClientCertificateSecretName(ar.GetName())
484-
if agentCertSecretName != "" {
485-
agentSecretSelector.Name = agentCertSecretName
486-
}
487483
wantToEnableAuthentication := ar.GetSecurity().Authentication.Enabled
488484
if wantToEnableAuthentication && canConfigureAuthentication(ac, ar.GetSecurity().Authentication.GetModes(), log) {
489485
log.Info("Configuring authentication for MongoDB resource")
490486

491487
if ar.GetSecurity().ShouldUseX509(ac.Auth.AutoAuthMechanism) || ar.GetSecurity().ShouldUseClientCertificates() {
492488
agentSecret := &corev1.Secret{}
493-
if err := r.client.Get(ctx, kube.ObjectKey(ar.GetNamespace(), agentSecretSelector.Name), agentSecret); client.IgnoreNotFound(err) != nil {
489+
if err := r.client.Get(ctx, kube.ObjectKey(ar.GetNamespace(), agentCertSecretSelector.Name), agentSecret); client.IgnoreNotFound(err) != nil {
494490
return workflow.Failed(err), false
495491
}
496492
// If the agent secret is of type TLS, we can find the certificate under the standard key,
@@ -500,10 +496,10 @@ func (r *ReconcileCommonController) updateOmAuthentication(ctx context.Context,
500496
//
501497
// Important: In multi cluster it is working with the TLS secret in the central cluster, hence below selector update.
502498
if agentSecret.Type == corev1.SecretTypeTLS {
503-
agentSecretSelector.Key = corev1.TLSCertKey
499+
agentCertSecretSelector.Key = corev1.TLSCertKey
504500
}
505501

506-
authOpts, err = r.configureAgentSubjects(ctx, ar.GetNamespace(), agentSecretSelector, authOpts, log)
502+
authOpts, err = r.configureAgentSubjects(ctx, ar.GetNamespace(), agentCertSecretSelector, authOpts, log)
507503
if err != nil {
508504
return workflow.Failed(xerrors.Errorf("error configuring agent subjects: %w", err)), false
509505
}
@@ -534,17 +530,17 @@ func (r *ReconcileCommonController) updateOmAuthentication(ctx context.Context,
534530
return workflow.OK(), true
535531
} else {
536532
agentSecret := &corev1.Secret{}
537-
if err := r.client.Get(ctx, kube.ObjectKey(ar.GetNamespace(), agentSecretSelector.Name), agentSecret); client.IgnoreNotFound(err) != nil {
533+
if err := r.client.Get(ctx, kube.ObjectKey(ar.GetNamespace(), agentCertSecretSelector.Name), agentSecret); client.IgnoreNotFound(err) != nil {
538534
return workflow.Failed(err), false
539535
}
540536

541537
if agentSecret.Type == corev1.SecretTypeTLS {
542-
agentSecretSelector.Name = fmt.Sprintf("%s%s", agentSecretSelector.Name, certs.OperatorGeneratedCertSuffix)
538+
agentCertSecretSelector.Name = fmt.Sprintf("%s%s", agentCertSecretSelector.Name, certs.OperatorGeneratedCertSuffix)
543539
}
544540

545541
// Should not fail if the Secret object with agent certs is not found.
546542
// It will only exist on x509 client auth enabled deployments.
547-
userOpts, err := r.readAgentSubjectsFromSecret(ctx, ar.GetNamespace(), agentSecretSelector, log)
543+
userOpts, err := r.readAgentSubjectsFromSecret(ctx, ar.GetNamespace(), agentCertSecretSelector, log)
548544
err = client.IgnoreNotFound(err)
549545
if err != nil {
550546
return workflow.Failed(err), true

controllers/operator/construct/database_construction.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ func buildDatabaseStatefulSetConfigurationFunction(mdb databaseStatefulSetSource
466466
appLabelKey: opts.ServiceName,
467467
}
468468

469-
annotationFunc := statefulset.WithAnnotations(defaultPodAnnotations(opts.CertificateHash))
469+
annotationFunc := statefulset.WithAnnotations(defaultStatefulSetAnnotations(opts.CertificateHash))
470470
podTemplateAnnotationFunc := podtemplatespec.NOOP()
471471

472472
annotationFunc = statefulset.Apply(
@@ -1057,11 +1057,8 @@ func DatabaseStartupProbe() probes.Modification {
10571057
)
10581058
}
10591059

1060-
func defaultPodAnnotations(certHash string) map[string]string {
1060+
func defaultStatefulSetAnnotations(certHash string) map[string]string {
10611061
return map[string]string{
1062-
// This annotation is necessary to trigger a pod restart
1063-
// if the certificate secret is out of date. This happens if
1064-
// existing certificates have been replaced/rotated/renewed.
10651062
certs.CertHashAnnotationKey: certHash,
10661063
}
10671064
}

controllers/operator/mongodbmultireplicaset_controller.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -758,9 +758,8 @@ func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Conte
758758

759759
caFilePath := fmt.Sprintf("%s/ca-pem", util.TLSCaMountPath)
760760

761-
// We do not provide an agentCertSecretName on purpose because then we will default to the non pem secret on the central cluster.
762-
// Below method has special code handling reading certificates from the central cluster in that case.
763-
status, additionalReconciliationRequired := r.updateOmAuthentication(ctx, conn, rs.GetProcessNames(), &mrs, "", caFilePath, internalClusterPath, isRecovering, log)
761+
agentCertSecretName := mrs.GetSecurity().AgentClientCertificateSecretName(mrs.GetName())
762+
status, additionalReconciliationRequired := r.updateOmAuthentication(ctx, conn, rs.GetProcessNames(), &mrs, agentCertSecretName, caFilePath, internalClusterPath, isRecovering, log)
764763
if !status.IsOK() && !isRecovering {
765764
return xerrors.Errorf("failed to enable Authentication for MongoDB Multi Replicaset")
766765
}

controllers/operator/mongodbreplicaset_controller.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,15 @@ func (r *ReconcileMongoDbReplicaSet) Reconcile(ctx context.Context, request reco
239239
}
240240
}
241241

242-
agentCertSecretName := rs.GetSecurity().AgentClientCertificateSecretName(rs.Name).Name
243-
agentCertSecretName += certs.OperatorGeneratedCertSuffix
242+
agentCertSecretSelector := rs.GetSecurity().AgentClientCertificateSecretName(rs.Name)
243+
agentCertSecretSelector.Name += certs.OperatorGeneratedCertSuffix
244244

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

438438
// updateOmDeploymentRs performs OM registration operation for the replicaset. So the changes will be finally propagated
439439
// to automation agents in containers
440-
func (r *ReconcileMongoDbReplicaSet) updateOmDeploymentRs(ctx context.Context, conn om.Connection, membersNumberBefore int, rs *mdbv1.MongoDB, set appsv1.StatefulSet, log *zap.SugaredLogger, caFilePath string, agentCertSecretName string, prometheusCertHash string, isRecovering bool, shouldMirrorKeyfileForMongot bool) workflow.Status {
440+
func (r *ReconcileMongoDbReplicaSet) updateOmDeploymentRs(ctx context.Context, conn om.Connection, membersNumberBefore int, rs *mdbv1.MongoDB, set appsv1.StatefulSet, log *zap.SugaredLogger, caFilePath string, agentCertSecretSelector corev1.SecretKeySelector, prometheusCertHash string, isRecovering bool, shouldMirrorKeyfileForMongot bool) workflow.Status {
441441
log.Debug("Entering UpdateOMDeployments")
442442
// Only "concrete" RS members should be observed
443443
// - if scaling down, let's observe only members that will remain after scale-down operation
@@ -471,7 +471,7 @@ func (r *ReconcileMongoDbReplicaSet) updateOmDeploymentRs(ctx context.Context, c
471471
internalClusterPath = fmt.Sprintf("%s%s", util.InternalClusterAuthMountPath, hash)
472472
}
473473

474-
status, additionalReconciliationRequired := r.updateOmAuthentication(ctx, conn, processNames, rs, agentCertSecretName, caFilePath, internalClusterPath, isRecovering, log)
474+
status, additionalReconciliationRequired := r.updateOmAuthentication(ctx, conn, processNames, rs, agentCertSecretSelector, caFilePath, internalClusterPath, isRecovering, log)
475475
if !status.IsOK() && !isRecovering {
476476
return status
477477
}

0 commit comments

Comments
 (0)