Skip to content

Commit 32a5c42

Browse files
CLOUDP-342325 Basic enterprise search support (#309)
# Summary <!-- Enter your issue summary here.--> ## Proof of Work <!-- Enter your proof that it works here.--> ## Checklist - [x] Have you linked a jira ticket and/or is the ticket in the title? - [x] Have you checked whether your jira ticket required DOCSP changes? - [x] Have you added changelog file? - use `skip-changelog` label if not needed - refer to [Changelog files and Release Notes](https://github.com/mongodb/mongodb-kubernetes/blob/master/CONTRIBUTING.md#changelog-files-and-release-notes) section in CONTRIBUTING.md for more details --------- Co-authored-by: Łukasz Sierant <lukasz.sierant@mongodb.com>
1 parent 1eb7247 commit 32a5c42

25 files changed

+1217
-222
lines changed

.evergreen-tasks.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,3 +1300,9 @@ tasks:
13001300
tags: [ "patch-run" ]
13011301
commands:
13021302
- func: "e2e_test"
1303+
1304+
- name: e2e_search_enterprise_basic
1305+
tags: [ "patch-run" ]
1306+
commands:
1307+
- func: "e2e_test"
1308+

.evergreen.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,8 @@ task_groups:
815815
- e2e_replica_set_oidc_workforce
816816
- e2e_sharded_cluster_oidc_m2m_group
817817
- e2e_sharded_cluster_oidc_m2m_user
818+
# MongoDBSearch test group
819+
- e2e_search_enterprise_basic
818820
<<: *teardown_group
819821

820822
# this task group contains just a one task, which is smoke testing whether the operator

controllers/operator/mongodbreplicaset_controller.go

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ import (
44
"context"
55
"fmt"
66

7+
"github.com/blang/semver"
78
"go.uber.org/zap"
89
"golang.org/x/xerrors"
910
"k8s.io/apimachinery/pkg/api/errors"
11+
"k8s.io/apimachinery/pkg/fields"
1012
"k8s.io/apimachinery/pkg/runtime"
13+
"k8s.io/apimachinery/pkg/types"
1114
"sigs.k8s.io/controller-runtime/pkg/client"
1215
"sigs.k8s.io/controller-runtime/pkg/controller"
16+
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
1317
"sigs.k8s.io/controller-runtime/pkg/event"
1418
"sigs.k8s.io/controller-runtime/pkg/handler"
1519
"sigs.k8s.io/controller-runtime/pkg/manager"
@@ -22,6 +26,7 @@ import (
2226

2327
mdbv1 "github.com/mongodb/mongodb-kubernetes/api/v1/mdb"
2428
rolev1 "github.com/mongodb/mongodb-kubernetes/api/v1/role"
29+
searchv1 "github.com/mongodb/mongodb-kubernetes/api/v1/search"
2530
mdbstatus "github.com/mongodb/mongodb-kubernetes/api/v1/status"
2631
"github.com/mongodb/mongodb-kubernetes/controllers/om"
2732
"github.com/mongodb/mongodb-kubernetes/controllers/om/backup"
@@ -39,6 +44,7 @@ import (
3944
"github.com/mongodb/mongodb-kubernetes/controllers/operator/recovery"
4045
"github.com/mongodb/mongodb-kubernetes/controllers/operator/watch"
4146
"github.com/mongodb/mongodb-kubernetes/controllers/operator/workflow"
47+
"github.com/mongodb/mongodb-kubernetes/controllers/search_controller"
4248
mcoConstruct "github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/controllers/construct"
4349
"github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/pkg/kube/annotations"
4450
"github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/pkg/kube/configmap"
@@ -52,6 +58,7 @@ import (
5258
"github.com/mongodb/mongodb-kubernetes/pkg/util/architectures"
5359
"github.com/mongodb/mongodb-kubernetes/pkg/util/env"
5460
util_int "github.com/mongodb/mongodb-kubernetes/pkg/util/int"
61+
"github.com/mongodb/mongodb-kubernetes/pkg/util/maputil"
5562
"github.com/mongodb/mongodb-kubernetes/pkg/vault"
5663
"github.com/mongodb/mongodb-kubernetes/pkg/vault/vaultwatcher"
5764
)
@@ -219,6 +226,8 @@ func (r *ReconcileMongoDbReplicaSet) Reconcile(ctx context.Context, request reco
219226
return r.updateStatus(ctx, rs, workflow.Failed(xerrors.Errorf("Failed to reconcileHostnameOverrideConfigMap: %w", err)), log)
220227
}
221228

229+
shouldMirrorKeyfile := r.applySearchOverrides(ctx, rs, log)
230+
222231
sts := construct.DatabaseStatefulSet(*rs, rsConfig, log)
223232
if status := r.ensureRoles(ctx, rs.Spec.DbCommonSpec, r.enableClusterMongoDBRoles, conn, kube.ObjectKeyFromApiObject(rs), log); !status.IsOK() {
224233
return r.updateStatus(ctx, rs, status, log)
@@ -238,7 +247,7 @@ func (r *ReconcileMongoDbReplicaSet) Reconcile(ctx context.Context, request reco
238247
// See CLOUDP-189433 and CLOUDP-229222 for more details.
239248
if recovery.ShouldTriggerRecovery(rs.Status.Phase != mdbstatus.PhaseRunning, rs.Status.LastTransition) {
240249
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)
241-
automationConfigStatus := r.updateOmDeploymentRs(ctx, conn, rs.Status.Members, rs, sts, log, caFilePath, agentCertSecretSelector, prometheusCertHash, true).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):")
242251
deploymentError := create.DatabaseInKubernetes(ctx, r.client, *rs, sts, rsConfig, log)
243252
if deploymentError != nil {
244253
log.Errorf("Recovery failed because of deployment errors, %w", deploymentError)
@@ -254,7 +263,7 @@ func (r *ReconcileMongoDbReplicaSet) Reconcile(ctx context.Context, request reco
254263
}
255264
status = workflow.RunInGivenOrder(publishAutomationConfigFirst(ctx, r.client, *rs, lastSpec, rsConfig, log),
256265
func() workflow.Status {
257-
return r.updateOmDeploymentRs(ctx, conn, rs.Status.Members, rs, sts, log, caFilePath, agentCertSecretSelector, prometheusCertHash, false).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):")
258267
},
259268
func() workflow.Status {
260269
workflowStatus := create.HandlePVCResize(ctx, r.client, &sts, log)
@@ -408,14 +417,27 @@ func AddReplicaSetController(ctx context.Context, mgr manager.Manager, imageUrls
408417
zap.S().Errorf("Failed to watch for vault secret changes: %w", err)
409418
}
410419
}
420+
421+
err = c.Watch(source.Kind(mgr.GetCache(), &searchv1.MongoDBSearch{},
422+
handler.TypedEnqueueRequestsFromMapFunc(func(ctx context.Context, search *searchv1.MongoDBSearch) []reconcile.Request {
423+
source := search.GetMongoDBResourceRef()
424+
if source == nil {
425+
return []reconcile.Request{}
426+
}
427+
return []reconcile.Request{{NamespacedName: types.NamespacedName{Namespace: source.Namespace, Name: source.Name}}}
428+
})))
429+
if err != nil {
430+
return err
431+
}
432+
411433
zap.S().Infof("Registered controller %s", util.MongoDbReplicaSetController)
412434

413435
return nil
414436
}
415437

416438
// updateOmDeploymentRs performs OM registration operation for the replicaset. So the changes will be finally propagated
417439
// to automation agents in containers
418-
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) 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 {
419441
log.Debug("Entering UpdateOMDeployments")
420442
// Only "concrete" RS members should be observed
421443
// - if scaling down, let's observe only members that will remain after scale-down operation
@@ -469,6 +491,11 @@ func (r *ReconcileMongoDbReplicaSet) updateOmDeploymentRs(ctx context.Context, c
469491

470492
err = conn.ReadUpdateDeployment(
471493
func(d om.Deployment) error {
494+
if shouldMirrorKeyfileForMongot {
495+
if err := r.mirrorKeyfileIntoSecretForMongot(ctx, d, rs, log); err != nil {
496+
return err
497+
}
498+
}
472499
return ReconcileReplicaSetAC(ctx, d, rs.Spec.DbCommonSpec, lastRsConfig.ToMap(), rs.Name, replicaSet, caFilePath, internalClusterPath, &p, log)
473500
},
474501
log,
@@ -609,3 +636,70 @@ func getAllHostsRs(set appsv1.StatefulSet, clusterName string, membersCount int,
609636
hostnames, _ := dns.GetDnsForStatefulSetReplicasSpecified(set, clusterName, membersCount, externalDomain)
610637
return hostnames
611638
}
639+
640+
func (r *ReconcileMongoDbReplicaSet) applySearchOverrides(ctx context.Context, rs *mdbv1.MongoDB, log *zap.SugaredLogger) bool {
641+
search := r.lookupCorrespondingSearchResource(ctx, rs, log)
642+
if search == nil {
643+
log.Debugf("No MongoDBSearch resource found, skipping search overrides")
644+
return false
645+
}
646+
647+
log.Infof("Applying search overrides from MongoDBSearch %s", search.NamespacedName())
648+
649+
if rs.Spec.AdditionalMongodConfig == nil {
650+
rs.Spec.AdditionalMongodConfig = mdbv1.NewEmptyAdditionalMongodConfig()
651+
}
652+
searchMongodConfig := search_controller.GetMongodConfigParameters(search)
653+
rs.Spec.AdditionalMongodConfig.AddOption("setParameter", searchMongodConfig["setParameter"])
654+
655+
mdbVersion, err := semver.ParseTolerant(rs.Spec.Version)
656+
if err != nil {
657+
log.Warnf("Failed to parse MongoDB version %q: %w. Proceeding without the automatic creation of the searchCoordinator role that's necessary for MongoDB <8.2", rs.Spec.Version, err)
658+
} else if semver.MustParse("8.2.0").GT(mdbVersion) {
659+
log.Infof("Polyfilling the searchCoordinator role for MongoDB %s", rs.Spec.Version)
660+
661+
if rs.Spec.Security == nil {
662+
rs.Spec.Security = &mdbv1.Security{}
663+
}
664+
rs.Spec.Security.Roles = append(rs.Spec.Security.Roles, search_controller.SearchCoordinatorRole())
665+
}
666+
667+
return true
668+
}
669+
670+
func (r *ReconcileMongoDbReplicaSet) mirrorKeyfileIntoSecretForMongot(ctx context.Context, d om.Deployment, rs *mdbv1.MongoDB, log *zap.SugaredLogger) error {
671+
keyfileContents := maputil.ReadMapValueAsString(d, "auth", "key")
672+
keyfileSecret := &corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s-keyfile", rs.Name), Namespace: rs.Namespace}}
673+
674+
log.Infof("Mirroring the replicaset %s's keyfile into the secret %s", rs.ObjectKey(), kube.ObjectKeyFromApiObject(keyfileSecret))
675+
676+
_, err := controllerutil.CreateOrUpdate(ctx, r.client, keyfileSecret, func() error {
677+
keyfileSecret.StringData = map[string]string{"keyfile": keyfileContents}
678+
return controllerutil.SetOwnerReference(rs, keyfileSecret, r.client.Scheme())
679+
})
680+
if err != nil {
681+
return xerrors.Errorf("Failed to mirror the replicaset's keyfile into a secret: %w", err)
682+
} else {
683+
return nil
684+
}
685+
}
686+
687+
func (r *ReconcileMongoDbReplicaSet) lookupCorrespondingSearchResource(ctx context.Context, rs *mdbv1.MongoDB, log *zap.SugaredLogger) *searchv1.MongoDBSearch {
688+
var search *searchv1.MongoDBSearch
689+
searchList := &searchv1.MongoDBSearchList{}
690+
if err := r.client.List(ctx, searchList, &client.ListOptions{
691+
FieldSelector: fields.OneTermEqualSelector(search_controller.MongoDBSearchIndexFieldName, rs.GetNamespace()+"/"+rs.GetName()),
692+
}); err != nil {
693+
log.Debugf("Failed to list MongoDBSearch resources: %v", err)
694+
}
695+
// this validates that there is exactly one MongoDBSearch pointing to this resource,
696+
// and that this resource passes search validations. If either fails, proceed without a search target
697+
// for the mongod automation config.
698+
if len(searchList.Items) == 1 {
699+
searchSource := search_controller.NewEnterpriseResourceSearchSource(rs)
700+
if searchSource.Validate() == nil {
701+
search = &searchList.Items[0]
702+
}
703+
}
704+
return search
705+
}

controllers/operator/mongodbsearch_controller.go

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ import (
1414

1515
appsv1 "k8s.io/api/apps/v1"
1616
corev1 "k8s.io/api/core/v1"
17+
apierrors "k8s.io/apimachinery/pkg/api/errors"
1718
ctrl "sigs.k8s.io/controller-runtime"
1819

20+
mdbv1 "github.com/mongodb/mongodb-kubernetes/api/v1/mdb"
1921
searchv1 "github.com/mongodb/mongodb-kubernetes/api/v1/search"
22+
"github.com/mongodb/mongodb-kubernetes/controllers/operator/watch"
2023
"github.com/mongodb/mongodb-kubernetes/controllers/search_controller"
2124
mdbcv1 "github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/api/v1"
22-
"github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/controllers/watch"
2325
kubernetesClient "github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/pkg/kube/client"
2426
"github.com/mongodb/mongodb-kubernetes/pkg/kube/commoncontroller"
2527
"github.com/mongodb/mongodb-kubernetes/pkg/util"
@@ -28,15 +30,14 @@ import (
2830

2931
type MongoDBSearchReconciler struct {
3032
kubeClient kubernetesClient.Client
31-
mdbcWatcher *watch.ResourceWatcher
33+
watch *watch.ResourceWatcher
3234
operatorSearchConfig search_controller.OperatorSearchConfig
3335
}
3436

3537
func newMongoDBSearchReconciler(client client.Client, operatorSearchConfig search_controller.OperatorSearchConfig) *MongoDBSearchReconciler {
36-
mdbcWatcher := watch.New()
3738
return &MongoDBSearchReconciler{
3839
kubeClient: kubernetesClient.NewClient(client),
39-
mdbcWatcher: &mdbcWatcher,
40+
watch: watch.NewResourceWatcher(),
4041
operatorSearchConfig: operatorSearchConfig,
4142
}
4243
}
@@ -51,36 +52,52 @@ func (r *MongoDBSearchReconciler) Reconcile(ctx context.Context, request reconci
5152
return result, err
5253
}
5354

54-
sourceResource, mdbc, err := getSourceMongoDBForSearch(ctx, r.kubeClient, mdbSearch)
55+
searchSource, err := r.getSourceMongoDBForSearch(ctx, r.kubeClient, mdbSearch, log)
5556
if err != nil {
5657
return reconcile.Result{RequeueAfter: time.Second * util.RetryTimeSec}, err
5758
}
5859

59-
if mdbc != nil {
60-
r.mdbcWatcher.Watch(ctx, mdbc.NamespacedName(), request.NamespacedName)
61-
}
60+
r.watch.AddWatchedResourceIfNotAdded(searchSource.KeyfileSecretName(), mdbSearch.Namespace, watch.Secret, mdbSearch.NamespacedName())
6261

63-
reconcileHelper := search_controller.NewMongoDBSearchReconcileHelper(kubernetesClient.NewClient(r.kubeClient), mdbSearch, sourceResource, r.operatorSearchConfig)
62+
reconcileHelper := search_controller.NewMongoDBSearchReconcileHelper(kubernetesClient.NewClient(r.kubeClient), mdbSearch, searchSource, r.operatorSearchConfig)
6463

6564
return reconcileHelper.Reconcile(ctx, log).ReconcileResult()
6665
}
6766

68-
func getSourceMongoDBForSearch(ctx context.Context, kubeClient client.Client, search *searchv1.MongoDBSearch) (search_controller.SearchSourceDBResource, *mdbcv1.MongoDBCommunity, error) {
67+
func (r *MongoDBSearchReconciler) getSourceMongoDBForSearch(ctx context.Context, kubeClient client.Client, search *searchv1.MongoDBSearch, log *zap.SugaredLogger) (search_controller.SearchSourceDBResource, error) {
6968
if search.IsExternalMongoDBSource() {
70-
return search_controller.NewSearchSourceDBResourceFromExternal(search.Namespace, search.Spec.Source.ExternalMongoDBSource), nil, nil
69+
return search_controller.NewExternalSearchSource(search.Namespace, search.Spec.Source.ExternalMongoDBSource), nil
7170
}
7271

7372
sourceMongoDBResourceRef := search.GetMongoDBResourceRef()
7473
if sourceMongoDBResourceRef == nil {
75-
return nil, nil, xerrors.New("MongoDBSearch source MongoDB resource reference is not set")
74+
return nil, xerrors.New("MongoDBSearch source MongoDB resource reference is not set")
75+
}
76+
77+
sourceName := types.NamespacedName{Namespace: search.GetNamespace(), Name: sourceMongoDBResourceRef.Name}
78+
log.Infof("Looking up Search source %s", sourceName)
79+
80+
mdb := &mdbv1.MongoDB{}
81+
if err := kubeClient.Get(ctx, sourceName, mdb); err != nil {
82+
if !apierrors.IsNotFound(err) {
83+
return nil, xerrors.Errorf("error getting MongoDB %s: %w", sourceName, err)
84+
}
85+
} else {
86+
r.watch.AddWatchedResourceIfNotAdded(sourceMongoDBResourceRef.Name, sourceMongoDBResourceRef.Namespace, watch.MongoDB, search.NamespacedName())
87+
return search_controller.NewEnterpriseResourceSearchSource(mdb), nil
7688
}
7789

78-
mdbcName := types.NamespacedName{Namespace: search.GetNamespace(), Name: sourceMongoDBResourceRef.Name}
7990
mdbc := &mdbcv1.MongoDBCommunity{}
80-
if err := kubeClient.Get(ctx, mdbcName, mdbc); err != nil {
81-
return nil, nil, xerrors.Errorf("error getting MongoDBCommunity %s: %w", mdbcName, err)
91+
if err := kubeClient.Get(ctx, sourceName, mdbc); err != nil {
92+
if !apierrors.IsNotFound(err) {
93+
return nil, xerrors.Errorf("error getting MongoDBCommunity %s: %w", sourceName, err)
94+
}
95+
} else {
96+
r.watch.AddWatchedResourceIfNotAdded(sourceMongoDBResourceRef.Name, sourceMongoDBResourceRef.Namespace, "MongoDBCommunity", search.NamespacedName())
97+
return search_controller.NewCommunityResourceSearchSource(mdbc), nil
8298
}
83-
return search_controller.NewSearchSourceDBResourceFromMongoDBCommunity(mdbc), mdbc, nil
99+
100+
return nil, xerrors.Errorf("No database resource named %s found", sourceName)
84101
}
85102

86103
func mdbcSearchIndexBuilder(rawObj client.Object) []string {
@@ -103,7 +120,9 @@ func AddMongoDBSearchController(ctx context.Context, mgr manager.Manager, operat
103120
return ctrl.NewControllerManagedBy(mgr).
104121
WithOptions(controller.Options{MaxConcurrentReconciles: env.ReadIntOrDefault(util.MaxConcurrentReconcilesEnv, 1)}). // nolint:forbidigo
105122
For(&searchv1.MongoDBSearch{}).
106-
Watches(&mdbcv1.MongoDBCommunity{}, r.mdbcWatcher).
123+
Watches(&mdbv1.MongoDB{}, &watch.ResourcesHandler{ResourceType: watch.MongoDB, ResourceWatcher: r.watch}).
124+
Watches(&mdbcv1.MongoDBCommunity{}, &watch.ResourcesHandler{ResourceType: "MongoDBCommunity", ResourceWatcher: r.watch}).
125+
Watches(&corev1.Secret{}, &watch.ResourcesHandler{ResourceType: watch.Secret, ResourceWatcher: r.watch}).
107126
Owns(&appsv1.StatefulSet{}).
108127
Owns(&corev1.Secret{}).
109128
Complete(r)

controllers/operator/mongodbsearch_controller_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ import (
88
"github.com/ghodss/yaml"
99
"github.com/stretchr/testify/assert"
1010
"k8s.io/apimachinery/pkg/types"
11-
"k8s.io/client-go/util/workqueue"
1211
"k8s.io/utils/ptr"
1312
"sigs.k8s.io/controller-runtime/pkg/client"
14-
"sigs.k8s.io/controller-runtime/pkg/controller/controllertest"
15-
"sigs.k8s.io/controller-runtime/pkg/event"
1613
"sigs.k8s.io/controller-runtime/pkg/reconcile"
1714

1815
appsv1 "k8s.io/api/apps/v1"
@@ -29,6 +26,7 @@ import (
2926
mdbcv1 "github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/api/v1"
3027
"github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/api/v1/common"
3128
"github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/pkg/mongot"
29+
"github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/pkg/util/constants"
3230
)
3331

3432
func newMongoDBCommunity(name, namespace string) *mdbcv1.MongoDBCommunity {
@@ -62,7 +60,16 @@ func newSearchReconcilerWithOperatorConfig(
6260
builder.WithIndex(&searchv1.MongoDBSearch{}, search_controller.MongoDBSearchIndexFieldName, mdbcSearchIndexBuilder)
6361

6462
if mdbc != nil {
65-
builder.WithObjects(mdbc)
63+
keyfileSecret := &corev1.Secret{
64+
ObjectMeta: metav1.ObjectMeta{
65+
Name: mdbc.GetAgentKeyfileSecretNamespacedName().Name,
66+
Namespace: mdbc.Namespace,
67+
},
68+
StringData: map[string]string{
69+
constants.AgentKeyfileKey: "keyfile",
70+
},
71+
}
72+
builder.WithObjects(mdbc, keyfileSecret)
6673
}
6774

6875
for _, search := range searches {
@@ -183,10 +190,6 @@ func TestMongoDBSearchReconcile_Success(t *testing.T) {
183190
sts := &appsv1.StatefulSet{}
184191
err = c.Get(ctx, search.StatefulSetNamespacedName(), sts)
185192
assert.NoError(t, err)
186-
187-
queue := controllertest.Queue{Interface: workqueue.New()}
188-
reconciler.mdbcWatcher.Create(ctx, event.CreateEvent{Object: mdbc}, &queue)
189-
assert.Equal(t, 1, queue.Len())
190193
}
191194

192195
func checkSearchReconcileFailed(

controllers/operator/watch/config_change_handler.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import (
1414
"sigs.k8s.io/controller-runtime/pkg/reconcile"
1515

1616
corev1 "k8s.io/api/core/v1"
17-
18-
rolev1 "github.com/mongodb/mongodb-kubernetes/api/v1/role"
1917
)
2018

2119
// Type is an enum for all kubernetes types watched by controller for changes for configuration
@@ -87,10 +85,14 @@ func (c *ResourcesHandler) doHandle(namespace, name string, q workqueue.RateLimi
8785

8886
// Seems we don't need to react on config map/secret removal..
8987
func (c *ResourcesHandler) Delete(ctx context.Context, e event.DeleteEvent, q workqueue.RateLimitingInterface) {
90-
switch v := e.Object.(type) {
91-
case *rolev1.ClusterMongoDBRole:
92-
c.doHandle(v.GetNamespace(), v.GetName(), q)
88+
switch e.Object.(type) {
89+
case *corev1.ConfigMap:
90+
return
91+
case *corev1.Secret:
92+
return
9393
}
94+
95+
c.doHandle(e.Object.GetNamespace(), e.Object.GetName(), q)
9496
}
9597

9698
func (c *ResourcesHandler) Generic(ctx context.Context, _ event.GenericEvent, _ workqueue.RateLimitingInterface) {

0 commit comments

Comments
 (0)