diff --git a/libnetwork/internal/kvstore/boltdb/boltdb.go b/libnetwork/internal/kvstore/boltdb/boltdb.go index 9ab5e5d88b4d53d4e468ee3bbe4aa28461cba19f..1c48864dbd1e49ea4964af587050e1023d52c0bd 100644 --- a/libnetwork/internal/kvstore/boltdb/boltdb.go +++ b/libnetwork/internal/kvstore/boltdb/boltdb.go @@ -9,6 +9,7 @@ import ( "sync/atomic" "github.com/boltdb/bolt" + "github.com/docker/libkv" "github.com/docker/libkv/store" ) @@ -35,6 +36,11 @@ const ( libkvmetadatalen = 8 ) +// Register registers boltdb to libkv +func Register() { + libkv.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 index c44366aeb08bcefeb6c74b17702b9c6108fb0176..7b3d0584bacd3f74bd1d907bd5ac4e02c74e0258 100644 --- a/libnetwork/internal/kvstore/kvstore_manage.go +++ b/libnetwork/internal/kvstore/kvstore_manage.go @@ -67,10 +67,6 @@ import ( "strings" "github.com/docker/libkv/store" - "github.com/docker/libkv/store/boltdb" - "github.com/docker/libkv/store/consul" - "github.com/docker/libkv/store/etcd" - "github.com/docker/libkv/store/zookeeper" ) // Initialize creates a new Store object, initializing the client @@ -78,12 +74,8 @@ type Initialize func(addrs []string, options *store.Config) (store.Store, error) var ( // Backend initializers - initializers = map[store.Backend]Initialize{ - store.CONSUL: consul.New, - store.ETCD: etcd.New, - store.ZK: zookeeper.New, - store.BOLTDB: boltdb.New, - } + initializers = make(map[store.Backend]Initialize) + supportedBackend = func() string { keys := make([]string, 0, len(initializers)) for k := range initializers { @@ -102,3 +94,8 @@ func NewStore(backend store.Backend, addrs []string, options *store.Config) (sto return nil, fmt.Errorf("%s %s", store.ErrNotSupported.Error(), supportedBackend) } + +// AddStore adds a new store backend to libkv +func AddStore(store store.Backend, init Initialize) { + initializers[store] = init +}