Skip to content

CLOUDP-321075: fail to reconcile mongo db search for version 1.47.0 #244

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
wants to merge 3 commits into
base: search/public-preview
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions controllers/operator/mongodbsearch_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
35 changes: 33 additions & 2 deletions controllers/search_controller/mongodbsearch_reconcile_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -76,6 +78,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)
}
Expand Down Expand Up @@ -264,7 +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 {
version := strings.TrimSpace(r.mdbSearch.Spec.Version)
if version != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the version field in the spec is empty, you should check r.operatorSearchConfig.SearchVersion (see the createOrUpdateStatefulSet() method on MongoDBSearchReconcileHelper and perhaps extract a helper to calculate the 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could trigger on any sidecar containers users add. Perhaps the if check should also test whether the container name equals the MongotContainerName constant in search_construction.go?

return xerrors.Errorf(unsupportedSearchVersionErrorFmt, unsupportedSearchVersion)
}
}

return nil
Expand Down