Skip to content

CLOUDP-240596: fix search index create watcher for Atlas deployments #2821

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

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
30 changes: 25 additions & 5 deletions internal/cli/deployments/search/indexes/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,25 @@ func (opts *CreateOpts) status(ctx context.Context) (string, error) {
return status, nil
}

func (opts *CreateOpts) watch(ctx context.Context) (any, bool, error) {
func (opts *CreateOpts) watchLocal(ctx context.Context) (any, bool, error) {
state, err := opts.status(ctx)
if err != nil {
return nil, false, err
}
if state == "READY" {
return nil, true, nil
opts.index.Status = &state
return opts.index, true, nil
}
return nil, false, nil
}

func (opts *CreateOpts) watchAtlas(_ context.Context) (any, bool, error) {
index, err := opts.store.SearchIndex(opts.ConfigProjectID(), opts.DeploymentName, *opts.index.IndexID)
if err != nil {
return nil, false, err
}
if index.GetStatus() == "STEADY" {
return index, true, nil
}
return nil, false, nil
}
Expand All @@ -177,11 +189,19 @@ func (opts *CreateOpts) PostRun(ctx context.Context) error {
return opts.Print(opts.index)
}

if _, err := opts.Watch(func() (any, bool, error) {
return opts.watch(ctx)
}); err != nil {
watch := opts.watchLocal
if opts.IsAtlasDeploymentType() {
watch = opts.watchAtlas
}

watchResult, err := opts.Watch(func() (any, bool, error) {
return watch(ctx)
})

if err != nil {
return err
}
opts.index = watchResult.(*admin.ClusterSearchIndex)

if err := opts.Print(opts.index); err != nil {
return err
Expand Down
15 changes: 15 additions & 0 deletions internal/mocks/mock_search.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/store/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type SearchIndexLister interface {

type SearchIndexCreator interface {
CreateSearchIndexes(string, string, *atlasv2.ClusterSearchIndex) (*atlasv2.ClusterSearchIndex, error)
SearchIndex(string, string, string) (*atlasv2.ClusterSearchIndex, error)
}

type SearchIndexDescriber interface {
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/atlas/deployments_atlas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func TestDeploymentsAtlas(t *testing.T) {
})
require.NoError(t, watchCluster(g.projectID, clusterName))

t.Run("Create Index", func(t *testing.T) {
t.Run("Create Search Index", func(t *testing.T) {
cmd := exec.Command(cliPath,
deploymentEntity,
searchEntity,
Expand All @@ -159,6 +159,7 @@ func TestDeploymentsAtlas(t *testing.T) {
databaseNameAtlas,
"--collection",
collectionNameAtlas,
"--watch",
)
cmd.Env = os.Environ()

Expand Down