diff --git a/libnetwork/datastore/datastore.go b/libnetwork/datastore/datastore.go index a431265068..c0111b8196 100644 --- a/libnetwork/datastore/datastore.go +++ b/libnetwork/datastore/datastore.go @@ -8,6 +8,7 @@ import ( "github.com/docker/docker/libnetwork/discoverapi" store "github.com/docker/docker/libnetwork/internal/kvstore" + "github.com/docker/docker/libnetwork/internal/kvstore/boltdb" "github.com/docker/docker/libnetwork/types" ) @@ -138,27 +139,16 @@ func Key(key ...string) string { // newClient used to connect to KV Store func newClient(kv string, addr string, config *store.Config) (*Store, error) { + if kv != string(store.BOLTDB) { + return nil, fmt.Errorf("unsupported KV store") + } + if config == nil { config = &store.Config{} } - var addrs []string - - if kv == string(store.BOLTDB) { - // Parse file path - addrs = strings.Split(addr, ",") - } else { - // Parse URI - parts := strings.SplitN(addr, "/", 2) - addrs = strings.Split(parts[0], ",") - - // Add the custom prefix to the root chain - if len(parts) == 2 { - rootChain = append([]string{parts[1]}, defaultRootChain...) - } - } - - s, err := store.New(store.Backend(kv), addrs, config) + // Parse file path + s, err := boltdb.New(strings.Split(addr, ","), config) if err != nil { return nil, err } @@ -390,7 +380,7 @@ func (ds *Store) DeleteObjectAtomic(kvObject KVObject) error { previous := &store.KVPair{Key: Key(kvObject.Key()...), LastIndex: kvObject.Index()} if kvObject.Skip() { - goto del_cache + goto deleteCache } if err := ds.store.AtomicDelete(Key(kvObject.Key()...), previous); err != nil { @@ -400,7 +390,7 @@ func (ds *Store) DeleteObjectAtomic(kvObject KVObject) error { return err } -del_cache: +deleteCache: // cleanup the cache only if AtomicDelete went through successfully if ds.cache != nil { // If persistent store is skipped, sequencing needs to diff --git a/libnetwork/drivers/overlay/overlay_test.go b/libnetwork/drivers/overlay/overlay_test.go index 5d28ac97b8..1e6a640c77 100644 --- a/libnetwork/drivers/overlay/overlay_test.go +++ b/libnetwork/drivers/overlay/overlay_test.go @@ -6,14 +6,9 @@ import ( "testing" "github.com/docker/docker/libnetwork/driverapi" - "github.com/docker/docker/libnetwork/internal/kvstore/boltdb" "github.com/docker/docker/pkg/plugingetter" ) -func init() { - boltdb.Register() -} - type driverTester struct { t *testing.T d *driver diff --git a/libnetwork/internal/kvstore/boltdb/boltdb.go b/libnetwork/internal/kvstore/boltdb/boltdb.go index e5a4b949fb..85793938a8 100644 --- a/libnetwork/internal/kvstore/boltdb/boltdb.go +++ b/libnetwork/internal/kvstore/boltdb/boltdb.go @@ -45,11 +45,6 @@ const ( transientTimeout = time.Duration(10) * time.Second ) -// Register registers boltdb to libkv -func Register() { - store.AddStore(store.BOLTDB, New) -} - // New opens a new BoltDB connection to the specified path and bucket func New(endpoints []string, options *store.Config) (store.Store, error) { if len(endpoints) > 1 { diff --git a/libnetwork/internal/kvstore/kvstore_manage.go b/libnetwork/internal/kvstore/kvstore_manage.go deleted file mode 100644 index efaee6000c..0000000000 --- a/libnetwork/internal/kvstore/kvstore_manage.go +++ /dev/null @@ -1,38 +0,0 @@ -package kvstore - -import ( - "fmt" - "sort" - "strings" -) - -// Initialize creates a new Store object, initializing the client -type Initialize func(addrs []string, options *Config) (Store, error) - -var ( - // Backend initializers - initializers = make(map[Backend]Initialize) - - supportedBackend = func() string { - keys := make([]string, 0, len(initializers)) - for k := range initializers { - keys = append(keys, string(k)) - } - sort.Strings(keys) - return strings.Join(keys, ", ") - }() -) - -// New creates an instance of store -func New(backend Backend, addrs []string, options *Config) (Store, error) { - if init, exists := initializers[backend]; exists { - return init(addrs, options) - } - - return nil, fmt.Errorf("%s %s", ErrBackendNotSupported.Error(), supportedBackend) -} - -// AddStore adds a new store backend to libkv -func AddStore(store Backend, init Initialize) { - initializers[store] = init -} diff --git a/libnetwork/store.go b/libnetwork/store.go index f05770989a..1d8dc151be 100644 --- a/libnetwork/store.go +++ b/libnetwork/store.go @@ -7,16 +7,9 @@ import ( "github.com/containerd/containerd/log" "github.com/docker/docker/libnetwork/datastore" - "github.com/docker/docker/libnetwork/internal/kvstore/boltdb" ) -func registerKVStores() { - boltdb.Register() -} - func (c *Controller) initStores() error { - registerKVStores() - c.mu.Lock() defer c.mu.Unlock()