Skip to content

Commit

Permalink
Add logdrivers to /info
Browse files Browse the repository at this point in the history
This is required for swarmkit to be able to filter based on log driver.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
  • Loading branch information
cpuguy83 committed Apr 11, 2017
1 parent 1a8206c commit 17abacb
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 2 deletions.
2 changes: 2 additions & 0 deletions api/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ type PluginsInfo struct {
Network []string
// List of Authorization plugins registered
Authorization []string
// List of Log plugins registered
Log []string
}

// ExecStartCheck is a temp struct used by execStart
Expand Down
4 changes: 4 additions & 0 deletions cli/command/system/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func prettyPrintInfo(dockerCli *command.DockerCli, info types.Info) error {
fmt.Fprintf(dockerCli.Out(), "\n")
}

fmt.Fprintf(dockerCli.Out(), " Log:")
fmt.Fprintf(dockerCli.Out(), " %s", strings.Join(info.Plugins.Log, " "))
fmt.Fprintf(dockerCli.Out(), "\n")

fmt.Fprintf(dockerCli.Out(), "Swarm: %v\n", info.Swarm.LocalNodeState)
if info.Swarm.LocalNodeState != swarm.LocalNodeStateInactive && info.Swarm.LocalNodeState != swarm.LocalNodeStateLocked {
fmt.Fprintf(dockerCli.Out(), " NodeID: %s\n", info.Swarm.NodeID)
Expand Down
9 changes: 7 additions & 2 deletions daemon/cluster/executor/container/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (e *executor) Describe(ctx context.Context) (*api.NodeDescription, error) {
// the plugin list by default.
addPlugins("Network", append([]string{"overlay"}, info.Plugins.Network...))
addPlugins("Authorization", info.Plugins.Authorization)
addPlugins("Log", info.Plugins.Log)

// add v2 plugins
v2Plugins, err := e.backend.PluginManager().List(filters.NewArgs())
Expand All @@ -62,11 +63,15 @@ func (e *executor) Describe(ctx context.Context) (*api.NodeDescription, error) {
continue
}
plgnTyp := typ.Capability
if typ.Capability == "volumedriver" {
switch typ.Capability {
case "volumedriver":
plgnTyp = "Volume"
} else if typ.Capability == "networkdriver" {
case "networkdriver":
plgnTyp = "Network"
case "logdriver":
plgnTyp = "Log"
}

plugins[api.PluginDescription{
Type: plgnTyp,
Name: plgn.Name,
Expand Down
2 changes: 2 additions & 0 deletions daemon/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/cli/debug"
"github.com/docker/docker/container"
"github.com/docker/docker/daemon/logger"
"github.com/docker/docker/dockerversion"
"github.com/docker/docker/pkg/fileutils"
"github.com/docker/docker/pkg/parsers/kernel"
Expand Down Expand Up @@ -175,6 +176,7 @@ func (daemon *Daemon) showPluginsInfo() types.PluginsInfo {
pluginsInfo.Volume = volumedrivers.GetDriverList()
pluginsInfo.Network = daemon.GetNetworkDriverList()
pluginsInfo.Authorization = daemon.configStore.GetAuthorizationPlugins()
pluginsInfo.Log = logger.ListDrivers()

return pluginsInfo
}
17 changes: 17 additions & 0 deletions daemon/logger/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package logger

import (
"fmt"
"sort"
"sync"

containertypes "github.com/docker/docker/api/types/container"
Expand All @@ -23,6 +24,22 @@ type logdriverFactory struct {
m sync.Mutex
}

func (lf *logdriverFactory) list() []string {
ls := make([]string, 0, len(lf.registry))
lf.m.Lock()
for name := range lf.registry {
ls = append(ls, name)
}
lf.m.Unlock()
sort.Strings(ls)
return ls
}

// ListDrivers gets the list of registered log driver names
func ListDrivers() []string {
return factory.list()
}

func (lf *logdriverFactory) register(name string, c Creator) error {
if lf.driverRegistered(name) {
return fmt.Errorf("logger: log driver named '%s' is already registered", name)
Expand Down
22 changes: 22 additions & 0 deletions integration-cli/docker_cli_plugins_logdriver_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package main

import (
"encoding/json"
"net/http"
"strings"

"github.com/docker/docker/api/types"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/request"
"github.com/go-check/check"
)

Expand All @@ -25,3 +29,21 @@ func (s *DockerSuite) TestPluginLogDriver(c *check.C) {
dockerCmd(c, "plugin", "disable", pluginName)
dockerCmd(c, "plugin", "rm", pluginName)
}

// Make sure log drivers are listed in info, and v2 plugins are not.
func (s *DockerSuite) TestPluginLogDriverInfoList(c *check.C) {
testRequires(c, IsAmd64, DaemonIsLinux)
pluginName := "cpuguy83/docker-logdriver-test"

dockerCmd(c, "plugin", "install", pluginName)
status, body, err := request.SockRequest("GET", "/info", nil, daemonHost())
c.Assert(status, checker.Equals, http.StatusOK)
c.Assert(err, checker.IsNil)

var info types.Info
err = json.Unmarshal(body, &info)
c.Assert(err, checker.IsNil)
drivers := strings.Join(info.Plugins.Log, " ")
c.Assert(drivers, checker.Contains, "json-file")
c.Assert(drivers, checker.Not(checker.Contains), pluginName)
}

0 comments on commit 17abacb

Please sign in to comment.