We are using interface in the api routers to not explicitely depend on
the daemon struct (`daemon.Daemon`), but somehow, we do depend on the
`daemon` package for the cluster functionalities.
This removes this dependency by defining the correct interfaces.
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
| ... | ... |
@@ -20,3 +20,13 @@ type Backend interface {
|
| 20 | 20 |
DeleteNetwork(networkID string) error |
| 21 | 21 |
NetworksPrune(ctx context.Context, pruneFilters filters.Args) (*types.NetworksPruneReport, error) |
| 22 | 22 |
} |
| 23 |
+ |
|
| 24 |
+// ClusterBackend is all the methods that need to be implemented |
|
| 25 |
+// to provide cluster network specific functionality. |
|
| 26 |
+type ClusterBackend interface {
|
|
| 27 |
+ GetNetworks() ([]types.NetworkResource, error) |
|
| 28 |
+ GetNetwork(name string) (types.NetworkResource, error) |
|
| 29 |
+ GetNetworksByName(name string) ([]types.NetworkResource, error) |
|
| 30 |
+ CreateNetwork(nc types.NetworkCreateRequest) (string, error) |
|
| 31 |
+ RemoveNetwork(name string) error |
|
| 32 |
+} |
| ... | ... |
@@ -2,18 +2,17 @@ package network // import "github.com/docker/docker/api/server/router/network" |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"github.com/docker/docker/api/server/router" |
| 5 |
- "github.com/docker/docker/daemon/cluster" |
|
| 6 | 5 |
) |
| 7 | 6 |
|
| 8 | 7 |
// networkRouter is a router to talk with the network controller |
| 9 | 8 |
type networkRouter struct {
|
| 10 | 9 |
backend Backend |
| 11 |
- cluster *cluster.Cluster |
|
| 10 |
+ cluster ClusterBackend |
|
| 12 | 11 |
routes []router.Route |
| 13 | 12 |
} |
| 14 | 13 |
|
| 15 | 14 |
// NewRouter initializes a new network router |
| 16 |
-func NewRouter(b Backend, c *cluster.Cluster) router.Router {
|
|
| 15 |
+func NewRouter(b Backend, c ClusterBackend) router.Router {
|
|
| 17 | 16 |
r := &networkRouter{
|
| 18 | 17 |
backend: b, |
| 19 | 18 |
cluster: c, |
| ... | ... |
@@ -6,6 +6,7 @@ import ( |
| 6 | 6 |
"github.com/docker/docker/api/types" |
| 7 | 7 |
"github.com/docker/docker/api/types/events" |
| 8 | 8 |
"github.com/docker/docker/api/types/filters" |
| 9 |
+ "github.com/docker/docker/api/types/swarm" |
|
| 9 | 10 |
"golang.org/x/net/context" |
| 10 | 11 |
) |
| 11 | 12 |
|
| ... | ... |
@@ -19,3 +20,9 @@ type Backend interface {
|
| 19 | 19 |
UnsubscribeFromEvents(chan interface{})
|
| 20 | 20 |
AuthenticateToRegistry(ctx context.Context, authConfig *types.AuthConfig) (string, string, error) |
| 21 | 21 |
} |
| 22 |
+ |
|
| 23 |
+// ClusterBackend is all the methods that need to be implemented |
|
| 24 |
+// to provide cluster system specific functionality. |
|
| 25 |
+type ClusterBackend interface {
|
|
| 26 |
+ Info() swarm.Info |
|
| 27 |
+} |
| ... | ... |
@@ -3,20 +3,19 @@ package system // import "github.com/docker/docker/api/server/router/system" |
| 3 | 3 |
import ( |
| 4 | 4 |
"github.com/docker/docker/api/server/router" |
| 5 | 5 |
"github.com/docker/docker/builder/fscache" |
| 6 |
- "github.com/docker/docker/daemon/cluster" |
|
| 7 | 6 |
) |
| 8 | 7 |
|
| 9 | 8 |
// systemRouter provides information about the Docker system overall. |
| 10 | 9 |
// It gathers information about host, daemon and container events. |
| 11 | 10 |
type systemRouter struct {
|
| 12 | 11 |
backend Backend |
| 13 |
- cluster *cluster.Cluster |
|
| 12 |
+ cluster ClusterBackend |
|
| 14 | 13 |
routes []router.Route |
| 15 | 14 |
builder *fscache.FSCache |
| 16 | 15 |
} |
| 17 | 16 |
|
| 18 | 17 |
// NewRouter initializes a new system router |
| 19 |
-func NewRouter(b Backend, c *cluster.Cluster, fscache *fscache.FSCache) router.Router {
|
|
| 18 |
+func NewRouter(b Backend, c ClusterBackend, fscache *fscache.FSCache) router.Router {
|
|
| 20 | 19 |
r := &systemRouter{
|
| 21 | 20 |
backend: b, |
| 22 | 21 |
cluster: c, |