Skip to content

Commit

Permalink
Add v1 api to db clients (#119)
Browse files Browse the repository at this point in the history
Signed-off-by: Neaj Morshad <[email protected]>
Signed-off-by: SK Ali Arman <[email protected]>
Signed-off-by: raihankhan <[email protected]>
Signed-off-by: souravbiswassanto <[email protected]>
Signed-off-by: obaydullahmhs <[email protected]>
Signed-off-by: Arnob kumar saha <[email protected]>
Co-authored-by: Neaj Morshad <[email protected]>
Co-authored-by: SK Ali Arman <[email protected]>
Co-authored-by: raihankhan <[email protected]>
Co-authored-by: Abu Sayed <[email protected]>
Co-authored-by: obaydullahmhs <[email protected]>
Co-authored-by: Arnob kumar saha <[email protected]>
  • Loading branch information
7 people authored Jul 3, 2024
1 parent cb56ea2 commit 3b94bb3
Show file tree
Hide file tree
Showing 390 changed files with 176,723 additions and 14,052 deletions.
16 changes: 16 additions & 0 deletions clickhouse/client.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright AppsCode Inc. and Contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package clickhouse

import (
Expand Down
22 changes: 19 additions & 3 deletions clickhouse/kubedb_client_builder.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
/*
Copyright AppsCode Inc. and Contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package clickhouse

import (
"context"
"database/sql"
"fmt"

api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
olddbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"

_ "github.com/ClickHouse/clickhouse-go/v2"
core "k8s.io/api/core/v1"
Expand All @@ -15,14 +31,14 @@ import (

type KubeDBClientBuilder struct {
kc client.Client
db *api.ClickHouse
db *olddbapi.ClickHouse
url string
podName string
port *int
ctx context.Context
}

func NewKubeDBClientBuilder(kc client.Client, db *api.ClickHouse) *KubeDBClientBuilder {
func NewKubeDBClientBuilder(kc client.Client, db *olddbapi.ClickHouse) *KubeDBClientBuilder {
return &KubeDBClientBuilder{
kc: kc,
db: db,
Expand Down
6 changes: 3 additions & 3 deletions elasticsearch/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package elasticsearch
import (
"context"

api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"

core "k8s.io/api/core/v1"
)
Expand Down Expand Up @@ -86,8 +86,8 @@ type ESClient interface {
CreateIndex(index string) error
DeleteIndex(index string) error
GetIndicesInfo() ([]interface{}, error)
GetClusterWriteStatus(ctx context.Context, db *api.Elasticsearch) error
GetClusterReadStatus(ctx context.Context, db *api.Elasticsearch) error
GetClusterWriteStatus(ctx context.Context, db *dbapi.Elasticsearch) error
GetClusterReadStatus(ctx context.Context, db *dbapi.Elasticsearch) error
GetTotalDiskUsage(ctx context.Context) (string, error)
GetDBUserRole(ctx context.Context) (error, bool)
IndexExistsOrNot(index string) error
Expand Down
6 changes: 3 additions & 3 deletions elasticsearch/es_client_v5.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"encoding/json"

api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"

esv5 "github.com/elastic/go-elasticsearch/v5"
"github.com/pkg/errors"
Expand Down Expand Up @@ -77,11 +77,11 @@ func (es *ESClientV5) SyncCredentialFromSecret(secret *core.Secret) error {
return nil
}

func (es *ESClientV5) GetClusterWriteStatus(ctx context.Context, db *api.Elasticsearch) error {
func (es *ESClientV5) GetClusterWriteStatus(ctx context.Context, db *dbapi.Elasticsearch) error {
return nil
}

func (es *ESClientV5) GetClusterReadStatus(ctx context.Context, db *api.Elasticsearch) error {
func (es *ESClientV5) GetClusterReadStatus(ctx context.Context, db *dbapi.Elasticsearch) error {
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions elasticsearch/es_client_v6.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"net/http"
"strings"

api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"

esv6 "github.com/elastic/go-elasticsearch/v6"
"github.com/elastic/go-elasticsearch/v6/esapi"
Expand Down Expand Up @@ -113,7 +113,7 @@ func (es *ESClientV6) SyncCredentialFromSecret(secret *core.Secret) error {
return nil
}

func (es *ESClientV6) GetClusterWriteStatus(ctx context.Context, db *api.Elasticsearch) error {
func (es *ESClientV6) GetClusterWriteStatus(ctx context.Context, db *dbapi.Elasticsearch) error {
// Build the request index & request body
// send the db specs as body
indexBody := WriteRequestIndexBody{
Expand Down Expand Up @@ -179,7 +179,7 @@ func (es *ESClientV6) GetClusterWriteStatus(ctx context.Context, db *api.Elastic
return errors.New("Failed to parse key `errors` in response from write request")
}

func (es *ESClientV6) GetClusterReadStatus(ctx context.Context, db *api.Elasticsearch) error {
func (es *ESClientV6) GetClusterReadStatus(ctx context.Context, db *dbapi.Elasticsearch) error {
// Perform a read request in writeRequestIndex/writeRequestID (kubedb-system/info) API
// Handle error specifically if index has not been created yet
res, err := esapi.GetRequest{
Expand Down
6 changes: 3 additions & 3 deletions elasticsearch/es_client_v7.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"net/http"
"strings"

api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"

esv7 "github.com/elastic/go-elasticsearch/v7"
"github.com/elastic/go-elasticsearch/v7/esapi"
Expand Down Expand Up @@ -175,7 +175,7 @@ func (es *ESClientV7) SyncCredentialFromSecret(secret *core.Secret) error {
return errors.New("CredSyncFailed")
}

func (es *ESClientV7) GetClusterWriteStatus(ctx context.Context, db *api.Elasticsearch) error {
func (es *ESClientV7) GetClusterWriteStatus(ctx context.Context, db *dbapi.Elasticsearch) error {
// Build the request index & request body
// send the db specs as body
indexBody := WriteRequestIndexBody{
Expand Down Expand Up @@ -241,7 +241,7 @@ func (es *ESClientV7) GetClusterWriteStatus(ctx context.Context, db *api.Elastic
return errors.New("Failed to parse key `errors` in response from write request")
}

func (es *ESClientV7) GetClusterReadStatus(ctx context.Context, db *api.Elasticsearch) error {
func (es *ESClientV7) GetClusterReadStatus(ctx context.Context, db *dbapi.Elasticsearch) error {
// Perform a read request in writeRequestIndex/writeRequestID (kubedb-system/info) API
// Handle error specifically if index has not been created yet
res, err := esapi.GetRequest{
Expand Down
6 changes: 3 additions & 3 deletions elasticsearch/es_client_v8.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"net/http"
"strings"

api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"

esv8 "github.com/elastic/go-elasticsearch/v8"
"github.com/elastic/go-elasticsearch/v8/esapi"
Expand Down Expand Up @@ -175,7 +175,7 @@ func (es *ESClientV8) SyncCredentialFromSecret(secret *core.Secret) error {
return errors.New("CredSyncFailed")
}

func (es *ESClientV8) GetClusterWriteStatus(ctx context.Context, db *api.Elasticsearch) error {
func (es *ESClientV8) GetClusterWriteStatus(ctx context.Context, db *dbapi.Elasticsearch) error {
// Build the request index & request body
// send the db specs as body
indexBody := WriteRequestIndexBody{
Expand Down Expand Up @@ -240,7 +240,7 @@ func (es *ESClientV8) GetClusterWriteStatus(ctx context.Context, db *api.Elastic
return errors.New("Failed to parse key `errors` in response from write request")
}

func (es *ESClientV8) GetClusterReadStatus(ctx context.Context, db *api.Elasticsearch) error {
func (es *ESClientV8) GetClusterReadStatus(ctx context.Context, db *dbapi.Elasticsearch) error {
// Perform a read request in writeRequestIndex/writeRequestID (kubedb-system/info) API
// Handle error specifically if index has not been created yet
res, err := esapi.GetRequest{
Expand Down
11 changes: 6 additions & 5 deletions elasticsearch/kubedb_client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import (

catalog "kubedb.dev/apimachinery/apis/catalog/v1alpha1"
"kubedb.dev/apimachinery/apis/elasticsearch/v1alpha1"
api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
"kubedb.dev/apimachinery/apis/kubedb"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"

"github.com/Masterminds/semver/v3"
esv5 "github.com/elastic/go-elasticsearch/v5"
Expand All @@ -50,13 +51,13 @@ import (

type KubeDBClientBuilder struct {
kc client.Client
db *api.Elasticsearch
db *dbapi.Elasticsearch
url string
podName string
ctx context.Context
}

func NewKubeDBClientBuilder(kc client.Client, db *api.Elasticsearch) *KubeDBClientBuilder {
func NewKubeDBClientBuilder(kc client.Client, db *dbapi.Elasticsearch) *KubeDBClientBuilder {
return &KubeDBClientBuilder{
kc: kc,
db: db,
Expand Down Expand Up @@ -506,7 +507,7 @@ func (o *KubeDBClientBuilder) getDefaultTLSConfig() (*tls.Config, error) {

if o.db.Spec.EnableSSL {
var certSecret core.Secret
err := o.kc.Get(o.ctx, client.ObjectKey{Namespace: o.db.Namespace, Name: o.db.GetCertSecretName(api.ElasticsearchClientCert)}, &certSecret)
err := o.kc.Get(o.ctx, client.ObjectKey{Namespace: o.db.Namespace, Name: o.db.GetCertSecretName(dbapi.ElasticsearchClientCert)}, &certSecret)
if err != nil {
klog.Errorf("Failed to get client-cert for tls configurations")
return nil, err
Expand Down Expand Up @@ -539,5 +540,5 @@ func (o *KubeDBClientBuilder) getDefaultTLSConfig() (*tls.Config, error) {
}

func (o *KubeDBClientBuilder) ServiceURL() string {
return fmt.Sprintf("%v://%s.%s.svc:%d", o.db.GetConnectionScheme(), o.db.ServiceName(), o.db.GetNamespace(), api.ElasticsearchRestPort)
return fmt.Sprintf("%v://%s.%s.svc:%d", o.db.GetConnectionScheme(), o.db.ServiceName(), o.db.GetNamespace(), kubedb.ElasticsearchRestPort)
}
6 changes: 3 additions & 3 deletions elasticsearch/os_client_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"net/http"
"strings"

api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"

"github.com/opensearch-project/opensearch-go"
"github.com/opensearch-project/opensearch-go/opensearchapi"
Expand Down Expand Up @@ -120,7 +120,7 @@ func (os *OSClientV1) ClusterStatus() (string, error) {
return "", errors.New("status is missing")
}

func (os *OSClientV1) GetClusterWriteStatus(ctx context.Context, db *api.Elasticsearch) error {
func (os *OSClientV1) GetClusterWriteStatus(ctx context.Context, db *dbapi.Elasticsearch) error {
// Build the request index & request body
// send the db specs as body
indexBody := WriteRequestIndexBody{
Expand Down Expand Up @@ -186,7 +186,7 @@ func (os *OSClientV1) GetClusterWriteStatus(ctx context.Context, db *api.Elastic
return errors.New("Failed to parse key `errors` in response from write request")
}

func (os *OSClientV1) GetClusterReadStatus(ctx context.Context, db *api.Elasticsearch) error {
func (os *OSClientV1) GetClusterReadStatus(ctx context.Context, db *dbapi.Elasticsearch) error {
// Perform a read request in writeRequestIndex/writeRequestID (kubedb-system/info) API
// Handle error specifically if index has not been created yet
res, err := opensearchapi.GetRequest{
Expand Down
6 changes: 3 additions & 3 deletions elasticsearch/os_client_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"net/http"
"strings"

api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"

"github.com/opensearch-project/opensearch-go/opensearchapi"
osv2 "github.com/opensearch-project/opensearch-go/v2"
Expand Down Expand Up @@ -121,7 +121,7 @@ func (os *OSClientV2) ClusterStatus() (string, error) {
return "", errors.New("status is missing")
}

func (os *OSClientV2) GetClusterWriteStatus(ctx context.Context, db *api.Elasticsearch) error {
func (os *OSClientV2) GetClusterWriteStatus(ctx context.Context, db *dbapi.Elasticsearch) error {
// Build the request index & request body
// send the db specs as body
indexBody := WriteRequestIndexBody{
Expand Down Expand Up @@ -186,7 +186,7 @@ func (os *OSClientV2) GetClusterWriteStatus(ctx context.Context, db *api.Elastic
return errors.New("Failed to parse key `errors` in response from write request")
}

func (os *OSClientV2) GetClusterReadStatus(ctx context.Context, db *api.Elasticsearch) error {
func (os *OSClientV2) GetClusterReadStatus(ctx context.Context, db *dbapi.Elasticsearch) error {
// Perform a read request in writeRequestIndex/writeRequestID (kubedb-system/info) API
// Handle error specifically if index has not been created yet
res, err := osv2api.GetRequest{
Expand Down
4 changes: 2 additions & 2 deletions elasticsearchdashboard/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

catalog "kubedb.dev/apimachinery/apis/catalog/v1alpha1"
esapi "kubedb.dev/apimachinery/apis/elasticsearch/v1alpha1"
api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"

core "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -53,7 +53,7 @@ type ClientOptions struct {
KClient client.Client
Dashboard *esapi.ElasticsearchDashboard
ESVersion *catalog.ElasticsearchVersion
DB *api.Elasticsearch
DB *dbapi.Elasticsearch
Ctx context.Context
Secret *core.Secret
}
Expand Down
6 changes: 3 additions & 3 deletions elasticsearchdashboard/kubedb-client-builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

catalog "kubedb.dev/apimachinery/apis/catalog/v1alpha1"
esapi "kubedb.dev/apimachinery/apis/elasticsearch/v1alpha1"
"kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"

"github.com/Masterminds/semver/v3"
"github.com/go-resty/resty/v2"
Expand All @@ -41,7 +41,7 @@ import (
type KubeDBClientBuilder struct {
kc client.Client
dashboard *esapi.ElasticsearchDashboard
db *v1alpha2.Elasticsearch
db *dbapi.Elasticsearch
dbVersion *catalog.ElasticsearchVersion
dbVersionInfo *DbVersionInfo
authSecret *core.Secret
Expand Down Expand Up @@ -72,7 +72,7 @@ func (o *KubeDBClientBuilder) WithAuthSecret(secret *core.Secret) *KubeDBClientB
return o
}

func (o *KubeDBClientBuilder) WithDatabaseRef(db *v1alpha2.Elasticsearch) *KubeDBClientBuilder {
func (o *KubeDBClientBuilder) WithDatabaseRef(db *dbapi.Elasticsearch) *KubeDBClientBuilder {
o.db = db
return o
}
Expand Down
Loading

0 comments on commit 3b94bb3

Please sign in to comment.