Skip to content

Commit

Permalink
xorm client list building
Browse files Browse the repository at this point in the history
  • Loading branch information
HiranmoyChowdhury committed Apr 26, 2024
1 parent 9526abd commit 9f8990c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pgbouncer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package pgbouncer

import (
"database/sql"
"sync"

"xorm.io/xorm"
)
Expand All @@ -29,3 +30,8 @@ type Client struct {
type XormClient struct {
*xorm.Engine
}

type XormClientList struct {
list []XormClient
mu sync.Mutex
}
36 changes: 36 additions & 0 deletions pgbouncer/kubedb_client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package pgbouncer
import (
"context"
"fmt"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
appbinding "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1"
api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"

Expand Down Expand Up @@ -170,3 +172,37 @@ func (o *KubeDBClientBuilder) getConnectionString() (string, error) {
connector := fmt.Sprintf("user=%s password=%s host=%s port=%d connect_timeout=10 dbname=%s sslmode=%s", user, pass, o.url, listeningPort, o.backendDBName, TLSModeDisable)
return connector, nil
}

func GetXormClientList(kc client.Client, pb *api.PgBouncer, ctx context.Context) (*XormClientList, error) {
Clientlist := &XormClientList{
list: []XormClient{},
}

podList := &corev1.PodList{}
err := kc.List(context.Background(), podList, client.MatchingLabels(pb.PodLabels()))

for _, postgresRef := range pb.Spec.Databases {
for _, pods := range podList.Items {

}

}
return Clientlist, nil
}
func (l *XormClientList) getXormClient(kc client.Client, pb *api.PgBouncer, ctx context.Context, podName string, postgresRef *api.Databases) {
NewKubeDBClientBuilder(kc, pb).WithContext(ctx).WithDatabaseRef(postgresRef).WithPod(podName).GetPgBouncerXormClient()
if err != nil {
klog.V(5).ErrorS(err, fmt.Sprintf("failed to create xorm client for pgbouncer %v to make pool with postgres pod %s/%s", key, postgresRef.DatabaseRef.Namespace, postgresRef.DatabaseRef.Name))
if hcs.HasFailed(health.HealthCheckClientFailure, err) {
// Since the client was unable to connect the database,
// update "AcceptingConnection" to "false".
// update "Ready" to "false"
if err := c.updateConditionsForUnhealthy(ctx, db, err); err != nil {
return
}
}
klog.Error(err)
return
}
dbXormClient = append(dbXormClient, *XormClient)
}

0 comments on commit 9f8990c

Please sign in to comment.