@@ -26,16 +26,14 @@ import (
2626 "strconv"
2727 "sync"
2828
29- "github.com/arangodb/kube-arangodb/pkg/util/errors"
30-
31- "github.com/arangodb/go-driver/agency"
32- "github.com/arangodb/kube-arangodb/pkg/util/arangod/conn"
33- "github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
34-
3529 driver "github.com/arangodb/go-driver"
30+ "github.com/arangodb/go-driver/agency"
3631 api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
3732 "github.com/arangodb/kube-arangodb/pkg/apis/shared"
3833 "github.com/arangodb/kube-arangodb/pkg/deployment/reconciler"
34+ "github.com/arangodb/kube-arangodb/pkg/util/arangod/conn"
35+ "github.com/arangodb/kube-arangodb/pkg/util/errors"
36+ "github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
3937)
4038
4139type Cache interface {
@@ -81,6 +79,8 @@ func (cc *cache) extendHost(host string) string {
8179}
8280
8381func (cc * cache ) getClient (group api.ServerGroup , id string ) (driver.Client , error ) {
82+ cc .mutex .Lock ()
83+ defer cc .mutex .Unlock ()
8484 m , _ , _ := cc .in .GetStatusSnapshot ().Members .ElementByID (id )
8585
8686 endpoint , err := cc .in .GenerateMemberEndpoint (group , m )
@@ -95,7 +95,9 @@ func (cc *cache) getClient(group api.ServerGroup, id string) (driver.Client, err
9595 return c , nil
9696}
9797
98- func (cc * cache ) get (ctx context.Context , group api.ServerGroup , id string ) (driver.Client , error ) {
98+ // Get a cached client for the given ID in the given group, creating one
99+ // if needed.
100+ func (cc * cache ) Get (ctx context.Context , group api.ServerGroup , id string ) (driver.Client , error ) {
99101 client , err := cc .getClient (group , id )
100102 if err != nil {
101103 return nil , errors .WithStack (err )
@@ -110,28 +112,24 @@ func (cc *cache) get(ctx context.Context, group api.ServerGroup, id string) (dri
110112 }
111113}
112114
113- // Get a cached client for the given ID in the given group, creating one
114- // if needed.
115- func (cc * cache ) Get (ctx context.Context , group api.ServerGroup , id string ) (driver.Client , error ) {
116- cc .mutex .Lock ()
117- defer cc .mutex .Unlock ()
118-
119- return cc .get (ctx , group , id )
120- }
121-
122115func (cc * cache ) GetAuth () conn.Auth {
123116 return cc .factory .GetAuth ()
124117}
125118
126119func (cc * cache ) getDatabaseClient () (driver.Client , error ) {
120+ cc .mutex .Lock ()
121+ defer cc .mutex .Unlock ()
122+
127123 c , err := cc .factory .Client (cc .extendHost (k8sutil .CreateDatabaseClientServiceDNSName (cc .in .GetAPIObject ())))
128124 if err != nil {
129125 return nil , errors .WithStack (err )
130126 }
131127 return c , nil
132128}
133129
134- func (cc * cache ) getDatabase (ctx context.Context ) (driver.Client , error ) {
130+ // GetDatabase returns a cached client for the entire database (cluster coordinators or single server),
131+ // creating one if needed.
132+ func (cc * cache ) GetDatabase (ctx context.Context ) (driver.Client , error ) {
135133 client , err := cc .getDatabaseClient ()
136134 if err != nil {
137135 return nil , errors .WithStack (err )
@@ -146,16 +144,11 @@ func (cc *cache) getDatabase(ctx context.Context) (driver.Client, error) {
146144 }
147145}
148146
149- // GetDatabase returns a cached client for the entire database (cluster coordinators or single server),
150- // creating one if needed.
151- func (cc * cache ) GetDatabase (ctx context.Context ) (driver.Client , error ) {
147+ // GetAgency returns a cached client for the agency
148+ func (cc * cache ) GetAgency (ctx context.Context ) (agency.Agency , error ) {
152149 cc .mutex .Lock ()
153150 defer cc .mutex .Unlock ()
154151
155- return cc .getDatabase (ctx )
156- }
157-
158- func (cc * cache ) getAgencyClient () (agency.Agency , error ) {
159152 // Not found, create a new client
160153 var dnsNames []string
161154 for _ , m := range cc .in .GetStatusSnapshot ().Members .Agents {
@@ -177,11 +170,3 @@ func (cc *cache) getAgencyClient() (agency.Agency, error) {
177170 }
178171 return c , nil
179172}
180-
181- // GetDatabase returns a cached client for the agency
182- func (cc * cache ) GetAgency (ctx context.Context ) (agency.Agency , error ) {
183- cc .mutex .Lock ()
184- defer cc .mutex .Unlock ()
185-
186- return cc .getAgencyClient ()
187- }
0 commit comments