Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logdrivers to /info #32540

Merged
merged 1 commit into from Apr 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/types/types.go
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
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
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
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
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
@@ -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)
}