Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions cli/command/system/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/registry"
"github.com/docker/go-units"
"github.com/spf13/cobra"
)
Expand All @@ -41,6 +42,7 @@ type info struct {
// object.
*types.Info `json:",omitempty"`
ServerErrors []string `json:",omitempty"`
UserName string `json:"-"`

ClientInfo *clientInfo `json:",omitempty"`
ClientErrors []string `json:",omitempty"`
Expand Down Expand Up @@ -112,6 +114,8 @@ func runInfo(cmd *cobra.Command, dockerCli command.Cli, opts *infoOptions) error
}

if opts.format == "" {
info.UserName = dockerCli.ConfigFile().AuthConfigs[registry.IndexServer].Username
info.ClientInfo.APIVersion = dockerCli.CurrentVersion()
return prettyPrintInfo(dockerCli, info)
}
return formatInfo(dockerCli, info, opts.format)
Expand Down Expand Up @@ -173,7 +177,7 @@ func prettyPrintInfo(dockerCli command.Cli, info info) error {
fmt.Fprintln(dockerCli.Out())
fmt.Fprintln(dockerCli.Out(), "Server:")
if info.Info != nil {
for _, err := range prettyPrintServerInfo(dockerCli, *info.Info) {
for _, err := range prettyPrintServerInfo(dockerCli, &info) {
info.ServerErrors = append(info.ServerErrors, err.Error())
}
}
Expand Down Expand Up @@ -211,7 +215,7 @@ func prettyPrintClientInfo(dockerCli command.Cli, info clientInfo) {
}

//nolint:gocyclo
func prettyPrintServerInfo(dockerCli command.Cli, info types.Info) []error {
func prettyPrintServerInfo(dockerCli command.Cli, info *info) []error {
var errs []error

fmt.Fprintln(dockerCli.Out(), " Containers:", info.Containers)
Expand Down Expand Up @@ -246,7 +250,7 @@ func prettyPrintServerInfo(dockerCli command.Cli, info types.Info) []error {
fmt.Fprintln(dockerCli.Out(), " Log:", strings.Join(info.Plugins.Log, " "))

fmt.Fprintln(dockerCli.Out(), " Swarm:", info.Swarm.LocalNodeState)
printSwarmInfo(dockerCli, info)
printSwarmInfo(dockerCli, *info.Info)

if len(info.Runtimes) > 0 {
fmt.Fprint(dockerCli.Out(), " Runtimes:")
Expand Down Expand Up @@ -318,14 +322,7 @@ func prettyPrintServerInfo(dockerCli command.Cli, info types.Info) []error {
fprintlnNonEmpty(dockerCli.Out(), " HTTP Proxy:", info.HTTPProxy)
fprintlnNonEmpty(dockerCli.Out(), " HTTPS Proxy:", info.HTTPSProxy)
fprintlnNonEmpty(dockerCli.Out(), " No Proxy:", info.NoProxy)

if info.IndexServerAddress != "" {
u := dockerCli.ConfigFile().AuthConfigs[info.IndexServerAddress].Username
if len(u) > 0 {
fmt.Fprintln(dockerCli.Out(), " Username:", u)
}
}

fprintlnNonEmpty(dockerCli.Out(), " Username:", info.UserName)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I'm also very much leaning towards moving this information to the Client: section, because nothing about it is part of the "Server:".

I think this was historically because it depended on the server (?) but no real idea.

Also;

  • because it's not part of the actual info.Info struct (i.e., the Server part), it's currently not even possible to use docker info --format <template> to show the name
  • ^^ so docker info --format=json won't show it
  • ^^ AND if a credentials-helper is used, it's not even filled in at all (it only looks in the config file
  • 🙃 🤷

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So ... perhaps we should either remove it altogether, or make it use the actual credential-store in use, BUT reading info from that is not always .. fast, and I don't want docker info to become slow 😓

if len(info.Labels) > 0 {
fmt.Fprintln(dockerCli.Out(), " Labels:")
for _, lbl := range info.Labels {
Expand Down Expand Up @@ -444,16 +441,16 @@ func printSwarmInfo(dockerCli command.Cli, info types.Info) {
}
}

func printServerWarnings(dockerCli command.Cli, info types.Info) {
if versions.LessThan(dockerCli.Client().ClientVersion(), "1.42") {
printSecurityOptionsWarnings(dockerCli, info)
func printServerWarnings(dockerCli command.Cli, info *info) {
if versions.LessThan(info.ClientInfo.APIVersion, "1.42") {
printSecurityOptionsWarnings(dockerCli, *info.Info)
}
if len(info.Warnings) > 0 {
fmt.Fprintln(dockerCli.Err(), strings.Join(info.Warnings, "\n"))
return
}
// daemon didn't return warnings. Fallback to old behavior
printServerWarningsLegacy(dockerCli, info)
printServerWarningsLegacy(dockerCli, *info.Info)
}

// printSecurityOptionsWarnings prints warnings based on the security options
Expand Down