@@ -129,37 +129,28 @@ const (
129129 EndpointKeyPrefix = "endpoint"
130130)
131131
132- var (
133- defaultScopes = makeDefaultScopes ()
134- )
132+ var defaultRootChain = []string {"docker" , "network" , "v1.0" }
133+ var rootChain = defaultRootChain
134+
135+ // DefaultScope returns a default scope config for clients to use.
136+ func DefaultScope (dataDir string ) ScopeCfg {
137+ var dbpath string
138+ if dataDir == "" {
139+ dbpath = defaultPrefix + "/local-kv.db"
140+ } else {
141+ dbpath = dataDir + "/network/files/local-kv.db"
142+ }
135143
136- func makeDefaultScopes () map [string ]* ScopeCfg {
137- def := make (map [string ]* ScopeCfg )
138- def [LocalScope ] = & ScopeCfg {
144+ return ScopeCfg {
139145 Client : ScopeClientCfg {
140146 Provider : string (store .BOLTDB ),
141- Address : defaultPrefix + "/local-kv.db" ,
147+ Address : dbpath ,
142148 Config : & store.Config {
143149 Bucket : "libnetwork" ,
144150 ConnectionTimeout : time .Minute ,
145151 },
146152 },
147153 }
148-
149- return def
150- }
151-
152- var defaultRootChain = []string {"docker" , "network" , "v1.0" }
153- var rootChain = defaultRootChain
154-
155- // DefaultScopes returns a map of default scopes and its config for clients to use.
156- func DefaultScopes (dataDir string ) map [string ]* ScopeCfg {
157- s := makeDefaultScopes ()
158- if dataDir != "" {
159- s [LocalScope ].Client .Address = dataDir + "/network/files/local-kv.db"
160- }
161-
162- return s
163154}
164155
165156// IsValid checks if the scope config has valid configuration.
@@ -192,16 +183,7 @@ func ParseKey(key string) ([]string, error) {
192183}
193184
194185// newClient used to connect to KV Store
195- func newClient (scope string , kv string , addr string , config * store.Config , cached bool ) (DataStore , error ) {
196-
197- if cached && scope != LocalScope {
198- return nil , fmt .Errorf ("caching supported only for scope %s" , LocalScope )
199- }
200- sequential := false
201- if scope == LocalScope {
202- sequential = true
203- }
204-
186+ func newClient (kv string , addr string , config * store.Config ) (DataStore , error ) {
205187 if config == nil {
206188 config = & store.Config {}
207189 }
@@ -227,31 +209,19 @@ func newClient(scope string, kv string, addr string, config *store.Config, cache
227209 return nil , err
228210 }
229211
230- ds := & datastore {scope : scope , store : s , active : true , watchCh : make (chan struct {}), sequential : sequential }
231- if cached {
232- ds .cache = newCache (ds )
233- }
212+ ds := & datastore {scope : LocalScope , store : s , active : true , watchCh : make (chan struct {}), sequential : true }
213+ ds .cache = newCache (ds )
234214
235215 return ds , nil
236216}
237217
238218// NewDataStore creates a new instance of LibKV data store
239- func NewDataStore (scope string , cfg * ScopeCfg ) (DataStore , error ) {
240- if cfg == nil || cfg .Client .Provider == "" || cfg .Client .Address == "" {
241- c , ok := defaultScopes [scope ]
242- if ! ok || c .Client .Provider == "" || c .Client .Address == "" {
243- return nil , fmt .Errorf ("unexpected scope %s without configuration passed" , scope )
244- }
245-
246- cfg = c
247- }
248-
249- var cached bool
250- if scope == LocalScope {
251- cached = true
219+ func NewDataStore (cfg ScopeCfg ) (DataStore , error ) {
220+ if cfg .Client .Provider == "" || cfg .Client .Address == "" {
221+ cfg = DefaultScope ("" )
252222 }
253223
254- return newClient (scope , cfg .Client .Provider , cfg .Client .Address , cfg .Client .Config , cached )
224+ return newClient (cfg .Client .Provider , cfg .Client .Address , cfg .Client .Config )
255225}
256226
257227// NewDataStoreFromConfig creates a new instance of LibKV data store starting from the datastore config data
@@ -266,15 +236,15 @@ func NewDataStoreFromConfig(dsc discoverapi.DatastoreConfigData) (DataStore, err
266236 return nil , fmt .Errorf ("cannot parse store configuration: %v" , dsc .Config )
267237 }
268238
269- scopeCfg := & ScopeCfg {
239+ scopeCfg := ScopeCfg {
270240 Client : ScopeClientCfg {
271241 Address : dsc .Address ,
272242 Provider : dsc .Provider ,
273243 Config : sCfgP ,
274244 },
275245 }
276246
277- ds , err := NewDataStore (dsc . Scope , scopeCfg )
247+ ds , err := NewDataStore (scopeCfg )
278248 if err != nil {
279249 return nil , fmt .Errorf ("failed to construct datastore client from datastore configuration %v: %v" , dsc , err )
280250 }
0 commit comments