Skip to content

Commit

Permalink
Remove service from searchIndexesReconciler
Browse files Browse the repository at this point in the history
  • Loading branch information
josvazg committed Jan 12, 2025
1 parent 0c95fde commit bcda48b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 46 deletions.
24 changes: 11 additions & 13 deletions internal/controller/atlasdeployment/searchindexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,27 @@ func verifyAllIndexesNamesAreUnique(indexes []akov2.SearchIndex) bool {
}

type searchIndexesReconciler struct {
ctx *workflow.Context
deployment *akov2.AtlasDeployment
k8sClient client.Client
projectID string
searchService searchindex.AtlasSearchIdxService
ctx *workflow.Context
deployment *akov2.AtlasDeployment
k8sClient client.Client
projectID string
}

func handleSearchIndexes(ctx *workflow.Context, k8sClient client.Client, searchService searchindex.AtlasSearchIdxService, deployment *akov2.AtlasDeployment, projectID string) workflow.Result {
ctx.Log.Debug("starting indexes processing")
defer ctx.Log.Debug("finished indexes processing")

reconciler := &searchIndexesReconciler{
ctx: ctx,
k8sClient: k8sClient,
deployment: deployment,
projectID: projectID,
searchService: searchService,
ctx: ctx,
k8sClient: k8sClient,
deployment: deployment,
projectID: projectID,
}

return reconciler.Reconcile()
return reconciler.Reconcile(searchService)
}

func (sr *searchIndexesReconciler) Reconcile() workflow.Result {
func (sr *searchIndexesReconciler) Reconcile(searchService searchindex.AtlasSearchIdxService) workflow.Result {
if !verifyAllIndexesNamesAreUnique(sr.deployment.Spec.DeploymentSpec.SearchIndexes) {
return sr.terminate(api.SearchIndexesNamesAreNotUnique, fmt.Errorf("every index 'Name' must be unique"))
}
Expand Down Expand Up @@ -114,7 +112,7 @@ func (sr *searchIndexesReconciler) Reconcile() workflow.Result {
k8sClient: sr.k8sClient,
projectID: sr.projectID,
indexName: indexName,
}).Reconcile(val.spec, val.previous, sr.searchService))
}).Reconcile(val.spec, val.previous, searchService))
}

allDeleted := true
Expand Down
60 changes: 27 additions & 33 deletions internal/controller/atlasdeployment/searchindexes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func Test_SearchIndexesReconcile(t *testing.T) {
},
deployment: deployment,
}
result := reconciler.Reconcile()
result := reconciler.Reconcile(nil)
assert.True(t, reconciler.ctx.HasReason(api.SearchIndexesNamesAreNotUnique))
assert.False(t, result.IsOk())
})
Expand Down Expand Up @@ -211,13 +211,12 @@ func Test_SearchIndexesReconcile(t *testing.T) {
Client: nil,
Context: context.Background(),
},
deployment: deployment,
k8sClient: k8sClient,
projectID: "testProjectID",
searchService: fakeAtlasSearch,
deployment: deployment,
k8sClient: k8sClient,
projectID: "testProjectID",
}

result := reconciler.Reconcile()
result := reconciler.Reconcile(fakeAtlasSearch)
assert.True(t, result.IsOk())
deployment.UpdateStatus(reconciler.ctx.Conditions(), reconciler.ctx.StatusOptions()...)
assert.Len(t, deployment.Status.SearchIndexes, 1)
Expand Down Expand Up @@ -294,12 +293,11 @@ func Test_SearchIndexesReconcile(t *testing.T) {
Client: nil,
Context: context.Background(),
},
deployment: deployment,
k8sClient: k8sClient,
projectID: "testProjectID",
searchService: fakeAtlasSearch,
deployment: deployment,
k8sClient: k8sClient,
projectID: "testProjectID",
}
result := reconciler.Reconcile()
result := reconciler.Reconcile(fakeAtlasSearch)
assert.False(t, result.IsOk())
})

Expand Down Expand Up @@ -390,14 +388,13 @@ func Test_SearchIndexesReconcile(t *testing.T) {
Client: nil,
Context: context.Background(),
},
deployment: deployment,
k8sClient: k8sClient,
projectID: "testProjectID",
searchService: fakeAtlasSearch,
deployment: deployment,
k8sClient: k8sClient,
projectID: "testProjectID",
}

// first reconcile succeeds, creation succeeds
result := reconciler.Reconcile()
result := reconciler.Reconcile(fakeAtlasSearch)
deployment.UpdateStatus(reconciler.ctx.Conditions(), reconciler.ctx.StatusOptions()...)
assert.False(t, result.IsOk())
assert.Equal(t, []status.DeploymentSearchIndexStatus{
Expand All @@ -422,7 +419,7 @@ func Test_SearchIndexesReconcile(t *testing.T) {
})

// create fails
result = reconciler.Reconcile()
result = reconciler.Reconcile(fakeAtlasSearch)
deployment.UpdateStatus(reconciler.ctx.Conditions(), reconciler.ctx.StatusOptions()...)
assert.False(t, result.IsOk())
assert.Equal(t, []status.DeploymentSearchIndexStatus{
Expand All @@ -444,7 +441,7 @@ func Test_SearchIndexesReconcile(t *testing.T) {
deployment.Spec.DeploymentSpec.SearchIndexes = []akov2.SearchIndex{deployment.Spec.DeploymentSpec.SearchIndexes[0]}

// third reconcile succeeds, creation succeeds
result = reconciler.Reconcile()
result = reconciler.Reconcile(fakeAtlasSearch)
deployment.UpdateStatus(reconciler.ctx.Conditions(), reconciler.ctx.StatusOptions()...)
assert.True(t, result.IsOk())
assert.Equal(t, []status.DeploymentSearchIndexStatus{
Expand Down Expand Up @@ -545,12 +542,11 @@ func Test_SearchIndexesReconcile(t *testing.T) {
Client: nil,
Context: context.Background(),
},
deployment: cluster,
k8sClient: k8sClient,
projectID: "testProjectID",
searchService: fakeAtlasSearch,
deployment: cluster,
k8sClient: k8sClient,
projectID: "testProjectID",
}
result := reconciler.Reconcile()
result := reconciler.Reconcile(fakeAtlasSearch)
fmt.Println("Result", result)
assert.True(t, reconciler.ctx.HasReason(api.SearchIndexesNotReady))
assert.True(t, result.IsInProgress())
Expand Down Expand Up @@ -644,12 +640,11 @@ func Test_SearchIndexesReconcile(t *testing.T) {
Client: nil,
Context: context.Background(),
},
deployment: cluster,
k8sClient: k8sClient,
projectID: "testProjectID",
searchService: fakeAtlasSearch,
deployment: cluster,
k8sClient: k8sClient,
projectID: "testProjectID",
}
result := reconciler.Reconcile()
result := reconciler.Reconcile(fakeAtlasSearch)
fmt.Println("Result", result)
assert.True(t, reconciler.ctx.HasReason(api.SearchIndexesNotReady))
assert.True(t, result.IsInProgress())
Expand Down Expand Up @@ -748,12 +743,11 @@ func Test_SearchIndexesReconcile(t *testing.T) {
Client: nil,
Context: context.Background(),
},
deployment: cluster,
k8sClient: k8sClient,
projectID: "testProjectID",
searchService: fakeAtlasSearch,
deployment: cluster,
k8sClient: k8sClient,
projectID: "testProjectID",
}
result := reconciler.Reconcile()
result := reconciler.Reconcile(fakeAtlasSearch)
cluster.UpdateStatus(reconciler.ctx.Conditions(), reconciler.ctx.StatusOptions()...)
assert.Empty(t, cluster.Status.SearchIndexes)
assert.True(t, result.IsOk())
Expand Down

0 comments on commit bcda48b

Please sign in to comment.