From 17d4a45f77894256b4e8bdfdac60d2cf379a6bde Mon Sep 17 00:00:00 2001 From: Anand Singh Date: Tue, 8 Jul 2025 11:46:00 +0200 Subject: [PATCH 1/2] add filter for mongodb search version 1.47.0 --- .../operator/mongodbsearch_controller_test.go | 10 ++++++++++ .../mongodbsearch_reconcile_helper.go | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/controllers/operator/mongodbsearch_controller_test.go b/controllers/operator/mongodbsearch_controller_test.go index 3c4cfb556..0bdd824e1 100644 --- a/controllers/operator/mongodbsearch_controller_test.go +++ b/controllers/operator/mongodbsearch_controller_test.go @@ -203,3 +203,13 @@ func TestMongoDBSearchReconcile_MultipleSearchResources(t *testing.T) { checkSearchReconcileFailed(ctx, t, reconciler, c, search1, "multiple MongoDBSearch") } + +func TestMongoDBSearchReconcile_InvalidSearchImageVersion(t *testing.T) { + ctx := context.Background() + search := newMongoDBSearch("search", mock.TestNamespace, "mdb") + mdbc := newMongoDBCommunity("mdb", mock.TestNamespace) + search.Spec.Version = "1.47.0" + reconciler, c := newSearchReconciler(mdbc, search) + + checkSearchReconcileFailed(ctx, t, reconciler, c, search, "MongoDBSearch version 1.47.0 is not supported") +} diff --git a/controllers/search_controller/mongodbsearch_reconcile_helper.go b/controllers/search_controller/mongodbsearch_reconcile_helper.go index 59523ce8e..f7461b774 100644 --- a/controllers/search_controller/mongodbsearch_reconcile_helper.go +++ b/controllers/search_controller/mongodbsearch_reconcile_helper.go @@ -76,6 +76,10 @@ func (r *MongoDBSearchReconcileHelper) reconcile(ctx context.Context, log *zap.S return workflow.Failed(err) } + if err := r.ValidateSearchImageVersion(); err != nil { + return workflow.Failed(err) + } + if err := r.ValidateSingleMongoDBSearchForSearchSource(ctx); err != nil { return workflow.Failed(err) } @@ -269,3 +273,11 @@ func (r *MongoDBSearchReconcileHelper) ValidateSingleMongoDBSearchForSearchSourc return nil } + +func (r *MongoDBSearchReconcileHelper) ValidateSearchImageVersion() error { + if r.mdbSearch.Spec.Version == "1.47.0" { + return xerrors.New("MongoDBSearch version 1.47.0 is not supported") + } + + return nil +} From 5ae3b262174d4f03d8b1aa82cc16e4da25301e5f Mon Sep 17 00:00:00 2001 From: Anand Singh Date: Wed, 9 Jul 2025 15:25:29 +0200 Subject: [PATCH 2/2] add filter for mongodb search version 1.47.0 --- .../mongodbsearch_reconcile_helper.go | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/controllers/search_controller/mongodbsearch_reconcile_helper.go b/controllers/search_controller/mongodbsearch_reconcile_helper.go index f7461b774..6bb8cc886 100644 --- a/controllers/search_controller/mongodbsearch_reconcile_helper.go +++ b/controllers/search_controller/mongodbsearch_reconcile_helper.go @@ -30,7 +30,9 @@ import ( ) const ( - MongoDBSearchIndexFieldName = "mdbsearch-for-mongodbresourceref-index" + MongoDBSearchIndexFieldName = "mdbsearch-for-mongodbresourceref-index" + unsupportedSearchVersion = "1.47.0" + unsupportedSearchVersionErrorFmt = "MongoDBSearch version %s is not supported" ) type OperatorSearchConfig struct { @@ -268,15 +270,32 @@ func (r *MongoDBSearchReconcileHelper) ValidateSingleMongoDBSearchForSearchSourc for i, search := range searchList.Items { resourceNames[i] = search.Name } - return xerrors.Errorf("Found multiple MongoDBSearch resources for search source '%s': %s", r.db.Name(), strings.Join(resourceNames, ", ")) + return xerrors.Errorf( + "Found multiple MongoDBSearch resources for search source '%s': %s", r.db.Name(), + strings.Join(resourceNames, ", "), + ) } return nil } func (r *MongoDBSearchReconcileHelper) ValidateSearchImageVersion() error { - if r.mdbSearch.Spec.Version == "1.47.0" { - return xerrors.New("MongoDBSearch version 1.47.0 is not supported") + version := strings.TrimSpace(r.mdbSearch.Spec.Version) + if version != "" { + if version == unsupportedSearchVersion { + return xerrors.Errorf(unsupportedSearchVersionErrorFmt, unsupportedSearchVersion) + } + return nil + } + + if r.mdbSearch.Spec.StatefulSetConfiguration == nil { + return nil + } + + for _, container := range r.mdbSearch.Spec.StatefulSetConfiguration.SpecWrapper.Spec.Template.Spec.Containers { + if strings.Contains(container.Image, unsupportedSearchVersion) { + return xerrors.Errorf(unsupportedSearchVersionErrorFmt, unsupportedSearchVersion) + } } return nil