From 78d6ae737a9e04c00820d2b9586d783365f6d545 Mon Sep 17 00:00:00 2001 From: pritamdas99 Date: Thu, 4 Jul 2024 11:58:56 +0600 Subject: [PATCH 01/13] Add solr client. Signed-off-by: pritamdas99 --- go.mod | 1 + kafka/client.go | 3 +- kafka/connect/kubedb_client_builder.go | 3 +- mssqlserver/kubedb_client_builder.go | 1 + pgpool/kubedb_client_builder.go | 1 + rabbitmq/kubedb_client_builder.go | 1 + singlestore/kubedb_client_builder.go | 1 + solr/api.go | 25 ++ solr/client.go | 76 ++++++ solr/kubedb_client_builder.go | 137 ++++++++++ solr/solrv8.go | 330 +++++++++++++++++++++++++ solr/solrv9.go | 305 +++++++++++++++++++++++ solr/util.go | 127 ++++++++++ 13 files changed, 1009 insertions(+), 2 deletions(-) create mode 100644 solr/api.go create mode 100644 solr/client.go create mode 100644 solr/kubedb_client_builder.go create mode 100644 solr/solrv8.go create mode 100644 solr/solrv9.go create mode 100644 solr/util.go diff --git a/go.mod b/go.mod index 69ea7295e..fc96c9073 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/elastic/go-elasticsearch/v6 v6.8.10 github.com/elastic/go-elasticsearch/v7 v7.15.1 github.com/elastic/go-elasticsearch/v8 v8.4.0 + github.com/go-logr/logr v1.4.1 github.com/go-resty/resty/v2 v2.11.0 github.com/go-sql-driver/mysql v1.8.1 github.com/lib/pq v1.10.7 diff --git a/kafka/client.go b/kafka/client.go index 216f20cdb..c7630b7d9 100644 --- a/kafka/client.go +++ b/kafka/client.go @@ -17,9 +17,10 @@ limitations under the License. package kafka import ( - "fmt" "time" + "fmt" + kafkago "github.com/IBM/sarama" "k8s.io/klog/v2" ) diff --git a/kafka/connect/kubedb_client_builder.go b/kafka/connect/kubedb_client_builder.go index be8b7a268..59e3d08d4 100644 --- a/kafka/connect/kubedb_client_builder.go +++ b/kafka/connect/kubedb_client_builder.go @@ -21,11 +21,12 @@ import ( "crypto/tls" "crypto/x509" "errors" - "fmt" "net" "net/http" "time" + "fmt" + "github.com/go-resty/resty/v2" core "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" diff --git a/mssqlserver/kubedb_client_builder.go b/mssqlserver/kubedb_client_builder.go index b1bed02c5..d26e81385 100644 --- a/mssqlserver/kubedb_client_builder.go +++ b/mssqlserver/kubedb_client_builder.go @@ -18,6 +18,7 @@ package mssql import ( "context" + "fmt" _ "github.com/microsoft/go-mssqldb" diff --git a/pgpool/kubedb_client_builder.go b/pgpool/kubedb_client_builder.go index f0cd15d37..4867cba44 100644 --- a/pgpool/kubedb_client_builder.go +++ b/pgpool/kubedb_client_builder.go @@ -18,6 +18,7 @@ package pgpool import ( "context" + "fmt" olddbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2" diff --git a/rabbitmq/kubedb_client_builder.go b/rabbitmq/kubedb_client_builder.go index c54157b88..a71863066 100644 --- a/rabbitmq/kubedb_client_builder.go +++ b/rabbitmq/kubedb_client_builder.go @@ -19,6 +19,7 @@ package rabbitmq import ( "context" "errors" + "fmt" "strings" diff --git a/singlestore/kubedb_client_builder.go b/singlestore/kubedb_client_builder.go index 289935d68..58aac421d 100644 --- a/singlestore/kubedb_client_builder.go +++ b/singlestore/kubedb_client_builder.go @@ -21,6 +21,7 @@ import ( "crypto/tls" "crypto/x509" "database/sql" + "fmt" sql_driver "github.com/go-sql-driver/mysql" diff --git a/solr/api.go b/solr/api.go new file mode 100644 index 000000000..686ca8e2a --- /dev/null +++ b/solr/api.go @@ -0,0 +1,25 @@ +package solr + +import ( + "context" + "github.com/go-logr/logr" + "github.com/go-resty/resty/v2" +) + +type SLClient interface { + GetClusterStatus() (*Response, error) + ListCollection() (*Response, error) + CreateCollection() (*Response, error) + WriteCollection() (*Response, error) + ReadCollection() (*Response, error) + BackupCollection(ctx context.Context, collection string, backupName string, location string, repository string) (*Response, error) + RestoreCollection(ctx context.Context, collection string, backupName string, location string, repository string, backupId int) (*Response, error) + FlushStatus(asyncId string) (*Response, error) + RequestStatus(asyncId string) (*Response, error) + DeleteBackup(ctx context.Context, backupName string, collection string, location string, repository string, backupId int, snap string) (*Response, error) + PurgeBackup(ctx context.Context, backupName string, collection string, location string, repository string, snap string) (*Response, error) + GetConfig() *Config + GetClient() *resty.Client + GetLog() logr.Logger + DecodeBackupResponse(data map[string]interface{}, collection string) ([]byte, error) +} diff --git a/solr/client.go b/solr/client.go new file mode 100644 index 000000000..c6939432a --- /dev/null +++ b/solr/client.go @@ -0,0 +1,76 @@ +package solr + +import ( + "context" + "io" + "net/http" + + "github.com/go-logr/logr" + api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +type Client struct { + SLClient +} + +type ClientOptions struct { + KBClient client.Client + DB *api.Solr + Ctx context.Context + Log logr.Logger +} + +type Config struct { + host string + connectionScheme string + transport *http.Transport + log logr.Logger +} + +type Response struct { + Code int + header http.Header + body io.ReadCloser +} + +type Doc struct { + Id int `json:"id,omitempty" yaml:"id,omitempty"` + DB string `json:"db,omitempty" yaml:"db,omitempty"` +} + +type Data struct { + CommitWithin int `json:"commitWithin,omitempty" yaml:"commitWithin,omitempty"` + Overwrite bool `json:"overwrite,omitempty" yaml:"overwrite,omitempty"` + Doc *Doc `json:"doc,omitempty" yaml:"doc,omitempty"` +} + +type ADD struct { + Add *Data `json:"add,omitempty" yaml:"add,omitempty"` +} + +type QueryParams struct { + Query string `json:"query,omitempty" yaml:"query,omitempty"` + Limit int `json:"limit,omitempty" yaml:"limit,omitempty"` +} + +type BackupParams struct { + Location string `json:"location,omitempty" yaml:"location,omitempty"` + Repository string `json:"repository,omitempty" yaml:"repository,omitempty"` + Async string `json:"async,omitempty" yaml:"async,omitempty"` +} + +type BackupRestoreParams struct { + Location string `json:"location,omitempty" yaml:"location,omitempty"` + Repository string `json:"repository,omitempty" yaml:"repository,omitempty"` + Collection string `json:"collection,omitempty" yaml:"collection,omitempty"` + Async string `json:"async,omitempty" yaml:"async,omitempty"` + BackupId int `json:"backupId,omitempty" yaml:"backupId,omitempty"` +} + +type CreateParams struct { + Name string `json:"name,omitempty" yaml:"name,omitempty"` + Config string `json:"config,omitempty" yaml:"config,omitempty"` + NumShards int `json:"numShards,omitempty" yaml:"numShards,omitempty"` + ReplicationFactor int `json:"replicationFactor,omitempty" yaml:"replicationFactor,omitempty"` +} diff --git a/solr/kubedb_client_builder.go b/solr/kubedb_client_builder.go new file mode 100644 index 000000000..e08b95aeb --- /dev/null +++ b/solr/kubedb_client_builder.go @@ -0,0 +1,137 @@ +package solr + +import ( + "context" + "errors" + "github.com/Masterminds/semver/v3" + gerr "github.com/pkg/errors" + core "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/types" + "net" + "net/http" + "time" + + "fmt" + + "github.com/go-logr/logr" + "github.com/go-resty/resty/v2" + api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +type KubeDBClientBuilder struct { + kc client.Client + db *api.Solr + url string + podName string + ctx context.Context + log logr.Logger +} + +func NewKubeDBClientBuilder(kc client.Client, db *api.Solr) *KubeDBClientBuilder { + return &KubeDBClientBuilder{ + kc: kc, + db: db, + } +} + +func (o *KubeDBClientBuilder) WithPod(podName string) *KubeDBClientBuilder { + o.podName = podName + return o +} + +func (o *KubeDBClientBuilder) WithURL(url string) *KubeDBClientBuilder { + o.url = url + return o +} + +func (o *KubeDBClientBuilder) WithLog(log logr.Logger) *KubeDBClientBuilder { + o.log = log + return o +} + +func (o *KubeDBClientBuilder) WithContext(ctx context.Context) *KubeDBClientBuilder { + o.ctx = ctx + return o +} + +func (o *KubeDBClientBuilder) GetSolrClient() (*Client, error) { + if o.podName != "" { + o.url = o.GetHostPath(o.db) + } + if o.url == "" { + o.url = o.GetHostPath(o.db) + } + if o.db == nil { + return nil, errors.New("db is empty") + } + config := Config{ + host: o.url, + transport: &http.Transport{ + IdleConnTimeout: time.Minute * 6, + DialContext: (&net.Dialer{ + Timeout: time.Minute * 6, + KeepAlive: time.Minute * 6, + }).DialContext, + TLSHandshakeTimeout: time.Minute * 6, + ResponseHeaderTimeout: time.Minute * 6, + ExpectContinueTimeout: time.Minute * 6, + }, + connectionScheme: o.db.GetConnectionScheme(), + log: o.log, + } + + var authSecret core.Secret + if !o.db.Spec.DisableSecurity { + err := o.kc.Get(o.ctx, types.NamespacedName{ + Name: o.db.Spec.AuthSecret.Name, + Namespace: o.db.Namespace, + }, &authSecret) + if err != nil { + config.log.Error(err, "failed to get auth secret to get solr client") + return nil, err + } + } + version, err := semver.NewVersion(o.db.Spec.Version) + if err != nil { + return nil, gerr.Wrap(err, "failed to parse version") + } + + switch { + case version.Major() == 9: + newClient := resty.New() + newClient.SetScheme(config.connectionScheme).SetBaseURL(config.host).SetTransport(config.transport) + newClient.SetTimeout(6 * time.Minute) + newClient.SetHeader("Accept", "application/json") + newClient.SetDisableWarn(true) + newClient.SetBasicAuth(string(authSecret.Data[core.BasicAuthUsernameKey]), string(authSecret.Data[core.BasicAuthPasswordKey])) + return &Client{ + &SLClientV9{ + Client: newClient, + log: config.log, + Config: &config, + }, + }, nil + case version.Major() == 8: + newClient := resty.New() + newClient.SetScheme(config.connectionScheme).SetBaseURL(config.host).SetTransport(config.transport) + newClient.SetTimeout(6 * time.Minute) + newClient.SetHeader("Accept", "application/json") + newClient.SetDisableWarn(true) + newClient.SetBasicAuth(string(authSecret.Data[core.BasicAuthUsernameKey]), string(authSecret.Data[core.BasicAuthPasswordKey])) + return &Client{ + &SLClientV8{ + Client: newClient, + log: config.log, + Config: &config, + }, + }, nil + } + + return nil, fmt.Errorf("unknown version: %s", o.db.Spec.Version) + +} + +func (o *KubeDBClientBuilder) GetHostPath(db *api.Solr) string { + return fmt.Sprintf("%v://%s.%s.svc.cluster.local:%d", db.GetConnectionScheme(), db.ServiceName(), db.GetNamespace(), api.SolrRestPort) +} diff --git a/solr/solrv8.go b/solr/solrv8.go new file mode 100644 index 000000000..082f09c04 --- /dev/null +++ b/solr/solrv8.go @@ -0,0 +1,330 @@ +package solr + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "github.com/go-logr/logr" + "github.com/go-resty/resty/v2" + "k8s.io/klog/v2" + "strconv" +) + +type SLClientV8 struct { + Client *resty.Client + log logr.Logger + Config *Config +} + +func (sc *SLClientV8) GetClusterStatus() (*Response, error) { + sc.Config.log.V(5).Info("GETTING CLUSTER STATUS") + req := sc.Client.R().SetDoNotParseResponse(true) + req.SetQueryParam("action", "CLUSTERSTATUS") + res, err := req.Get("/solr/admin/collections") + if err != nil { + sc.log.Error(err, "Failed to send http request") + return nil, err + } + + clusterResponse := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return clusterResponse, nil +} + +func (sc *SLClientV8) ListCollection() (*Response, error) { + sc.Config.log.V(5).Info("SEARCHING COLLECTION: kubedb-system") + req := sc.Client.R().SetDoNotParseResponse(true) + req.SetQueryParam("action", "LIST") + res, err := req.Get("/solr/admin/collections") + if err != nil { + sc.log.Error(err, "Failed to send http request while getting colection list") + return nil, err + } + response := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return response, nil +} + +func (sc *SLClientV8) CreateCollection() (*Response, error) { + sc.Config.log.V(5).Info("CREATING COLLECTION: kubedb-system") + req := sc.Client.R().SetDoNotParseResponse(true) + req.SetHeader("Content-Type", "application/json") + params := map[string]string{ + "action": "CREATE", + "name": "kubedb-system", + "numShards": "1", + "replicationFactor": "1", + } + + req.SetQueryParams(params) + res, err := req.Post("/solr/admin/collections") + if err != nil { + sc.log.Error(err, "Failed to send http request to create a collection") + return nil, err + } + + collectionResponse := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return collectionResponse, nil +} + +func (sc *SLClientV8) WriteCollection() (*Response, error) { + sc.Config.log.V(5).Info("WRITING COLLECTION: kubedb-system") + req := sc.Client.R().SetDoNotParseResponse(true) + req.SetHeader("Content-Type", "application/json") + data1 := &Data{ + CommitWithin: 5000, + Overwrite: true, + Doc: &Doc{ + Id: 1, + DB: "elasticsearch", + }, + } + add := ADD{ + Add: data1, + } + req.SetBody(add) + res, err := req.Post("/solr/kubedb-system/update") + if err != nil { + sc.log.Error(err, "Failed to send http request to add document in collect") + return nil, err + } + + writeResponse := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return writeResponse, nil +} + +func (sc *SLClientV8) ReadCollection() (*Response, error) { + sc.Config.log.V(5).Info("READING COLLECTION: kubedb-system") + req := sc.Client.R().SetDoNotParseResponse(true) + req.SetQueryParam("q", "*:*") + res, err := req.Get("/solr/kubedb-system/select") + if err != nil { + sc.log.Error(err, "Failed to send http request to read a collection") + return nil, err + } + + writeResponse := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return writeResponse, nil +} + +func (sc *SLClientV8) BackupCollection(ctx context.Context, collection string, backupName string, location string, repository string) (*Response, error) { + sc.Config.log.V(5).Info(fmt.Sprintf("BACKUP COLLECTION: %s", collection)) + req := sc.Client.R().SetDoNotParseResponse(true).SetContext(ctx) + req.SetHeader("Content-Type", "application/json") + params := map[string]string{ + "action": "BACKUP", + "name": backupName, + "collection": collection, + "location": location, + "repository": repository, + "async": fmt.Sprintf("%s-backup", collection), + } + + req.SetQueryParams(params) + + res, err := req.Post("/solr/admin/collections") + if err != nil { + sc.log.Error(err, "Failed to send http request to backup a collection") + return nil, err + } + + backupResponse := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return backupResponse, nil +} + +func (sc *SLClientV8) RestoreCollection(ctx context.Context, collection string, backupName string, location string, repository string, backupId int) (*Response, error) { + sc.Config.log.V(5).Info(fmt.Sprintf("RESTORE COLLECTION: %s", collection)) + req := sc.Client.R().SetDoNotParseResponse(true).SetContext(ctx) + req.SetHeader("Content-Type", "application/json") + params := map[string]string{ + "action": "RESTORE", + "name": backupName, + "collection": collection, + "location": location, + "repository": repository, + "backupId": strconv.Itoa(backupId), + "async": fmt.Sprintf("%s-restore", collection), + } + + req.SetQueryParams(params) + + res, err := req.Post("/solr/admin/collections") + if err != nil { + sc.log.Error(err, "Failed to send http request to restore a collection") + return nil, err + } + + backupResponse := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return backupResponse, nil +} + +func (sc *SLClientV8) FlushStatus(asyncId string) (*Response, error) { + sc.Config.log.V(5).Info("Flush Status") + req := sc.Client.R().SetDoNotParseResponse(true) + req.SetHeader("Content-Type", "application/json") + + params := map[string]string{ + "action": "DELETESTATUS", + "requestid": asyncId, + } + req.SetQueryParams(params) + res, err := req.Get("/solr/admin/collections") + if err != nil { + sc.log.Error(err, "Failed to send http request to flush status") + return nil, err + } + + backupResponse := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return backupResponse, nil +} + +func (sc *SLClientV8) RequestStatus(asyncId string) (*Response, error) { + sc.Config.log.V(5).Info("Request Status") + req := sc.Client.R().SetDoNotParseResponse(true) + req.SetHeader("Content-Type", "application/json") + params := map[string]string{ + "action": "REQUESTSTATUS", + "requestid": asyncId, + } + req.SetQueryParams(params) + res, err := req.Get("/solr/admin/collections") + if err != nil { + sc.log.Error(err, "Failed to send http request to request status") + return nil, err + } + backupResponse := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return backupResponse, nil +} + +func (sc *SLClientV8) DeleteBackup(ctx context.Context, backupName string, collection string, location string, repository string, backupId int, snap string) (*Response, error) { + sc.Config.log.V(5).Info(fmt.Sprintf("DELETE BACKUP ID %d of BACKUP %s", backupId, backupName)) + req := sc.Client.R().SetDoNotParseResponse(true).SetContext(ctx) + req.SetHeader("Content-Type", "application/json") + async := fmt.Sprintf("%s-delete", collection) + if snap != "" { + async = fmt.Sprintf("%s-%s", async, snap) + } + params := map[string]string{ + "action": "DELETEBACKUP", + "name": backupName, + "location": location, + "repository": repository, + "backupId": strconv.Itoa(backupId), + "purgeUnused": "true", + "async": async, + } + req.SetQueryParams(params) + + res, err := req.Delete("/solr/admin/collections") + if err != nil { + sc.log.Error(err, "Failed to send http request to restore a collection") + return nil, err + } + + backupResponse := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return backupResponse, nil +} + +func (sc *SLClientV8) PurgeBackup(ctx context.Context, backupName string, collection string, location string, repository string, snap string) (*Response, error) { + sc.Config.log.V(5).Info(fmt.Sprintf("PURGE BACKUP ID %s", backupName)) + req := sc.Client.R().SetDoNotParseResponse(true).SetContext(ctx) + req.SetHeader("Content-Type", "application/json") + async := fmt.Sprintf("%s-purge", collection) + if snap != "" { + async = fmt.Sprintf("%s-%s", async, snap) + } + params := map[string]string{ + "action": "DELETEBACKUP", + "name": backupName, + "location": location, + "repository": repository, + "purgeUnused": "true", + "async": async, + } + req.SetQueryParams(params) + res, err := req.Put("/solr/admin/collections") + if err != nil { + sc.log.Error(err, "Failed to send http request to restore a collection") + return nil, err + } + + backupResponse := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return backupResponse, nil +} + +func (sc *SLClientV8) GetConfig() *Config { + return sc.Config +} + +func (sc *SLClientV8) GetClient() *resty.Client { + return sc.Client +} + +func (sc *SLClientV8) GetLog() logr.Logger { + return sc.log +} + +func (sc *SLClientV8) DecodeBackupResponse(data map[string]interface{}, collection string) ([]byte, error) { + sc.Config.log.V(5).Info("Decode Backup Data") + backupResponse, ok := data["response"].([]interface{}) + if !ok { + err := errors.New(fmt.Sprintf("didn't find status for collection %s\n", collection)) + return nil, err + } + mp := make(map[string]interface{}) + for i := 0; i < len(backupResponse); i += 2 { + a := backupResponse[i].(string) + b := backupResponse[i+1] + mp[a] = b + } + b, err := json.Marshal(mp) + if err != nil { + klog.Error(fmt.Sprintf("Could not format response for collection %s into json", collection)) + return nil, err + } + return b, nil + +} diff --git a/solr/solrv9.go b/solr/solrv9.go new file mode 100644 index 000000000..3cbdcb75d --- /dev/null +++ b/solr/solrv9.go @@ -0,0 +1,305 @@ +package solr + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "github.com/go-logr/logr" + "github.com/go-resty/resty/v2" + "k8s.io/klog/v2" +) + +type SLClientV9 struct { + Client *resty.Client + log logr.Logger + Config *Config +} + +func (sc *SLClientV9) GetClusterStatus() (*Response, error) { + sc.Config.log.V(5).Info("GETTING CLUSTER STATUS") + req := sc.Client.R().SetDoNotParseResponse(true) + res, err := req.Get("/api/cluster") + if err != nil { + sc.log.Error(err, "Failed to send http request") + return nil, err + } + + clusterResponse := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return clusterResponse, nil +} + +func (sc *SLClientV9) ListCollection() (*Response, error) { + sc.Config.log.V(5).Info("SEARCHING COLLECTION: kubedb-system") + req := sc.Client.R().SetDoNotParseResponse(true) + res, err := req.Get("/api/collections") + if err != nil { + sc.log.Error(err, "Failed to send http request while getting colection list") + return nil, err + } + response := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return response, nil +} + +func (sc *SLClientV9) CreateCollection() (*Response, error) { + sc.Config.log.V(5).Info("CREATING COLLECTION: kubedb-system") + req := sc.Client.R().SetDoNotParseResponse(true) + req.SetHeader("Content-Type", "application/json") + createParams := &CreateParams{ + Name: "kubedb-system", + NumShards: 1, + ReplicationFactor: 1, + } + + req.SetBody(createParams) + res, err := req.Post("/api/collections") + if err != nil { + sc.log.Error(err, "Failed to send http request to create a collection") + return nil, err + } + + collectionResponse := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return collectionResponse, nil +} + +type ADDList []ADD + +func (sc *SLClientV9) WriteCollection() (*Response, error) { + sc.Config.log.V(5).Info("WRITING COLLECTION: kubedb-system") + req := sc.Client.R().SetDoNotParseResponse(true) + req.SetHeader("Content-Type", "application/json") + data1 := &Data{ + CommitWithin: 5000, + Overwrite: true, + Doc: &Doc{ + Id: 1, + DB: "elasticsearch", + }, + } + add := ADD{ + Add: data1, + } + req.SetBody(add) + res, err := req.Post("/solr/kubedb-system/update") + if err != nil { + sc.log.Error(err, "Failed to send http request to add document in collect") + return nil, err + } + + writeResponse := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return writeResponse, nil +} + +func (sc *SLClientV9) ReadCollection() (*Response, error) { + sc.Config.log.V(5).Info("READING COLLECTION: kubedb-system") + req := sc.Client.R().SetDoNotParseResponse(true) + req.SetHeader("Content-Type", "application/json") + queryParams := QueryParams{ + Query: "*:*", + Limit: 10, + } + req.SetBody(queryParams) + res, err := req.Get("/solr/kubedb-system/select") + if err != nil { + sc.log.Error(err, "Failed to send http request to read a collection") + return nil, err + } + + writeResponse := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return writeResponse, nil +} + +func (sc *SLClientV9) BackupCollection(ctx context.Context, collection string, backupName string, location string, repository string) (*Response, error) { + sc.Config.log.V(5).Info(fmt.Sprintf("BACKUP COLLECTION: %s", collection)) + req := sc.Client.R().SetDoNotParseResponse(true).SetContext(ctx) + req.SetHeader("Content-Type", "application/json") + backupParams := &BackupRestoreParams{ + Location: location, + Repository: repository, + Async: fmt.Sprintf("%s-backup", collection), + } + req.SetBody(backupParams) + + res, err := req.Post(fmt.Sprintf("/api/collections/%s/backups/%s/versions", collection, backupName)) + if err != nil { + sc.log.Error(err, "Failed to send http request to backup a collection") + return nil, err + } + + backupResponse := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return backupResponse, nil +} + +func (sc *SLClientV9) RestoreCollection(ctx context.Context, collection string, backupName string, location string, repository string, backupId int) (*Response, error) { + sc.Config.log.V(5).Info(fmt.Sprintf("RESTORE COLLECTION: %s", collection)) + req := sc.Client.R().SetDoNotParseResponse(true).SetContext(ctx) + req.SetHeader("Content-Type", "application/json") + restoreParams := &BackupRestoreParams{ + Location: location, + Repository: repository, + Collection: collection, + BackupId: backupId, + Async: fmt.Sprintf("%s-restore", collection), + } + req.SetBody(restoreParams) + + res, err := req.Post(fmt.Sprintf("/api/backups/%s/restore", backupName)) + if err != nil { + sc.log.Error(err, "Failed to send http request to restore a collection") + return nil, err + } + + backupResponse := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return backupResponse, nil +} + +func (sc *SLClientV9) FlushStatus(asyncId string) (*Response, error) { + sc.Config.log.V(5).Info("Flush Status") + req := sc.Client.R().SetDoNotParseResponse(true) + req.SetHeader("Content-Type", "application/json") + + res, err := req.Delete(fmt.Sprintf("/api/cluster/command-status/%s", asyncId)) + if err != nil { + sc.log.Error(err, "Failed to send http request to flush status") + return nil, err + } + + backupResponse := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return backupResponse, nil +} + +func (sc *SLClientV9) RequestStatus(asyncId string) (*Response, error) { + sc.Config.log.V(5).Info("Request Status") + req := sc.Client.R().SetDoNotParseResponse(true) + req.SetHeader("Content-Type", "application/json") + res, err := req.Get(fmt.Sprintf("/api/cluster/command-status/%s", asyncId)) + if err != nil { + sc.log.Error(err, "Failed to send http request to request status") + return nil, err + } + backupResponse := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return backupResponse, nil +} + +func (sc *SLClientV9) DeleteBackup(ctx context.Context, backupName string, collection string, location string, repository string, backupId int, snap string) (*Response, error) { + sc.Config.log.V(5).Info(fmt.Sprintf("DELETE BACKUP ID %d of BACKUP %s", backupId, backupName)) + req := sc.Client.R().SetDoNotParseResponse(true).SetContext(ctx) + req.SetHeader("Content-Type", "application/json") + async := fmt.Sprintf("%s-delete", collection) + if snap != "" { + async = fmt.Sprintf("%s-%s", async, snap) + } + params := map[string]string{ + "location": location, + "repository": repository, + "async": async, + } + req.SetQueryParams(params) + + res, err := req.Delete(fmt.Sprintf("/api/backups/%s/versions/%d", backupName, backupId)) + if err != nil { + sc.log.Error(err, "Failed to send http request to restore a collection") + return nil, err + } + + backupResponse := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return backupResponse, nil +} + +func (sc *SLClientV9) PurgeBackup(ctx context.Context, backupName string, collection string, location string, repository string, snap string) (*Response, error) { + sc.Config.log.V(5).Info(fmt.Sprintf("PURGE BACKUP ID %s", backupName)) + req := sc.Client.R().SetDoNotParseResponse(true).SetContext(ctx) + req.SetHeader("Content-Type", "application/json") + async := fmt.Sprintf("%s-purge", collection) + if snap != "" { + async = fmt.Sprintf("%s-%s", async, snap) + } + params := &BackupRestoreParams{ + Location: location, + Repository: repository, + Async: async, + } + req.SetBody(params) + + res, err := req.Put(fmt.Sprintf("/api/backups/%s/purgeUnused", backupName)) + if err != nil { + sc.log.Error(err, "Failed to send http request to restore a collection") + return nil, err + } + + backupResponse := &Response{ + Code: res.StatusCode(), + header: res.Header(), + body: res.RawBody(), + } + return backupResponse, nil +} + +func (sc *SLClientV9) GetConfig() *Config { + return sc.Config +} + +func (sc *SLClientV9) GetClient() *resty.Client { + return sc.Client +} + +func (sc *SLClientV9) GetLog() logr.Logger { + return sc.log +} + +func (sc *SLClientV9) DecodeBackupResponse(data map[string]interface{}, collection string) ([]byte, error) { + sc.Config.log.V(5).Info("Decode Backup Data") + backupResponse, ok := data["response"].(map[string]interface{}) + if !ok { + err := errors.New(fmt.Sprintf("didn't find status for collection %s\n", collection)) + return nil, err + } + klog.Info("backup response ", backupResponse) + b, err := json.Marshal(backupResponse) + if err != nil { + klog.Error(fmt.Sprintf("Could not format response for collection %s into json", collection)) + return nil, err + } + klog.Info(fmt.Sprintf("Response for collection %s\n%v", collection, string(b))) + return b, nil +} diff --git a/solr/util.go b/solr/util.go new file mode 100644 index 000000000..aeed9523e --- /dev/null +++ b/solr/util.go @@ -0,0 +1,127 @@ +package solr + +import ( + "encoding/json" + "io" + + "github.com/pkg/errors" + + "fmt" +) + +func (sc *Client) DecodeResponse(response *Response) (map[string]interface{}, error) { + defer func(Body io.ReadCloser) { + err := Body.Close() + if err != nil { + err1 := errors.Wrap(err, "failed to parse response body") + if err1 != nil { + return + } + return + } + }(response.body) + + responseBody := make(map[string]interface{}) + if err := json.NewDecoder(response.body).Decode(&responseBody); err != nil { + return nil, fmt.Errorf("failed to deserialize the response: %v", err) + } + + return responseBody, nil +} + +func (sc *Client) GetResponseStatus(responseBody map[string]interface{}) (int, error) { + err, ok := responseBody["error"].(map[string]interface{}) + if ok { + msg, ok := err["msg"].(string) + if !ok { + return -1, errors.New("no msg found in error message while getting response status") + + } + code, ok := err["code"].(float64) + if !ok { + return -1, errors.New("error occurred but didn't found error code while getting response status") + + } + return -1, errors.New(fmt.Sprintf("Error: %v with code %d", msg, int(code))) + } + responseHeader, ok := responseBody["responseHeader"].(map[string]interface{}) + if !ok { + return -1, errors.New("didn't find responseHeader") + } + + status, ok := responseHeader["status"].(float64) + if !ok { + return -1, errors.New("didn't find status") + } + + if int(status) != 0 { + msg, ok := responseBody["message"].(string) + if !ok { + return -1, errors.New("no msg found in error message") + + } + return -1, errors.New(fmt.Sprintf("Error: %v with code %d", msg, int(status))) + } + return int(status), nil +} + +func (sc *Client) GetAsyncStatus(responseBody map[string]interface{}) (string, error) { + status, ok := responseBody["status"].(map[string]interface{}) + if !ok { + return "unknown", errors.New("didn't find status") + } + + state, ok := status["state"].(string) + if !ok { + return "unknown", errors.New("didn't find state") + } + + return state, nil +} + +func (sc *Client) DecodeCollectionHealth(responseBody map[string]interface{}) error { + clusterInfo, ok := responseBody["cluster"].(map[string]interface{}) + if !ok { + return errors.New(fmt.Sprintf("did not find cluster %v\n", responseBody)) + } + collections, ok := clusterInfo["collections"].(map[string]interface{}) + if !ok { + return errors.New("didn't find collections") + } + for name, info := range collections { + collectionInfo := info.(map[string]interface{}) + health, ok := collectionInfo["health"].(string) + if !ok { + return errors.New("didn't find health") + } + if health != "GREEN" { + config := sc.GetConfig() + config.log.Error(errors.New(""), fmt.Sprintf("Health of collection %s IS NOT GREEN", name)) + return errors.New(fmt.Sprintf("health for collection %s is not green", name)) + } + } + return nil +} + +func (sc *Client) GetCollectionList(responseBody map[string]interface{}) ([]string, error) { + collectionList, ok := responseBody["collections"].([]interface{}) + if !ok { + return []string{}, errors.New("didn't find collection list") + } + + collections := make([]string, 0) + + for idx := range collectionList { + collections = append(collections, collectionList[idx].(string)) + } + return collections, nil +} + +func (sc *Client) SearchCollection(collections []string) bool { + for _, collection := range collections { + if collection == "kubedb-system" { + return true + } + } + return false +} From e9822fc51186ba4000b6c973f8788e83dae3c72d Mon Sep 17 00:00:00 2001 From: pritamdas99 Date: Thu, 4 Jul 2024 12:01:19 +0600 Subject: [PATCH 02/13] Update go mod Signed-off-by: pritamdas99 --- go.mod | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/go.mod b/go.mod index fc96c9073..97306cdbc 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/elastic/go-elasticsearch/v6 v6.8.10 github.com/elastic/go-elasticsearch/v7 v7.15.1 github.com/elastic/go-elasticsearch/v8 v8.4.0 - github.com/go-logr/logr v1.4.1 + github.com/go-logr/logr v1.4.2 github.com/go-resty/resty/v2 v2.11.0 github.com/go-sql-driver/mysql v1.8.1 github.com/lib/pq v1.10.7 @@ -55,7 +55,6 @@ require ( github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-faster/city v1.0.1 // indirect github.com/go-faster/errors v0.7.1 // indirect - github.com/go-logr/logr v1.4.2 // indirect github.com/go-openapi/jsonpointer v0.21.0 // indirect github.com/go-openapi/jsonreference v0.21.0 // indirect github.com/go-openapi/swag v0.23.0 // indirect From a77ea4d1c45677c7bb1c7a5659e42473e18bc136 Mon Sep 17 00:00:00 2001 From: pritamdas99 Date: Thu, 4 Jul 2024 12:26:43 +0600 Subject: [PATCH 03/13] Update conatant. Signed-off-by: pritamdas99 --- solr/kubedb_client_builder.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/solr/kubedb_client_builder.go b/solr/kubedb_client_builder.go index e08b95aeb..d5a479fa1 100644 --- a/solr/kubedb_client_builder.go +++ b/solr/kubedb_client_builder.go @@ -7,6 +7,7 @@ import ( gerr "github.com/pkg/errors" core "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" + "kubedb.dev/apimachinery/apis/kubedb" "net" "net/http" "time" @@ -133,5 +134,5 @@ func (o *KubeDBClientBuilder) GetSolrClient() (*Client, error) { } func (o *KubeDBClientBuilder) GetHostPath(db *api.Solr) string { - return fmt.Sprintf("%v://%s.%s.svc.cluster.local:%d", db.GetConnectionScheme(), db.ServiceName(), db.GetNamespace(), api.SolrRestPort) + return fmt.Sprintf("%v://%s.%s.svc.cluster.local:%d", db.GetConnectionScheme(), db.ServiceName(), db.GetNamespace(), kubedb.SolrRestPort) } From d9e49ac874e41f76aadc85c7b7361a66bfbbd649 Mon Sep 17 00:00:00 2001 From: pritamdas99 Date: Thu, 4 Jul 2024 12:50:31 +0600 Subject: [PATCH 04/13] Apply goimport. Signed-off-by: pritamdas99 --- solr/api.go | 1 + solr/kubedb_client_builder.go | 7 ++++--- solr/solrv8.go | 6 +++--- solr/solrv9.go | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/solr/api.go b/solr/api.go index 686ca8e2a..5ceadbe7d 100644 --- a/solr/api.go +++ b/solr/api.go @@ -2,6 +2,7 @@ package solr import ( "context" + "github.com/go-logr/logr" "github.com/go-resty/resty/v2" ) diff --git a/solr/kubedb_client_builder.go b/solr/kubedb_client_builder.go index d5a479fa1..737bb8233 100644 --- a/solr/kubedb_client_builder.go +++ b/solr/kubedb_client_builder.go @@ -3,14 +3,15 @@ package solr import ( "context" "errors" + "net" + "net/http" + "time" + "github.com/Masterminds/semver/v3" gerr "github.com/pkg/errors" core "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" "kubedb.dev/apimachinery/apis/kubedb" - "net" - "net/http" - "time" "fmt" diff --git a/solr/solrv8.go b/solr/solrv8.go index 082f09c04..0cda4f716 100644 --- a/solr/solrv8.go +++ b/solr/solrv8.go @@ -3,12 +3,12 @@ package solr import ( "context" "encoding/json" - "errors" "fmt" + "strconv" + "github.com/go-logr/logr" "github.com/go-resty/resty/v2" "k8s.io/klog/v2" - "strconv" ) type SLClientV8 struct { @@ -311,7 +311,7 @@ func (sc *SLClientV8) DecodeBackupResponse(data map[string]interface{}, collecti sc.Config.log.V(5).Info("Decode Backup Data") backupResponse, ok := data["response"].([]interface{}) if !ok { - err := errors.New(fmt.Sprintf("didn't find status for collection %s\n", collection)) + err := fmt.Errorf("didn't find status for collection %s\n", collection) return nil, err } mp := make(map[string]interface{}) diff --git a/solr/solrv9.go b/solr/solrv9.go index 3cbdcb75d..2c4935e0e 100644 --- a/solr/solrv9.go +++ b/solr/solrv9.go @@ -3,8 +3,8 @@ package solr import ( "context" "encoding/json" - "errors" "fmt" + "github.com/go-logr/logr" "github.com/go-resty/resty/v2" "k8s.io/klog/v2" @@ -291,7 +291,7 @@ func (sc *SLClientV9) DecodeBackupResponse(data map[string]interface{}, collecti sc.Config.log.V(5).Info("Decode Backup Data") backupResponse, ok := data["response"].(map[string]interface{}) if !ok { - err := errors.New(fmt.Sprintf("didn't find status for collection %s\n", collection)) + err := fmt.Errorf("didn't find status for collection %s\n", collection) return nil, err } klog.Info("backup response ", backupResponse) From 63c3d0eb45eaaf0d2c4569c12152c9770dbc4195 Mon Sep 17 00:00:00 2001 From: pritamdas99 Date: Fri, 12 Jul 2024 15:10:07 +0600 Subject: [PATCH 05/13] Update backup restore api Signed-off-by: pritamdas99 --- solr/solrv9.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/solr/solrv9.go b/solr/solrv9.go index 2c4935e0e..aa02e600c 100644 --- a/solr/solrv9.go +++ b/solr/solrv9.go @@ -133,14 +133,16 @@ func (sc *SLClientV9) BackupCollection(ctx context.Context, collection string, b sc.Config.log.V(5).Info(fmt.Sprintf("BACKUP COLLECTION: %s", collection)) req := sc.Client.R().SetDoNotParseResponse(true).SetContext(ctx) req.SetHeader("Content-Type", "application/json") - backupParams := &BackupRestoreParams{ - Location: location, - Repository: repository, - Async: fmt.Sprintf("%s-backup", collection), + backupParams := map[string]string{ + "action": "BACKUP", + "name": backupName, + "location": location, + "repository": repository, + "async": fmt.Sprintf("%s-backup", collection), } - req.SetBody(backupParams) + req.SetQueryParams(backupParams) - res, err := req.Post(fmt.Sprintf("/api/collections/%s/backups/%s/versions", collection, backupName)) + res, err := req.Post("/solr/admin/collections") if err != nil { sc.log.Error(err, "Failed to send http request to backup a collection") return nil, err @@ -158,16 +160,16 @@ func (sc *SLClientV9) RestoreCollection(ctx context.Context, collection string, sc.Config.log.V(5).Info(fmt.Sprintf("RESTORE COLLECTION: %s", collection)) req := sc.Client.R().SetDoNotParseResponse(true).SetContext(ctx) req.SetHeader("Content-Type", "application/json") - restoreParams := &BackupRestoreParams{ - Location: location, - Repository: repository, - Collection: collection, - BackupId: backupId, - Async: fmt.Sprintf("%s-restore", collection), + restoreParams := map[string]string{ + "action": "RESTORE", + "name": backupName, + "location": location, + "repository": repository, + "async": fmt.Sprintf("%s-restore", collection), } - req.SetBody(restoreParams) + req.SetQueryParams(restoreParams) - res, err := req.Post(fmt.Sprintf("/api/backups/%s/restore", backupName)) + res, err := req.Post("/solr/admin/collections") if err != nil { sc.log.Error(err, "Failed to send http request to restore a collection") return nil, err From f07bef3a219e1e5d4d5180d5cc96fb20349dd97f Mon Sep 17 00:00:00 2001 From: pritamdas99 Date: Fri, 12 Jul 2024 15:35:34 +0600 Subject: [PATCH 06/13] Update to v1 api. Signed-off-by: pritamdas99 --- solr/solrv9.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/solr/solrv9.go b/solr/solrv9.go index aa02e600c..29f887bd4 100644 --- a/solr/solrv9.go +++ b/solr/solrv9.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "strconv" "github.com/go-logr/logr" "github.com/go-resty/resty/v2" @@ -130,7 +131,7 @@ func (sc *SLClientV9) ReadCollection() (*Response, error) { } func (sc *SLClientV9) BackupCollection(ctx context.Context, collection string, backupName string, location string, repository string) (*Response, error) { - sc.Config.log.V(5).Info(fmt.Sprintf("BACKUP COLLECTION: %s", collection)) + sc.Config.log.V(5).Info(fmt.Sprintf("BACKUP COLLECTION v11111111111111111: %s", collection)) req := sc.Client.R().SetDoNotParseResponse(true).SetContext(ctx) req.SetHeader("Content-Type", "application/json") backupParams := map[string]string{ @@ -228,13 +229,16 @@ func (sc *SLClientV9) DeleteBackup(ctx context.Context, backupName string, colle async = fmt.Sprintf("%s-%s", async, snap) } params := map[string]string{ + "action": "DELETEBACKUP", + "name": backupName, "location": location, "repository": repository, + "backupId": strconv.Itoa(backupId), "async": async, } req.SetQueryParams(params) - res, err := req.Delete(fmt.Sprintf("/api/backups/%s/versions/%d", backupName, backupId)) + res, err := req.Delete("/solr/admin/collections") if err != nil { sc.log.Error(err, "Failed to send http request to restore a collection") return nil, err @@ -256,14 +260,17 @@ func (sc *SLClientV9) PurgeBackup(ctx context.Context, backupName string, collec if snap != "" { async = fmt.Sprintf("%s-%s", async, snap) } - params := &BackupRestoreParams{ - Location: location, - Repository: repository, - Async: async, + params := map[string]string{ + "action": "DELETEBACKUP", + "name": backupName, + "location": location, + "repository": repository, + "purgeUnused": "true", + "async": async, } - req.SetBody(params) + req.SetQueryParams(params) - res, err := req.Put(fmt.Sprintf("/api/backups/%s/purgeUnused", backupName)) + res, err := req.Delete("/solr/admin/collections") if err != nil { sc.log.Error(err, "Failed to send http request to restore a collection") return nil, err From 625ead218b8e7f04696caeff78ace1b3dc545585 Mon Sep 17 00:00:00 2001 From: pritamdas99 Date: Fri, 12 Jul 2024 15:48:11 +0600 Subject: [PATCH 07/13] Update backup api Signed-off-by: pritamdas99 --- solr/solrv9.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/solr/solrv9.go b/solr/solrv9.go index 29f887bd4..a85bbcc27 100644 --- a/solr/solrv9.go +++ b/solr/solrv9.go @@ -137,6 +137,7 @@ func (sc *SLClientV9) BackupCollection(ctx context.Context, collection string, b backupParams := map[string]string{ "action": "BACKUP", "name": backupName, + "collection": collection, "location": location, "repository": repository, "async": fmt.Sprintf("%s-backup", collection), @@ -165,6 +166,7 @@ func (sc *SLClientV9) RestoreCollection(ctx context.Context, collection string, "action": "RESTORE", "name": backupName, "location": location, + "collection": collection, "repository": repository, "async": fmt.Sprintf("%s-restore", collection), } From 323695e49828016f9055bd6bcae595eb0d3cc2e9 Mon Sep 17 00:00:00 2001 From: pritamdas99 Date: Fri, 12 Jul 2024 16:11:32 +0600 Subject: [PATCH 08/13] Update purge api call Signed-off-by: pritamdas99 --- solr/solrv9.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/solr/solrv9.go b/solr/solrv9.go index a85bbcc27..6c2fbceed 100644 --- a/solr/solrv9.go +++ b/solr/solrv9.go @@ -240,7 +240,7 @@ func (sc *SLClientV9) DeleteBackup(ctx context.Context, backupName string, colle } req.SetQueryParams(params) - res, err := req.Delete("/solr/admin/collections") + res, err := req.Get("/solr/admin/collections") if err != nil { sc.log.Error(err, "Failed to send http request to restore a collection") return nil, err @@ -272,7 +272,7 @@ func (sc *SLClientV9) PurgeBackup(ctx context.Context, backupName string, collec } req.SetQueryParams(params) - res, err := req.Delete("/solr/admin/collections") + res, err := req.Get("/solr/admin/collections") if err != nil { sc.log.Error(err, "Failed to send http request to restore a collection") return nil, err From 4eb17859290a9ca77c63b969f8f8000a006bb523 Mon Sep 17 00:00:00 2001 From: pritamdas99 Date: Wed, 17 Jul 2024 12:36:32 +0600 Subject: [PATCH 09/13] Update backup api with constants Signed-off-by: pritamdas99 --- solr/api.go | 18 +++++++ solr/client.go | 14 ----- solr/kubedb_client_builder.go | 18 +++---- solr/solrv8.go | 98 +++++++++++++++++------------------ solr/solrv9.go | 90 ++++++++++++++++---------------- 5 files changed, 119 insertions(+), 119 deletions(-) diff --git a/solr/api.go b/solr/api.go index 5ceadbe7d..912fde342 100644 --- a/solr/api.go +++ b/solr/api.go @@ -7,6 +7,24 @@ import ( "github.com/go-resty/resty/v2" ) +const ( + writeCollectionName = "kubedb-system" + Action = "action" + ActionBackup = "BACKUP" + ActionRestore = "RESTORE" + ActionDeleteBackup = "DELETEBACKUP" + BackupName = "name" + Location = "location" + Repository = "repository" + Collection = "collection" + Async = "async" + PurgeUnused = "purgeUnused" + BackupId = "backupId" + DeleteStatus = "DELETESTATUS" + RequestStatus = "REQUESTSTATUS" + RequestId = "requestid" +) + type SLClient interface { GetClusterStatus() (*Response, error) ListCollection() (*Response, error) diff --git a/solr/client.go b/solr/client.go index c6939432a..c5736db0e 100644 --- a/solr/client.go +++ b/solr/client.go @@ -54,20 +54,6 @@ type QueryParams struct { Limit int `json:"limit,omitempty" yaml:"limit,omitempty"` } -type BackupParams struct { - Location string `json:"location,omitempty" yaml:"location,omitempty"` - Repository string `json:"repository,omitempty" yaml:"repository,omitempty"` - Async string `json:"async,omitempty" yaml:"async,omitempty"` -} - -type BackupRestoreParams struct { - Location string `json:"location,omitempty" yaml:"location,omitempty"` - Repository string `json:"repository,omitempty" yaml:"repository,omitempty"` - Collection string `json:"collection,omitempty" yaml:"collection,omitempty"` - Async string `json:"async,omitempty" yaml:"async,omitempty"` - BackupId int `json:"backupId,omitempty" yaml:"backupId,omitempty"` -} - type CreateParams struct { Name string `json:"name,omitempty" yaml:"name,omitempty"` Config string `json:"config,omitempty" yaml:"config,omitempty"` diff --git a/solr/kubedb_client_builder.go b/solr/kubedb_client_builder.go index 737bb8233..b208d1663 100644 --- a/solr/kubedb_client_builder.go +++ b/solr/kubedb_client_builder.go @@ -70,14 +70,14 @@ func (o *KubeDBClientBuilder) GetSolrClient() (*Client, error) { config := Config{ host: o.url, transport: &http.Transport{ - IdleConnTimeout: time.Minute * 6, + IdleConnTimeout: time.Second * 10, DialContext: (&net.Dialer{ - Timeout: time.Minute * 6, - KeepAlive: time.Minute * 6, + Timeout: time.Second * 30, + KeepAlive: time.Second * 30, }).DialContext, - TLSHandshakeTimeout: time.Minute * 6, - ResponseHeaderTimeout: time.Minute * 6, - ExpectContinueTimeout: time.Minute * 6, + TLSHandshakeTimeout: time.Second * 20, + ResponseHeaderTimeout: time.Second * 20, + ExpectContinueTimeout: time.Second * 20, }, connectionScheme: o.db.GetConnectionScheme(), log: o.log, @@ -103,28 +103,26 @@ func (o *KubeDBClientBuilder) GetSolrClient() (*Client, error) { case version.Major() == 9: newClient := resty.New() newClient.SetScheme(config.connectionScheme).SetBaseURL(config.host).SetTransport(config.transport) - newClient.SetTimeout(6 * time.Minute) + newClient.SetTimeout(time.Second * 30) newClient.SetHeader("Accept", "application/json") newClient.SetDisableWarn(true) newClient.SetBasicAuth(string(authSecret.Data[core.BasicAuthUsernameKey]), string(authSecret.Data[core.BasicAuthPasswordKey])) return &Client{ &SLClientV9{ Client: newClient, - log: config.log, Config: &config, }, }, nil case version.Major() == 8: newClient := resty.New() newClient.SetScheme(config.connectionScheme).SetBaseURL(config.host).SetTransport(config.transport) - newClient.SetTimeout(6 * time.Minute) + newClient.SetTimeout(time.Second * 30) newClient.SetHeader("Accept", "application/json") newClient.SetDisableWarn(true) newClient.SetBasicAuth(string(authSecret.Data[core.BasicAuthUsernameKey]), string(authSecret.Data[core.BasicAuthPasswordKey])) return &Client{ &SLClientV8{ Client: newClient, - log: config.log, Config: &config, }, }, nil diff --git a/solr/solrv8.go b/solr/solrv8.go index 0cda4f716..346718290 100644 --- a/solr/solrv8.go +++ b/solr/solrv8.go @@ -13,7 +13,6 @@ import ( type SLClientV8 struct { Client *resty.Client - log logr.Logger Config *Config } @@ -23,7 +22,7 @@ func (sc *SLClientV8) GetClusterStatus() (*Response, error) { req.SetQueryParam("action", "CLUSTERSTATUS") res, err := req.Get("/solr/admin/collections") if err != nil { - sc.log.Error(err, "Failed to send http request") + sc.Config.log.Error(err, "Failed to send http request") return nil, err } @@ -36,12 +35,12 @@ func (sc *SLClientV8) GetClusterStatus() (*Response, error) { } func (sc *SLClientV8) ListCollection() (*Response, error) { - sc.Config.log.V(5).Info("SEARCHING COLLECTION: kubedb-system") + sc.Config.log.V(5).Info(fmt.Sprintf("SEARCHING COLLECTION: %s", writeCollectionName)) req := sc.Client.R().SetDoNotParseResponse(true) req.SetQueryParam("action", "LIST") res, err := req.Get("/solr/admin/collections") if err != nil { - sc.log.Error(err, "Failed to send http request while getting colection list") + sc.Config.log.Error(err, "Failed to send http request while getting colection list") return nil, err } response := &Response{ @@ -53,12 +52,12 @@ func (sc *SLClientV8) ListCollection() (*Response, error) { } func (sc *SLClientV8) CreateCollection() (*Response, error) { - sc.Config.log.V(5).Info("CREATING COLLECTION: kubedb-system") + sc.Config.log.V(5).Info(fmt.Sprintf("CREATING COLLECTION: %s", writeCollectionName)) req := sc.Client.R().SetDoNotParseResponse(true) req.SetHeader("Content-Type", "application/json") params := map[string]string{ "action": "CREATE", - "name": "kubedb-system", + "name": writeCollectionName, "numShards": "1", "replicationFactor": "1", } @@ -66,7 +65,7 @@ func (sc *SLClientV8) CreateCollection() (*Response, error) { req.SetQueryParams(params) res, err := req.Post("/solr/admin/collections") if err != nil { - sc.log.Error(err, "Failed to send http request to create a collection") + sc.Config.log.Error(err, "Failed to send http request to create a collection") return nil, err } @@ -79,7 +78,7 @@ func (sc *SLClientV8) CreateCollection() (*Response, error) { } func (sc *SLClientV8) WriteCollection() (*Response, error) { - sc.Config.log.V(5).Info("WRITING COLLECTION: kubedb-system") + sc.Config.log.V(5).Info(fmt.Sprintf("WRITING COLLECTION: %s", writeCollectionName)) req := sc.Client.R().SetDoNotParseResponse(true) req.SetHeader("Content-Type", "application/json") data1 := &Data{ @@ -94,9 +93,9 @@ func (sc *SLClientV8) WriteCollection() (*Response, error) { Add: data1, } req.SetBody(add) - res, err := req.Post("/solr/kubedb-system/update") + res, err := req.Post(fmt.Sprintf("/solr/%s/update", writeCollectionName)) if err != nil { - sc.log.Error(err, "Failed to send http request to add document in collect") + sc.Config.log.Error(err, "Failed to send http request to add document in collect") return nil, err } @@ -109,12 +108,12 @@ func (sc *SLClientV8) WriteCollection() (*Response, error) { } func (sc *SLClientV8) ReadCollection() (*Response, error) { - sc.Config.log.V(5).Info("READING COLLECTION: kubedb-system") + sc.Config.log.V(5).Info(fmt.Sprintf("READING COLLECTION: %s", writeCollectionName)) req := sc.Client.R().SetDoNotParseResponse(true) req.SetQueryParam("q", "*:*") - res, err := req.Get("/solr/kubedb-system/select") + res, err := req.Get(fmt.Sprintf("/solr/%s/select", writeCollectionName)) if err != nil { - sc.log.Error(err, "Failed to send http request to read a collection") + sc.Config.log.Error(err, "Failed to send http request to read a collection") return nil, err } @@ -131,19 +130,19 @@ func (sc *SLClientV8) BackupCollection(ctx context.Context, collection string, b req := sc.Client.R().SetDoNotParseResponse(true).SetContext(ctx) req.SetHeader("Content-Type", "application/json") params := map[string]string{ - "action": "BACKUP", - "name": backupName, - "collection": collection, - "location": location, - "repository": repository, - "async": fmt.Sprintf("%s-backup", collection), + Action: ActionBackup, + BackupName: backupName, + Collection: collection, + Location: location, + Repository: repository, + Async: fmt.Sprintf("%s-backup", collection), } req.SetQueryParams(params) res, err := req.Post("/solr/admin/collections") if err != nil { - sc.log.Error(err, "Failed to send http request to backup a collection") + sc.Config.log.Error(err, "Failed to send http request to backup a collection") return nil, err } @@ -160,20 +159,20 @@ func (sc *SLClientV8) RestoreCollection(ctx context.Context, collection string, req := sc.Client.R().SetDoNotParseResponse(true).SetContext(ctx) req.SetHeader("Content-Type", "application/json") params := map[string]string{ - "action": "RESTORE", - "name": backupName, - "collection": collection, - "location": location, - "repository": repository, - "backupId": strconv.Itoa(backupId), - "async": fmt.Sprintf("%s-restore", collection), + Action: ActionRestore, + BackupName: backupName, + Location: location, + Collection: collection, + Repository: repository, + BackupId: strconv.Itoa(backupId), + Async: fmt.Sprintf("%s-restore", collection), } req.SetQueryParams(params) res, err := req.Post("/solr/admin/collections") if err != nil { - sc.log.Error(err, "Failed to send http request to restore a collection") + sc.Config.log.Error(err, "Failed to send http request to restore a collection") return nil, err } @@ -191,13 +190,13 @@ func (sc *SLClientV8) FlushStatus(asyncId string) (*Response, error) { req.SetHeader("Content-Type", "application/json") params := map[string]string{ - "action": "DELETESTATUS", - "requestid": asyncId, + Action: DeleteStatus, + RequestId: asyncId, } req.SetQueryParams(params) res, err := req.Get("/solr/admin/collections") if err != nil { - sc.log.Error(err, "Failed to send http request to flush status") + sc.Config.log.Error(err, "Failed to send http request to flush status") return nil, err } @@ -214,13 +213,13 @@ func (sc *SLClientV8) RequestStatus(asyncId string) (*Response, error) { req := sc.Client.R().SetDoNotParseResponse(true) req.SetHeader("Content-Type", "application/json") params := map[string]string{ - "action": "REQUESTSTATUS", - "requestid": asyncId, + Action: RequestStatus, + RequestId: asyncId, } req.SetQueryParams(params) res, err := req.Get("/solr/admin/collections") if err != nil { - sc.log.Error(err, "Failed to send http request to request status") + sc.Config.log.Error(err, "Failed to send http request to request status") return nil, err } backupResponse := &Response{ @@ -240,19 +239,18 @@ func (sc *SLClientV8) DeleteBackup(ctx context.Context, backupName string, colle async = fmt.Sprintf("%s-%s", async, snap) } params := map[string]string{ - "action": "DELETEBACKUP", - "name": backupName, - "location": location, - "repository": repository, - "backupId": strconv.Itoa(backupId), - "purgeUnused": "true", - "async": async, + Action: ActionDeleteBackup, + BackupName: backupName, + Location: location, + Repository: repository, + BackupId: strconv.Itoa(backupId), + Async: async, } req.SetQueryParams(params) res, err := req.Delete("/solr/admin/collections") if err != nil { - sc.log.Error(err, "Failed to send http request to restore a collection") + sc.Config.log.Error(err, "Failed to send http request to restore a collection") return nil, err } @@ -273,17 +271,17 @@ func (sc *SLClientV8) PurgeBackup(ctx context.Context, backupName string, collec async = fmt.Sprintf("%s-%s", async, snap) } params := map[string]string{ - "action": "DELETEBACKUP", - "name": backupName, - "location": location, - "repository": repository, - "purgeUnused": "true", - "async": async, + Action: ActionDeleteBackup, + BackupName: backupName, + Location: location, + Repository: repository, + PurgeUnused: "true", + Async: async, } req.SetQueryParams(params) res, err := req.Put("/solr/admin/collections") if err != nil { - sc.log.Error(err, "Failed to send http request to restore a collection") + sc.Config.log.Error(err, "Failed to send http request to restore a collection") return nil, err } @@ -304,7 +302,7 @@ func (sc *SLClientV8) GetClient() *resty.Client { } func (sc *SLClientV8) GetLog() logr.Logger { - return sc.log + return sc.Config.log } func (sc *SLClientV8) DecodeBackupResponse(data map[string]interface{}, collection string) ([]byte, error) { diff --git a/solr/solrv9.go b/solr/solrv9.go index 6c2fbceed..b8d75107d 100644 --- a/solr/solrv9.go +++ b/solr/solrv9.go @@ -13,7 +13,6 @@ import ( type SLClientV9 struct { Client *resty.Client - log logr.Logger Config *Config } @@ -22,7 +21,7 @@ func (sc *SLClientV9) GetClusterStatus() (*Response, error) { req := sc.Client.R().SetDoNotParseResponse(true) res, err := req.Get("/api/cluster") if err != nil { - sc.log.Error(err, "Failed to send http request") + sc.Config.log.Error(err, "Failed to send http request") return nil, err } @@ -35,11 +34,11 @@ func (sc *SLClientV9) GetClusterStatus() (*Response, error) { } func (sc *SLClientV9) ListCollection() (*Response, error) { - sc.Config.log.V(5).Info("SEARCHING COLLECTION: kubedb-system") + sc.Config.log.V(5).Info(fmt.Sprintf("SEARCHING COLLECTION: %s", writeCollectionName)) req := sc.Client.R().SetDoNotParseResponse(true) res, err := req.Get("/api/collections") if err != nil { - sc.log.Error(err, "Failed to send http request while getting colection list") + sc.Config.log.Error(err, "Failed to send http request while getting colection list") return nil, err } response := &Response{ @@ -51,11 +50,11 @@ func (sc *SLClientV9) ListCollection() (*Response, error) { } func (sc *SLClientV9) CreateCollection() (*Response, error) { - sc.Config.log.V(5).Info("CREATING COLLECTION: kubedb-system") + sc.Config.log.V(5).Info(fmt.Sprintf("CREATING COLLECTION: %s", writeCollectionName)) req := sc.Client.R().SetDoNotParseResponse(true) req.SetHeader("Content-Type", "application/json") createParams := &CreateParams{ - Name: "kubedb-system", + Name: writeCollectionName, NumShards: 1, ReplicationFactor: 1, } @@ -63,7 +62,7 @@ func (sc *SLClientV9) CreateCollection() (*Response, error) { req.SetBody(createParams) res, err := req.Post("/api/collections") if err != nil { - sc.log.Error(err, "Failed to send http request to create a collection") + sc.Config.log.Error(err, "Failed to send http request to create a collection") return nil, err } @@ -78,7 +77,7 @@ func (sc *SLClientV9) CreateCollection() (*Response, error) { type ADDList []ADD func (sc *SLClientV9) WriteCollection() (*Response, error) { - sc.Config.log.V(5).Info("WRITING COLLECTION: kubedb-system") + sc.Config.log.V(5).Info(fmt.Sprintf("WRITING COLLECTION: %s", writeCollectionName)) req := sc.Client.R().SetDoNotParseResponse(true) req.SetHeader("Content-Type", "application/json") data1 := &Data{ @@ -93,9 +92,9 @@ func (sc *SLClientV9) WriteCollection() (*Response, error) { Add: data1, } req.SetBody(add) - res, err := req.Post("/solr/kubedb-system/update") + res, err := req.Post(fmt.Sprintf("/solr/%s/update", writeCollectionName)) if err != nil { - sc.log.Error(err, "Failed to send http request to add document in collect") + sc.Config.log.Error(err, "Failed to send http request to add document in collect") return nil, err } @@ -108,7 +107,7 @@ func (sc *SLClientV9) WriteCollection() (*Response, error) { } func (sc *SLClientV9) ReadCollection() (*Response, error) { - sc.Config.log.V(5).Info("READING COLLECTION: kubedb-system") + sc.Config.log.V(5).Info(fmt.Sprintf("READING COLLECTION: %s", writeCollectionName)) req := sc.Client.R().SetDoNotParseResponse(true) req.SetHeader("Content-Type", "application/json") queryParams := QueryParams{ @@ -116,9 +115,9 @@ func (sc *SLClientV9) ReadCollection() (*Response, error) { Limit: 10, } req.SetBody(queryParams) - res, err := req.Get("/solr/kubedb-system/select") + res, err := req.Get(fmt.Sprintf("/solr/%s/select", writeCollectionName)) if err != nil { - sc.log.Error(err, "Failed to send http request to read a collection") + sc.Config.log.Error(err, "Failed to send http request to read a collection") return nil, err } @@ -131,22 +130,22 @@ func (sc *SLClientV9) ReadCollection() (*Response, error) { } func (sc *SLClientV9) BackupCollection(ctx context.Context, collection string, backupName string, location string, repository string) (*Response, error) { - sc.Config.log.V(5).Info(fmt.Sprintf("BACKUP COLLECTION v11111111111111111: %s", collection)) + sc.Config.log.V(5).Info(fmt.Sprintf("BACKUP COLLECTION: %s", collection)) req := sc.Client.R().SetDoNotParseResponse(true).SetContext(ctx) req.SetHeader("Content-Type", "application/json") backupParams := map[string]string{ - "action": "BACKUP", - "name": backupName, - "collection": collection, - "location": location, - "repository": repository, - "async": fmt.Sprintf("%s-backup", collection), + Action: ActionBackup, + BackupName: backupName, + Collection: collection, + Location: location, + Repository: repository, + Async: fmt.Sprintf("%s-backup", collection), } req.SetQueryParams(backupParams) res, err := req.Post("/solr/admin/collections") if err != nil { - sc.log.Error(err, "Failed to send http request to backup a collection") + sc.Config.log.Error(err, "Failed to send http request to backup a collection") return nil, err } @@ -163,18 +162,19 @@ func (sc *SLClientV9) RestoreCollection(ctx context.Context, collection string, req := sc.Client.R().SetDoNotParseResponse(true).SetContext(ctx) req.SetHeader("Content-Type", "application/json") restoreParams := map[string]string{ - "action": "RESTORE", - "name": backupName, - "location": location, - "collection": collection, - "repository": repository, - "async": fmt.Sprintf("%s-restore", collection), + Action: ActionRestore, + BackupName: backupName, + Location: location, + Collection: collection, + Repository: repository, + BackupId: strconv.Itoa(backupId), + Async: fmt.Sprintf("%s-restore", collection), } req.SetQueryParams(restoreParams) res, err := req.Post("/solr/admin/collections") if err != nil { - sc.log.Error(err, "Failed to send http request to restore a collection") + sc.Config.log.Error(err, "Failed to send http request to restore a collection") return nil, err } @@ -193,7 +193,7 @@ func (sc *SLClientV9) FlushStatus(asyncId string) (*Response, error) { res, err := req.Delete(fmt.Sprintf("/api/cluster/command-status/%s", asyncId)) if err != nil { - sc.log.Error(err, "Failed to send http request to flush status") + sc.Config.log.Error(err, "Failed to send http request to flush status") return nil, err } @@ -211,7 +211,7 @@ func (sc *SLClientV9) RequestStatus(asyncId string) (*Response, error) { req.SetHeader("Content-Type", "application/json") res, err := req.Get(fmt.Sprintf("/api/cluster/command-status/%s", asyncId)) if err != nil { - sc.log.Error(err, "Failed to send http request to request status") + sc.Config.log.Error(err, "Failed to send http request to request status") return nil, err } backupResponse := &Response{ @@ -231,18 +231,18 @@ func (sc *SLClientV9) DeleteBackup(ctx context.Context, backupName string, colle async = fmt.Sprintf("%s-%s", async, snap) } params := map[string]string{ - "action": "DELETEBACKUP", - "name": backupName, - "location": location, - "repository": repository, - "backupId": strconv.Itoa(backupId), - "async": async, + Action: ActionDeleteBackup, + BackupName: backupName, + Location: location, + Repository: repository, + BackupId: strconv.Itoa(backupId), + Async: async, } req.SetQueryParams(params) res, err := req.Get("/solr/admin/collections") if err != nil { - sc.log.Error(err, "Failed to send http request to restore a collection") + sc.Config.log.Error(err, "Failed to send http request to restore a collection") return nil, err } @@ -263,18 +263,18 @@ func (sc *SLClientV9) PurgeBackup(ctx context.Context, backupName string, collec async = fmt.Sprintf("%s-%s", async, snap) } params := map[string]string{ - "action": "DELETEBACKUP", - "name": backupName, - "location": location, - "repository": repository, - "purgeUnused": "true", - "async": async, + Action: ActionDeleteBackup, + BackupName: backupName, + Location: location, + Repository: repository, + PurgeUnused: "true", + Async: async, } req.SetQueryParams(params) res, err := req.Get("/solr/admin/collections") if err != nil { - sc.log.Error(err, "Failed to send http request to restore a collection") + sc.Config.log.Error(err, "Failed to send http request to restore a collection") return nil, err } @@ -295,7 +295,7 @@ func (sc *SLClientV9) GetClient() *resty.Client { } func (sc *SLClientV9) GetLog() logr.Logger { - return sc.log + return sc.Config.log } func (sc *SLClientV9) DecodeBackupResponse(data map[string]interface{}, collection string) ([]byte, error) { From c18134a36495254226024a6234236e77eb239077 Mon Sep 17 00:00:00 2001 From: pritamdas99 Date: Wed, 17 Jul 2024 12:37:59 +0600 Subject: [PATCH 10/13] Update formatting go imports Signed-off-by: pritamdas99 --- solr/util.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/solr/util.go b/solr/util.go index aeed9523e..e5e69242d 100644 --- a/solr/util.go +++ b/solr/util.go @@ -2,11 +2,10 @@ package solr import ( "encoding/json" + "fmt" "io" "github.com/pkg/errors" - - "fmt" ) func (sc *Client) DecodeResponse(response *Response) (map[string]interface{}, error) { From fee8fa0ec8b4ceef6af89f49036f50ae179da2cb Mon Sep 17 00:00:00 2001 From: pritamdas99 Date: Wed, 17 Jul 2024 12:47:45 +0600 Subject: [PATCH 11/13] Update constants Signed-off-by: pritamdas99 --- solr/api.go | 5 ++++- solr/solrv8.go | 16 ++++++++-------- solr/solrv9.go | 8 ++++---- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/solr/api.go b/solr/api.go index 912fde342..2452c8ea0 100644 --- a/solr/api.go +++ b/solr/api.go @@ -12,8 +12,9 @@ const ( Action = "action" ActionBackup = "BACKUP" ActionRestore = "RESTORE" + ActionCreate = "CREATE" ActionDeleteBackup = "DELETEBACKUP" - BackupName = "name" + Name = "name" Location = "location" Repository = "repository" Collection = "collection" @@ -23,6 +24,8 @@ const ( DeleteStatus = "DELETESTATUS" RequestStatus = "REQUESTSTATUS" RequestId = "requestid" + NumShards = "numShards" + ReplicationFactor = "replicationFactor" ) type SLClient interface { diff --git a/solr/solrv8.go b/solr/solrv8.go index 346718290..59f69e9b5 100644 --- a/solr/solrv8.go +++ b/solr/solrv8.go @@ -56,10 +56,10 @@ func (sc *SLClientV8) CreateCollection() (*Response, error) { req := sc.Client.R().SetDoNotParseResponse(true) req.SetHeader("Content-Type", "application/json") params := map[string]string{ - "action": "CREATE", - "name": writeCollectionName, - "numShards": "1", - "replicationFactor": "1", + Action: ActionCreate, + Name: writeCollectionName, + NumShards: "1", + ReplicationFactor: "1", } req.SetQueryParams(params) @@ -131,7 +131,7 @@ func (sc *SLClientV8) BackupCollection(ctx context.Context, collection string, b req.SetHeader("Content-Type", "application/json") params := map[string]string{ Action: ActionBackup, - BackupName: backupName, + Name: backupName, Collection: collection, Location: location, Repository: repository, @@ -160,7 +160,7 @@ func (sc *SLClientV8) RestoreCollection(ctx context.Context, collection string, req.SetHeader("Content-Type", "application/json") params := map[string]string{ Action: ActionRestore, - BackupName: backupName, + Name: backupName, Location: location, Collection: collection, Repository: repository, @@ -240,7 +240,7 @@ func (sc *SLClientV8) DeleteBackup(ctx context.Context, backupName string, colle } params := map[string]string{ Action: ActionDeleteBackup, - BackupName: backupName, + Name: backupName, Location: location, Repository: repository, BackupId: strconv.Itoa(backupId), @@ -272,7 +272,7 @@ func (sc *SLClientV8) PurgeBackup(ctx context.Context, backupName string, collec } params := map[string]string{ Action: ActionDeleteBackup, - BackupName: backupName, + Name: backupName, Location: location, Repository: repository, PurgeUnused: "true", diff --git a/solr/solrv9.go b/solr/solrv9.go index b8d75107d..2badd2260 100644 --- a/solr/solrv9.go +++ b/solr/solrv9.go @@ -135,7 +135,7 @@ func (sc *SLClientV9) BackupCollection(ctx context.Context, collection string, b req.SetHeader("Content-Type", "application/json") backupParams := map[string]string{ Action: ActionBackup, - BackupName: backupName, + Name: backupName, Collection: collection, Location: location, Repository: repository, @@ -163,7 +163,7 @@ func (sc *SLClientV9) RestoreCollection(ctx context.Context, collection string, req.SetHeader("Content-Type", "application/json") restoreParams := map[string]string{ Action: ActionRestore, - BackupName: backupName, + Name: backupName, Location: location, Collection: collection, Repository: repository, @@ -232,7 +232,7 @@ func (sc *SLClientV9) DeleteBackup(ctx context.Context, backupName string, colle } params := map[string]string{ Action: ActionDeleteBackup, - BackupName: backupName, + Name: backupName, Location: location, Repository: repository, BackupId: strconv.Itoa(backupId), @@ -264,7 +264,7 @@ func (sc *SLClientV9) PurgeBackup(ctx context.Context, backupName string, collec } params := map[string]string{ Action: ActionDeleteBackup, - BackupName: backupName, + Name: backupName, Location: location, Repository: repository, PurgeUnused: "true", From cbb2afe16dd4a2079377fa1d34fb54f6077eb40d Mon Sep 17 00:00:00 2001 From: pritamdas99 Date: Wed, 17 Jul 2024 13:15:50 +0600 Subject: [PATCH 12/13] Update client Signed-off-by: pritamdas99 --- solr/kubedb_client_builder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solr/kubedb_client_builder.go b/solr/kubedb_client_builder.go index b208d1663..f4df93688 100644 --- a/solr/kubedb_client_builder.go +++ b/solr/kubedb_client_builder.go @@ -100,7 +100,7 @@ func (o *KubeDBClientBuilder) GetSolrClient() (*Client, error) { } switch { - case version.Major() == 9: + case version.Major() >= 9: newClient := resty.New() newClient.SetScheme(config.connectionScheme).SetBaseURL(config.host).SetTransport(config.transport) newClient.SetTimeout(time.Second * 30) From 0b7b7ad94c4cc5f6bda04b307efd7b0f0a48ec62 Mon Sep 17 00:00:00 2001 From: pritamdas99 Date: Wed, 17 Jul 2024 14:32:59 +0600 Subject: [PATCH 13/13] Update go mod dependency Signed-off-by: pritamdas99 --- go.mod | 10 +- go.sum | 20 +- vendor/golang.org/x/crypto/md4/md4.go | 2 +- vendor/golang.org/x/crypto/ocsp/ocsp.go | 2 +- vendor/golang.org/x/crypto/pbkdf2/pbkdf2.go | 2 +- vendor/golang.org/x/crypto/scrypt/scrypt.go | 2 +- vendor/golang.org/x/net/http2/transport.go | 4 - vendor/golang.org/x/sys/unix/mremap.go | 5 + .../golang.org/x/sys/unix/syscall_darwin.go | 12 + vendor/golang.org/x/sys/unix/syscall_unix.go | 9 + .../x/sys/unix/zsyscall_darwin_amd64.go | 33 +++ .../x/sys/unix/zsyscall_darwin_amd64.s | 10 + .../x/sys/unix/zsyscall_darwin_arm64.go | 33 +++ .../x/sys/unix/zsyscall_darwin_arm64.s | 10 + .../x/sys/windows/security_windows.go | 24 +- .../x/sys/windows/zsyscall_windows.go | 9 + .../apimachinery/apis/kubedb/constants.go | 4 + .../apis/kubedb/v1alpha2/conversion.go | 24 +- .../apis/kubedb/v1alpha2/etcd_helpers.go | 4 +- .../apis/kubedb/v1alpha2/etcd_types.go | 4 +- .../apis/kubedb/v1alpha2/openapi_generated.go | 4 +- .../apimachinery/crds/kubedb.com_etcds.yaml | 14 +- .../crds/ops.kubedb.com_solropsrequests.yaml | 223 ++++++++++++++++++ vendor/modules.txt | 12 +- 24 files changed, 423 insertions(+), 53 deletions(-) diff --git a/go.mod b/go.mod index 97306cdbc..5fa35c7de 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( k8s.io/klog/v2 v2.130.1 kmodules.xyz/client-go v0.30.9 kmodules.xyz/custom-resources v0.30.0 - kubedb.dev/apimachinery v0.47.0-rc.1 + kubedb.dev/apimachinery v0.47.0-rc.1.0.20240717082707-f8438b7e77c7 sigs.k8s.io/controller-runtime v0.18.4 xorm.io/xorm v1.3.6 ) @@ -111,13 +111,13 @@ require ( github.com/zeebo/xxh3 v1.0.2 // indirect go.opentelemetry.io/otel v1.26.0 // indirect go.opentelemetry.io/otel/trace v1.26.0 // indirect - golang.org/x/crypto v0.24.0 // indirect + golang.org/x/crypto v0.25.0 // indirect golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect - golang.org/x/net v0.26.0 // indirect + golang.org/x/net v0.27.0 // indirect golang.org/x/oauth2 v0.21.0 // indirect golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.21.0 // indirect - golang.org/x/term v0.21.0 // indirect + golang.org/x/sys v0.22.0 // indirect + golang.org/x/term v0.22.0 // indirect golang.org/x/text v0.16.0 // indirect golang.org/x/time v0.5.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 8e5f9bbb2..6a463db84 100644 --- a/go.sum +++ b/go.sum @@ -522,8 +522,8 @@ golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIi golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= -golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= -golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= +golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM= golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= @@ -573,8 +573,8 @@ golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= -golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= +golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -631,8 +631,8 @@ golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -647,8 +647,8 @@ golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= -golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= -golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= +golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= +golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -773,8 +773,8 @@ kmodules.xyz/monitoring-agent-api v0.29.0 h1:gpFl6OZrlMLb/ySMHdREI9EwGtnJ91oZBn9 kmodules.xyz/monitoring-agent-api v0.29.0/go.mod h1:iNbvaMTgVFOI5q2LJtGK91j4Dmjv4ZRiRdasGmWLKQI= kmodules.xyz/offshoot-api v0.30.0 h1:dq9F93pu4Q8rL9oTcCk+vGGy8vpS7RNt0GSwx7Bvhec= kmodules.xyz/offshoot-api v0.30.0/go.mod h1:o9VoA3ImZMDBp3lpLb8+kc2d/KBxioRwCpaKDfLIyDw= -kubedb.dev/apimachinery v0.47.0-rc.1 h1:5DXoahPbJ1n1Fowa+lv3xobTWRLzDDKGhJaNiWjV/tk= -kubedb.dev/apimachinery v0.47.0-rc.1/go.mod h1:AUV5sXVwo77ctiYyrFWsSrhkuvy5fru5baiX7xF6LBA= +kubedb.dev/apimachinery v0.47.0-rc.1.0.20240717082707-f8438b7e77c7 h1:HqdKBHKbi5fhHRHstoDggFXpX6v7r+2P8/XevDdHjeg= +kubedb.dev/apimachinery v0.47.0-rc.1.0.20240717082707-f8438b7e77c7/go.mod h1:Gs/kwdVYmGjJmYmvCUNDmNbbprXqi/gbSj/JrsoM9sE= kubeops.dev/petset v0.0.6 h1:0IbvxD9fadZfH+3iMZWzN6ZHsO0vX458JlioamwyPKQ= kubeops.dev/petset v0.0.6/go.mod h1:A15vh0r979NsvL65DTIZKWsa/NoX9VapHBAEw1ZsdYI= lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk= diff --git a/vendor/golang.org/x/crypto/md4/md4.go b/vendor/golang.org/x/crypto/md4/md4.go index d1911c2e8..7d9281e02 100644 --- a/vendor/golang.org/x/crypto/md4/md4.go +++ b/vendor/golang.org/x/crypto/md4/md4.go @@ -7,7 +7,7 @@ // Deprecated: MD4 is cryptographically broken and should only be used // where compatibility with legacy systems, not security, is the goal. Instead, // use a secure hash like SHA-256 (from crypto/sha256). -package md4 // import "golang.org/x/crypto/md4" +package md4 import ( "crypto" diff --git a/vendor/golang.org/x/crypto/ocsp/ocsp.go b/vendor/golang.org/x/crypto/ocsp/ocsp.go index bf2259537..e6c645e7c 100644 --- a/vendor/golang.org/x/crypto/ocsp/ocsp.go +++ b/vendor/golang.org/x/crypto/ocsp/ocsp.go @@ -5,7 +5,7 @@ // Package ocsp parses OCSP responses as specified in RFC 2560. OCSP responses // are signed messages attesting to the validity of a certificate for a small // period of time. This is used to manage revocation for X.509 certificates. -package ocsp // import "golang.org/x/crypto/ocsp" +package ocsp import ( "crypto" diff --git a/vendor/golang.org/x/crypto/pbkdf2/pbkdf2.go b/vendor/golang.org/x/crypto/pbkdf2/pbkdf2.go index 904b57e01..28cd99c7f 100644 --- a/vendor/golang.org/x/crypto/pbkdf2/pbkdf2.go +++ b/vendor/golang.org/x/crypto/pbkdf2/pbkdf2.go @@ -16,7 +16,7 @@ Hash Functions SHA-1, SHA-224, SHA-256, SHA-384 and SHA-512 for HMAC. To choose, you can pass the `New` functions from the different SHA packages to pbkdf2.Key. */ -package pbkdf2 // import "golang.org/x/crypto/pbkdf2" +package pbkdf2 import ( "crypto/hmac" diff --git a/vendor/golang.org/x/crypto/scrypt/scrypt.go b/vendor/golang.org/x/crypto/scrypt/scrypt.go index c971a99fa..76fa40fb2 100644 --- a/vendor/golang.org/x/crypto/scrypt/scrypt.go +++ b/vendor/golang.org/x/crypto/scrypt/scrypt.go @@ -5,7 +5,7 @@ // Package scrypt implements the scrypt key derivation function as defined in // Colin Percival's paper "Stronger Key Derivation via Sequential Memory-Hard // Functions" (https://www.tarsnap.com/scrypt/scrypt.pdf). -package scrypt // import "golang.org/x/crypto/scrypt" +package scrypt import ( "crypto/sha256" diff --git a/vendor/golang.org/x/net/http2/transport.go b/vendor/golang.org/x/net/http2/transport.go index 98a49c6b6..61f511f97 100644 --- a/vendor/golang.org/x/net/http2/transport.go +++ b/vendor/golang.org/x/net/http2/transport.go @@ -827,10 +827,6 @@ func (t *Transport) newClientConn(c net.Conn, singleUse bool) (*ClientConn, erro cc.henc.SetMaxDynamicTableSizeLimit(t.maxEncoderHeaderTableSize()) cc.peerMaxHeaderTableSize = initialHeaderTableSize - if t.AllowHTTP { - cc.nextStreamID = 3 - } - if cs, ok := c.(connectionStater); ok { state := cs.ConnectionState() cc.tlsState = &state diff --git a/vendor/golang.org/x/sys/unix/mremap.go b/vendor/golang.org/x/sys/unix/mremap.go index fd45fe529..3a5e776f8 100644 --- a/vendor/golang.org/x/sys/unix/mremap.go +++ b/vendor/golang.org/x/sys/unix/mremap.go @@ -50,3 +50,8 @@ func (m *mremapMmapper) Mremap(oldData []byte, newLength int, flags int) (data [ func Mremap(oldData []byte, newLength int, flags int) (data []byte, err error) { return mapper.Mremap(oldData, newLength, flags) } + +func MremapPtr(oldAddr unsafe.Pointer, oldSize uintptr, newAddr unsafe.Pointer, newSize uintptr, flags int) (ret unsafe.Pointer, err error) { + xaddr, err := mapper.mremap(uintptr(oldAddr), oldSize, newSize, flags, uintptr(newAddr)) + return unsafe.Pointer(xaddr), err +} diff --git a/vendor/golang.org/x/sys/unix/syscall_darwin.go b/vendor/golang.org/x/sys/unix/syscall_darwin.go index 59542a897..4cc7b0059 100644 --- a/vendor/golang.org/x/sys/unix/syscall_darwin.go +++ b/vendor/golang.org/x/sys/unix/syscall_darwin.go @@ -542,6 +542,18 @@ func SysctlKinfoProcSlice(name string, args ...int) ([]KinfoProc, error) { } } +//sys pthread_chdir_np(path string) (err error) + +func PthreadChdir(path string) (err error) { + return pthread_chdir_np(path) +} + +//sys pthread_fchdir_np(fd int) (err error) + +func PthreadFchdir(fd int) (err error) { + return pthread_fchdir_np(fd) +} + //sys sendfile(infd int, outfd int, offset int64, len *int64, hdtr unsafe.Pointer, flags int) (err error) //sys shmat(id int, addr uintptr, flag int) (ret uintptr, err error) diff --git a/vendor/golang.org/x/sys/unix/syscall_unix.go b/vendor/golang.org/x/sys/unix/syscall_unix.go index 77081de8c..4e92e5aa4 100644 --- a/vendor/golang.org/x/sys/unix/syscall_unix.go +++ b/vendor/golang.org/x/sys/unix/syscall_unix.go @@ -154,6 +154,15 @@ func Munmap(b []byte) (err error) { return mapper.Munmap(b) } +func MmapPtr(fd int, offset int64, addr unsafe.Pointer, length uintptr, prot int, flags int) (ret unsafe.Pointer, err error) { + xaddr, err := mapper.mmap(uintptr(addr), length, prot, flags, fd, offset) + return unsafe.Pointer(xaddr), err +} + +func MunmapPtr(addr unsafe.Pointer, length uintptr) (err error) { + return mapper.munmap(uintptr(addr), length) +} + func Read(fd int, p []byte) (n int, err error) { n, err = read(fd, p) if raceenabled { diff --git a/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go b/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go index ccb02f240..07642c308 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go @@ -760,6 +760,39 @@ var libc_sysctl_trampoline_addr uintptr // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func pthread_chdir_np(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := syscall_syscall(libc_pthread_chdir_np_trampoline_addr, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +var libc_pthread_chdir_np_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_pthread_chdir_np pthread_chdir_np "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func pthread_fchdir_np(fd int) (err error) { + _, _, e1 := syscall_syscall(libc_pthread_fchdir_np_trampoline_addr, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +var libc_pthread_fchdir_np_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_pthread_fchdir_np pthread_fchdir_np "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func sendfile(infd int, outfd int, offset int64, len *int64, hdtr unsafe.Pointer, flags int) (err error) { _, _, e1 := syscall_syscall6(libc_sendfile_trampoline_addr, uintptr(infd), uintptr(outfd), uintptr(offset), uintptr(unsafe.Pointer(len)), uintptr(hdtr), uintptr(flags)) if e1 != 0 { diff --git a/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.s b/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.s index 8b8bb2840..923e08cb7 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.s +++ b/vendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.s @@ -228,6 +228,16 @@ TEXT libc_sysctl_trampoline<>(SB),NOSPLIT,$0-0 GLOBL ·libc_sysctl_trampoline_addr(SB), RODATA, $8 DATA ·libc_sysctl_trampoline_addr(SB)/8, $libc_sysctl_trampoline<>(SB) +TEXT libc_pthread_chdir_np_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_pthread_chdir_np(SB) +GLOBL ·libc_pthread_chdir_np_trampoline_addr(SB), RODATA, $8 +DATA ·libc_pthread_chdir_np_trampoline_addr(SB)/8, $libc_pthread_chdir_np_trampoline<>(SB) + +TEXT libc_pthread_fchdir_np_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_pthread_fchdir_np(SB) +GLOBL ·libc_pthread_fchdir_np_trampoline_addr(SB), RODATA, $8 +DATA ·libc_pthread_fchdir_np_trampoline_addr(SB)/8, $libc_pthread_fchdir_np_trampoline<>(SB) + TEXT libc_sendfile_trampoline<>(SB),NOSPLIT,$0-0 JMP libc_sendfile(SB) GLOBL ·libc_sendfile_trampoline_addr(SB), RODATA, $8 diff --git a/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go b/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go index 1b40b997b..7d73dda64 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go @@ -760,6 +760,39 @@ var libc_sysctl_trampoline_addr uintptr // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func pthread_chdir_np(path string) (err error) { + var _p0 *byte + _p0, err = BytePtrFromString(path) + if err != nil { + return + } + _, _, e1 := syscall_syscall(libc_pthread_chdir_np_trampoline_addr, uintptr(unsafe.Pointer(_p0)), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +var libc_pthread_chdir_np_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_pthread_chdir_np pthread_chdir_np "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func pthread_fchdir_np(fd int) (err error) { + _, _, e1 := syscall_syscall(libc_pthread_fchdir_np_trampoline_addr, uintptr(fd), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +var libc_pthread_fchdir_np_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_pthread_fchdir_np pthread_fchdir_np "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func sendfile(infd int, outfd int, offset int64, len *int64, hdtr unsafe.Pointer, flags int) (err error) { _, _, e1 := syscall_syscall6(libc_sendfile_trampoline_addr, uintptr(infd), uintptr(outfd), uintptr(offset), uintptr(unsafe.Pointer(len)), uintptr(hdtr), uintptr(flags)) if e1 != 0 { diff --git a/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.s b/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.s index 08362c1ab..057700111 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.s +++ b/vendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.s @@ -228,6 +228,16 @@ TEXT libc_sysctl_trampoline<>(SB),NOSPLIT,$0-0 GLOBL ·libc_sysctl_trampoline_addr(SB), RODATA, $8 DATA ·libc_sysctl_trampoline_addr(SB)/8, $libc_sysctl_trampoline<>(SB) +TEXT libc_pthread_chdir_np_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_pthread_chdir_np(SB) +GLOBL ·libc_pthread_chdir_np_trampoline_addr(SB), RODATA, $8 +DATA ·libc_pthread_chdir_np_trampoline_addr(SB)/8, $libc_pthread_chdir_np_trampoline<>(SB) + +TEXT libc_pthread_fchdir_np_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_pthread_fchdir_np(SB) +GLOBL ·libc_pthread_fchdir_np_trampoline_addr(SB), RODATA, $8 +DATA ·libc_pthread_fchdir_np_trampoline_addr(SB)/8, $libc_pthread_fchdir_np_trampoline<>(SB) + TEXT libc_sendfile_trampoline<>(SB),NOSPLIT,$0-0 JMP libc_sendfile(SB) GLOBL ·libc_sendfile_trampoline_addr(SB), RODATA, $8 diff --git a/vendor/golang.org/x/sys/windows/security_windows.go b/vendor/golang.org/x/sys/windows/security_windows.go index 6f7d2ac70..97651b5bd 100644 --- a/vendor/golang.org/x/sys/windows/security_windows.go +++ b/vendor/golang.org/x/sys/windows/security_windows.go @@ -894,7 +894,7 @@ type ACL struct { aclRevision byte sbz1 byte aclSize uint16 - aceCount uint16 + AceCount uint16 sbz2 uint16 } @@ -1087,6 +1087,27 @@ type EXPLICIT_ACCESS struct { Trustee TRUSTEE } +// https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-ace_header +type ACE_HEADER struct { + AceType uint8 + AceFlags uint8 + AceSize uint16 +} + +// https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-access_allowed_ace +type ACCESS_ALLOWED_ACE struct { + Header ACE_HEADER + Mask ACCESS_MASK + SidStart uint32 +} + +const ( + // Constants for AceType + // https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-ace_header + ACCESS_ALLOWED_ACE_TYPE = 0 + ACCESS_DENIED_ACE_TYPE = 1 +) + // This type is the union inside of TRUSTEE and must be created using one of the TrusteeValueFrom* functions. type TrusteeValue uintptr @@ -1158,6 +1179,7 @@ type OBJECTS_AND_NAME struct { //sys makeSelfRelativeSD(absoluteSD *SECURITY_DESCRIPTOR, selfRelativeSD *SECURITY_DESCRIPTOR, selfRelativeSDSize *uint32) (err error) = advapi32.MakeSelfRelativeSD //sys setEntriesInAcl(countExplicitEntries uint32, explicitEntries *EXPLICIT_ACCESS, oldACL *ACL, newACL **ACL) (ret error) = advapi32.SetEntriesInAclW +//sys GetAce(acl *ACL, aceIndex uint32, pAce **ACCESS_ALLOWED_ACE) (ret error) = advapi32.GetAce // Control returns the security descriptor control bits. func (sd *SECURITY_DESCRIPTOR) Control() (control SECURITY_DESCRIPTOR_CONTROL, revision uint32, err error) { diff --git a/vendor/golang.org/x/sys/windows/zsyscall_windows.go b/vendor/golang.org/x/sys/windows/zsyscall_windows.go index 9f73df75b..eba761018 100644 --- a/vendor/golang.org/x/sys/windows/zsyscall_windows.go +++ b/vendor/golang.org/x/sys/windows/zsyscall_windows.go @@ -91,6 +91,7 @@ var ( procEnumServicesStatusExW = modadvapi32.NewProc("EnumServicesStatusExW") procEqualSid = modadvapi32.NewProc("EqualSid") procFreeSid = modadvapi32.NewProc("FreeSid") + procGetAce = modadvapi32.NewProc("GetAce") procGetLengthSid = modadvapi32.NewProc("GetLengthSid") procGetNamedSecurityInfoW = modadvapi32.NewProc("GetNamedSecurityInfoW") procGetSecurityDescriptorControl = modadvapi32.NewProc("GetSecurityDescriptorControl") @@ -1224,6 +1225,14 @@ func setEntriesInAcl(countExplicitEntries uint32, explicitEntries *EXPLICIT_ACCE return } +func GetAce(acl *ACL, aceIndex uint32, pAce **ACCESS_ALLOWED_ACE) (ret error) { + r0, _, _ := syscall.Syscall(procGetAce.Addr(), 3, uintptr(unsafe.Pointer(acl)), uintptr(aceIndex), uintptr(unsafe.Pointer(pAce))) + if r0 == 0 { + ret = GetLastError() + } + return +} + func SetKernelObjectSecurity(handle Handle, securityInformation SECURITY_INFORMATION, securityDescriptor *SECURITY_DESCRIPTOR) (err error) { r1, _, e1 := syscall.Syscall(procSetKernelObjectSecurity.Addr(), 3, uintptr(handle), uintptr(securityInformation), uintptr(unsafe.Pointer(securityDescriptor))) if r1 == 0 { diff --git a/vendor/kubedb.dev/apimachinery/apis/kubedb/constants.go b/vendor/kubedb.dev/apimachinery/apis/kubedb/constants.go index 78a28e577..16eb693ec 100644 --- a/vendor/kubedb.dev/apimachinery/apis/kubedb/constants.go +++ b/vendor/kubedb.dev/apimachinery/apis/kubedb/constants.go @@ -689,6 +689,10 @@ const ( DatabaseWriteAccess = "DatabaseWriteAccess" // check dependencies are ready DatabaseDependencyReady = "DatabaseDependencyReady" + // update config secret for backup in solr + PatchConfigSecretUpdateForBackup = "PatchConfigSecretUpdatesForBackup" + // sync db to update configuration + SyncDatabaseForConfigurationUpdate = "SyncDatabaseForConfigurationUpdate" // Condition reasons DataRestoreStartedByExternalInitializer = "DataRestoreStartedByExternalInitializer" diff --git a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/conversion.go b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/conversion.go index cbe892276..fd347d990 100644 --- a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/conversion.go +++ b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/conversion.go @@ -662,11 +662,13 @@ func Convert_v1alpha2_RedisSpec_To_v1_RedisSpec(in *RedisSpec, out *v1.RedisSpec return err } - if out.Cluster == nil { - out.Cluster = &v1.RedisClusterSpec{} - } - if err := Convert_v1alpha2_RedisClusterSpec_To_v1_RedisClusterSpec(in.Cluster, out.Cluster, s); err != nil { - return err + if in.Mode == RedisModeCluster { + if out.Cluster == nil { + out.Cluster = &v1.RedisClusterSpec{} + } + if err := Convert_v1alpha2_RedisClusterSpec_To_v1_RedisClusterSpec(in.Cluster, out.Cluster, s); err != nil { + return err + } } out.Version = in.Version @@ -730,11 +732,13 @@ func Convert_v1_RedisSpec_To_v1alpha2_RedisSpec(in *v1.RedisSpec, out *RedisSpec return err } - if out.Cluster == nil { - out.Cluster = &RedisClusterSpec{} - } - if err := Convert_v1_RedisClusterSpec_To_v1alpha2_RedisClusterSpec(in.Cluster, out.Cluster, s); err != nil { - return err + if in.Mode == v1.RedisModeCluster { + if out.Cluster == nil { + out.Cluster = &RedisClusterSpec{} + } + if err := Convert_v1_RedisClusterSpec_To_v1alpha2_RedisClusterSpec(in.Cluster, out.Cluster, s); err != nil { + return err + } } out.Version = in.Version diff --git a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/etcd_helpers.go b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/etcd_helpers.go index 60f3bb472..d0708704c 100644 --- a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/etcd_helpers.go +++ b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/etcd_helpers.go @@ -181,8 +181,8 @@ func (e *Etcd) SetDefaults() { if e.Spec.StorageType == "" { e.Spec.StorageType = StorageTypeDurable } - if e.Spec.TerminationPolicy == "" { - e.Spec.TerminationPolicy = TerminationPolicyDelete + if e.Spec.DeletionPolicy == "" { + e.Spec.DeletionPolicy = TerminationPolicyDelete } e.Spec.Monitor.SetDefaults() diff --git a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/etcd_types.go b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/etcd_types.go index caa57e978..cbf151b15 100644 --- a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/etcd_types.go +++ b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/etcd_types.go @@ -90,9 +90,9 @@ type EtcdSpec struct { // +optional Halted bool `json:"halted,omitempty"` - // TerminationPolicy controls the delete operation for database + // DeletionPolicy controls the delete operation for database // +optional - TerminationPolicy TerminationPolicy `json:"terminationPolicy,omitempty"` + DeletionPolicy TerminationPolicy `json:"deletionPolicy,omitempty"` } type TLSPolicy struct { diff --git a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/openapi_generated.go b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/openapi_generated.go index f0cb1d2f0..bb77c0167 100644 --- a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/openapi_generated.go +++ b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/openapi_generated.go @@ -27409,9 +27409,9 @@ func schema_apimachinery_apis_kubedb_v1alpha2_EtcdSpec(ref common.ReferenceCallb Format: "", }, }, - "terminationPolicy": { + "deletionPolicy": { SchemaProps: spec.SchemaProps{ - Description: "TerminationPolicy controls the delete operation for database", + Description: "DeletionPolicy controls the delete operation for database", Type: []string{"string"}, Format: "", }, diff --git a/vendor/kubedb.dev/apimachinery/crds/kubedb.com_etcds.yaml b/vendor/kubedb.dev/apimachinery/crds/kubedb.com_etcds.yaml index 2f93dee89..55f5741d0 100644 --- a/vendor/kubedb.dev/apimachinery/crds/kubedb.com_etcds.yaml +++ b/vendor/kubedb.dev/apimachinery/crds/kubedb.com_etcds.yaml @@ -57,6 +57,13 @@ spec: type: string type: object x-kubernetes-map-type: atomic + deletionPolicy: + enum: + - Halt + - Delete + - WipeOut + - DoNotTerminate + type: string halted: type: boolean init: @@ -4064,13 +4071,6 @@ spec: - Durable - Ephemeral type: string - terminationPolicy: - enum: - - Halt - - Delete - - WipeOut - - DoNotTerminate - type: string tls: properties: member: diff --git a/vendor/kubedb.dev/apimachinery/crds/ops.kubedb.com_solropsrequests.yaml b/vendor/kubedb.dev/apimachinery/crds/ops.kubedb.com_solropsrequests.yaml index 0a67ea29d..71b048e34 100644 --- a/vendor/kubedb.dev/apimachinery/crds/ops.kubedb.com_solropsrequests.yaml +++ b/vendor/kubedb.dev/apimachinery/crds/ops.kubedb.com_solropsrequests.yaml @@ -61,8 +61,231 @@ spec: type: string type: enum: + - VerticalScaling + - VolumeExpansion - Restart type: string + verticalScaling: + properties: + coordinator: + properties: + nodeSelectionPolicy: + type: string + resources: + properties: + claims: + items: + properties: + name: + type: string + required: + - name + type: object + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map + limits: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + requests: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + type: object + topology: + properties: + key: + type: string + value: + type: string + required: + - key + - value + type: object + type: object + data: + properties: + nodeSelectionPolicy: + type: string + resources: + properties: + claims: + items: + properties: + name: + type: string + required: + - name + type: object + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map + limits: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + requests: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + type: object + topology: + properties: + key: + type: string + value: + type: string + required: + - key + - value + type: object + type: object + node: + properties: + nodeSelectionPolicy: + type: string + resources: + properties: + claims: + items: + properties: + name: + type: string + required: + - name + type: object + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map + limits: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + requests: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + type: object + topology: + properties: + key: + type: string + value: + type: string + required: + - key + - value + type: object + type: object + overseer: + properties: + nodeSelectionPolicy: + type: string + resources: + properties: + claims: + items: + properties: + name: + type: string + required: + - name + type: object + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map + limits: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + requests: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + type: object + topology: + properties: + key: + type: string + value: + type: string + required: + - key + - value + type: object + type: object + type: object + volumeExpansion: + properties: + coordinator: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + data: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + mode: + enum: + - Offline + - Online + type: string + node: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + overseer: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + required: + - mode + type: object required: - databaseRef - type diff --git a/vendor/modules.txt b/vendor/modules.txt index ace83c2f1..9890d853e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1072,8 +1072,8 @@ go.opentelemetry.io/otel/internal/attribute ## explicit; go 1.21 go.opentelemetry.io/otel/trace go.opentelemetry.io/otel/trace/embedded -# golang.org/x/crypto v0.24.0 -## explicit; go 1.18 +# golang.org/x/crypto v0.25.0 +## explicit; go 1.20 golang.org/x/crypto/md4 golang.org/x/crypto/ocsp golang.org/x/crypto/pbkdf2 @@ -1081,7 +1081,7 @@ golang.org/x/crypto/scrypt # golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 ## explicit; go 1.20 golang.org/x/exp/maps -# golang.org/x/net v0.26.0 +# golang.org/x/net v0.27.0 ## explicit; go 1.18 golang.org/x/net/http/httpguts golang.org/x/net/http2 @@ -1098,13 +1098,13 @@ golang.org/x/oauth2/internal ## explicit; go 1.18 golang.org/x/sync/errgroup golang.org/x/sync/singleflight -# golang.org/x/sys v0.21.0 +# golang.org/x/sys v0.22.0 ## explicit; go 1.18 golang.org/x/sys/cpu golang.org/x/sys/plan9 golang.org/x/sys/unix golang.org/x/sys/windows -# golang.org/x/term v0.21.0 +# golang.org/x/term v0.22.0 ## explicit; go 1.18 golang.org/x/term # golang.org/x/text v0.16.0 @@ -1513,7 +1513,7 @@ kmodules.xyz/offshoot-api/api/v1 kmodules.xyz/offshoot-api/api/v1/conversion kmodules.xyz/offshoot-api/api/v2 kmodules.xyz/offshoot-api/util -# kubedb.dev/apimachinery v0.47.0-rc.1 +# kubedb.dev/apimachinery v0.47.0-rc.1.0.20240717082707-f8438b7e77c7 ## explicit; go 1.22.1 kubedb.dev/apimachinery/apis kubedb.dev/apimachinery/apis/catalog