Skip to content

Commit dbc8db9

Browse files
committed
Fix a few issues with testing, add better cluster information
1 parent e5c1271 commit dbc8db9

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed

controllers/solr_cluster_ops_util.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func clearClusterOpLock(statefulSet *appsv1.StatefulSet) {
6666
}
6767

6868
func setClusterOpLock(statefulSet *appsv1.StatefulSet, op SolrClusterOp) error {
69+
op.LastStartTime = metav1.Now()
6970
bytes, err := json.Marshal(op)
7071
if err != nil {
7172
return err
@@ -124,7 +125,6 @@ func retryNextQueuedClusterOp(statefulSet *appsv1.StatefulSet) (hasOp bool, err
124125
hasOp = len(clusterOpRetryQueue) > 0
125126
if len(clusterOpRetryQueue) > 0 {
126127
nextOp := clusterOpRetryQueue[0]
127-
nextOp.LastStartTime = metav1.Now()
128128
err = setClusterOpLock(statefulSet, nextOp)
129129
if err != nil {
130130
return hasOp, err
@@ -141,7 +141,6 @@ func retryNextQueuedClusterOpWithQueue(statefulSet *appsv1.StatefulSet, clusterO
141141
hasOp = len(clusterOpQueue) > 0
142142
if len(clusterOpQueue) > 0 {
143143
nextOp := clusterOpQueue[0]
144-
nextOp.LastStartTime = metav1.Now()
145144
err = setClusterOpLock(statefulSet, nextOp)
146145
if err != nil {
147146
return hasOp, err

controllers/solrcloud_controller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,6 @@ func (r *SolrCloudReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
574574
if clusterOp != nil {
575575
// Starting a locked cluster operation!
576576
originalStatefulSet := statefulSet.DeepCopy()
577-
clusterOp.LastStartTime = metav1.Now()
578577
err = setClusterOpLock(statefulSet, *clusterOp)
579578
if err == nil {
580579
err = r.Patch(ctx, statefulSet, client.StrategicMergeFrom(originalStatefulSet))

tests/e2e/solrcloud_rolling_upgrade_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ var _ = FDescribe("E2E - SolrCloud - Rolling Upgrades", func() {
163163
}
164164

165165
By("waiting for the balanceReplicas to finish")
166-
expectStatefulSetWithChecksAndTimeout(ctx, solrCloud, solrCloud.StatefulSetName(), time.Second*30, time.Second, func(g Gomega, found *appsv1.StatefulSet) {
166+
expectStatefulSetWithChecksAndTimeout(ctx, solrCloud, solrCloud.StatefulSetName(), time.Second*70, time.Second, func(g Gomega, found *appsv1.StatefulSet) {
167167
clusterOp, err := controllers.GetCurrentClusterOp(found)
168168
g.Expect(err).ToNot(HaveOccurred(), "Error occurred while finding clusterLock for SolrCloud")
169169
g.Expect(clusterOp).To(BeNil(), "StatefulSet should not have a balanceReplicas lock after balancing is complete.")

tests/e2e/suite_test.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,23 @@ func writeAllSolrInfoToFiles(ctx context.Context, directory string, namespace st
285285
req, err := labels.NewRequirement("technology", selection.In, []string{solrv1beta1.SolrTechnologyLabel, solrv1beta1.SolrPrometheusExporterTechnologyLabel})
286286
Expect(err).ToNot(HaveOccurred())
287287

288-
labelSelector := labels.Everything().Add(*req)
289288
listOps := &client.ListOptions{
289+
Namespace: namespace,
290+
}
291+
292+
foundSolrs := &solrv1beta1.SolrCloudList{}
293+
Expect(k8sClient.List(ctx, foundSolrs, listOps)).To(Succeed(), "Could not fetch SolrClouds")
294+
Expect(foundSolrs).ToNot(BeNil(), "No SolrClouds could be found")
295+
for _, solrCloud := range foundSolrs.Items {
296+
writeSolrClusterStatusInfoToFile(
297+
ctx,
298+
directory+solrCloud.Name,
299+
&solrCloud,
300+
)
301+
}
302+
303+
labelSelector := labels.Everything().Add(*req)
304+
listOps = &client.ListOptions{
290305
Namespace: namespace,
291306
LabelSelector: labelSelector,
292307
}
@@ -333,6 +348,20 @@ func writeAllSolrInfoToFiles(ctx context.Context, directory string, namespace st
333348
}
334349
}
335350

351+
// writeSolrClusterStatusInfoToFile writes the following each to a separate file with the given base name & directory.
352+
// - SolrCloud's Cluster Status from the Collections API
353+
func writeSolrClusterStatusInfoToFile(ctx context.Context, baseFilename string, solrCloud *solrv1beta1.SolrCloud) {
354+
clusterStatus := fetchClusterStatusWithErrorHandling(ctx, solrCloud, false)
355+
if clusterStatus != "" {
356+
// Write cluster status to a file
357+
statusFile, err := os.Create(baseFilename + ".cluster-state.json")
358+
defer statusFile.Close()
359+
Expect(err).ToNot(HaveOccurred(), "Could not open file to save cluster status: %s", baseFilename+".cluster-state.json")
360+
_, writeErr := statusFile.Write([]byte(clusterStatus))
361+
Expect(writeErr).ToNot(HaveOccurred(), "Could not write cluster status json to file")
362+
}
363+
}
364+
336365
// writeAllStatefulSetInfoToFiles writes the following each to a separate file with the given base name & directory.
337366
// - StatefulSet Spec/Status
338367
// - StatefulSet Events

tests/e2e/test_utils_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ func queryCollectionWithGomega(ctx context.Context, solrCloud *solrv1beta1.SolrC
313313
}
314314

315315
func fetchClusterStatus(ctx context.Context, solrCloud *solrv1beta1.SolrCloud) string {
316+
return fetchClusterStatusWithErrorHandling(ctx, solrCloud, true)
317+
}
318+
319+
func fetchClusterStatusWithErrorHandling(ctx context.Context, solrCloud *solrv1beta1.SolrCloud, expectNoError bool) string {
316320
response, err := callSolrApiInPod(
317321
ctx,
318322
solrCloud,
@@ -323,7 +327,9 @@ func fetchClusterStatus(ctx context.Context, solrCloud *solrv1beta1.SolrCloud) s
323327
"wt": "json",
324328
},
325329
)
326-
Expect(err).ToNot(HaveOccurred(), "Could not fetch clusterStatus for cloud")
330+
if expectNoError {
331+
Expect(err).ToNot(HaveOccurred(), "Could not fetch clusterStatus for cloud")
332+
}
327333

328334
return response
329335
}

0 commit comments

Comments
 (0)