Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a testcase for the statefulset codepath? I'd do it by doing the reconcile and then updating search.Spec.Version to "" (not sure if that will work)

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"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make this error message more informative for the user? Let's mention why it's not supported, how the operator is treating it (ignoring it essentially), and perhaps that the existing workload will still work but cannot be reconfigured by the operator and they need to start from scratch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This sounds like something that needs to be in the docs.
Would a doc link be more helpful?

)

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 != "" {
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
Expand Down