You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ho...@apache.org on 2023/01/24 18:05:48 UTC
[solr-operator] branch main updated: Fix SolrBackup not taking backups when the collections field is omitted (#516)
This is an automated email from the ASF dual-hosted git repository.
houston pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr-operator.git
The following commit(s) were added to refs/heads/main by this push:
new 852d2a8 Fix SolrBackup not taking backups when the collections field is omitted (#516)
852d2a8 is described below
commit 852d2a8780d6ae1f1fb68e52ead767a90f7a3a82
Author: Adam Nych <gm...@gmail.com>
AuthorDate: Tue Jan 24 19:05:42 2023 +0100
Fix SolrBackup not taking backups when the collections field is omitted (#516)
Backup all collections if user doesn't specify them
---
controllers/solrbackup_controller.go | 12 +++++++++++-
controllers/util/backup_util.go | 14 ++++++++++++++
controllers/util/solr_api/api.go | 7 +++++++
docs/solr-backup/README.md | 1 +
helm/solr-operator/Chart.yaml | 7 +++++++
5 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/controllers/solrbackup_controller.go b/controllers/solrbackup_controller.go
index dfffd52..e5c6981 100644
--- a/controllers/solrbackup_controller.go
+++ b/controllers/solrbackup_controller.go
@@ -223,8 +223,18 @@ func (r *SolrBackupReconciler) reconcileSolrCloudBackup(ctx context.Context, bac
currentBackupStatus.StartTime = metav1.Now()
}
+ collectionsToBackup := backup.Spec.Collections
+
+ // If there are no collections specified, we need to list through collections available in Solr
+ if len(collectionsToBackup) == 0 {
+ collectionsToBackup, err = util.ListAllSolrCollections(ctx, solrCloud, logger)
+ if err != nil {
+ logger.Error(err, "Error listing collections", "solrCloud", solrCloud.Name)
+ }
+ }
+
// Go through each collection specified and reconcile the backup.
- for _, collection := range backup.Spec.Collections {
+ for _, collection := range collectionsToBackup {
// This will in-place update the CollectionBackupStatus in the backup object
if _, err = reconcileSolrCollectionBackup(ctx, backup, currentBackupStatus, solrCloud, backupRepository, collection, logger); err != nil {
break
diff --git a/controllers/util/backup_util.go b/controllers/util/backup_util.go
index 7f5e55e..cedceab 100644
--- a/controllers/util/backup_util.go
+++ b/controllers/util/backup_util.go
@@ -210,3 +210,17 @@ func ScheduleNextBackup(restartSchedule string, lastBackupTime time.Time) (nextB
}
return
}
+
+func ListAllSolrCollections(ctx context.Context, cloud *solr.SolrCloud, logger logr.Logger) (collections []string, err error) {
+ logger.Info("Listing all Solr collections available", "solrCloud", cloud.Name)
+ resp := &solr_api.SolrCollectionsListing{}
+ queryParams := url.Values{}
+ queryParams.Add("action", "LIST")
+ err = solr_api.CallCollectionsApi(ctx, cloud, queryParams, resp)
+ if err == nil {
+ if hasError, apiErr := solr_api.CheckForCollectionsApiError("LIST", resp.ResponseHeader); hasError {
+ err = apiErr
+ }
+ }
+ return resp.Collections, err
+}
diff --git a/controllers/util/solr_api/api.go b/controllers/util/solr_api/api.go
index 4ab0a07..e64d863 100644
--- a/controllers/util/solr_api/api.go
+++ b/controllers/util/solr_api/api.go
@@ -87,6 +87,13 @@ type SolrDeleteRequestStatus struct {
Status string `json:"status,omitempty"`
}
+type SolrCollectionsListing struct {
+ ResponseHeader SolrResponseHeader `json:"responseHeader"`
+
+ // +optional
+ Collections []string `json:"collections,omitempty"`
+}
+
func CheckAsyncRequest(ctx context.Context, cloud *solr.SolrCloud, asyncId string) (asyncState string, message string, err error) {
asyncStatus := &SolrAsyncStatusResponse{}
diff --git a/docs/solr-backup/README.md b/docs/solr-backup/README.md
index aa1c944..1fba4e6 100644
--- a/docs/solr-backup/README.md
+++ b/docs/solr-backup/README.md
@@ -97,6 +97,7 @@ spec:
```
This will create a backup of both the 'techproducts' and 'books' collections, storing the data on the 'collection-backup-pvc' volume.
+If you don't specify the collections field, every available SolrCloud collection will be backed up.
The status of our triggered backup can be checked with the command below.
```bash
diff --git a/helm/solr-operator/Chart.yaml b/helm/solr-operator/Chart.yaml
index 8386a1a..c091e59 100644
--- a/helm/solr-operator/Chart.yaml
+++ b/helm/solr-operator/Chart.yaml
@@ -101,6 +101,13 @@ annotations:
url: https://github.com/apache/solr-operator/pull/514
- name: GitHub Issue
url: https://github.com/apache/solr-operator/issues/490
+ - kind: fixed
+ description: Fix SolrBackup not taking backups when the collections field is omitted
+ links:
+ - name: GitHub PR
+ url: https://github.com/apache/solr-operator/pull/516
+ - name: GitHub Issue
+ url: https://github.com/apache/solr-operator/issues/515
artifacthub.io/images: |
- name: solr-operator
image: apache/solr-operator:v0.7.0-prerelease