8000 Fix missing Init Binary in docker info output · moby/moby@17b1288 · GitHub
[go: up one dir, main page]

Skip to content

Commit 17b1288

Browse files
committed
Fix missing Init Binary in docker info output
- Moved DefaultInitBinary from daemon/daemon.go to daemon/config/config.go since it's a daemon config and is referred in config package files. - Added condition in GetInitPath to check for any explicitly configured DefaultInitBinary. If not, the default value of DefaultInitBinary is returned. - Changed all references of DefaultInitBinary to refer to the variable from new location. - Added TestCommonUnixGetInitPath to test for the various values of GetInitPath. Fixes #32314 Signed-off-by: Sunny Gogoi <indiasuny000@gmail.com>
1 parent b0831ac commit 17b1288

File tree

6 files changed

+53
-8
lines changed

6 files changed

+53
-8
lines changed

daemon/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ const (
4141
DefaultNetworkMtu = 1500
4242
// DisableNetworkBridge is the default value of the option to disable network bridge
4343
DisableNetworkBridge = "none"
44+
// DefaultInitBinary is the name of the default init binary
45+
DefaultInitBinary = "docker-init"
4446
)
4547

4648
// flatOptions contains configuration keys

daemon/config/config_common_unix.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,8 @@ func (conf *Config) GetInitPath() string {
6666
if conf.InitPath != "" {
6767
return conf.InitPath
6868
}
69-
return conf.DefaultInitBinary
69+
if conf.DefaultInitBinary != "" {
70+
return conf.DefaultInitBinary
71+
}
72+
return DefaultInitBinary
7073
}

daemon/config/config_common_unix_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,44 @@ func TestCommonUnixValidateConfigurationErrors(t *testing.T) {
4141
}
4242
}
4343
}
44+
45+
func TestCommonUnixGetInitPath(t *testing.T) {
46+
testCases := []struct {
47+
config *Config
48+
expectedInitPath string
49+
}{
50+
{
51+
config: &Config{
52+
InitPath: "some-init-path",
53+
},
54+
expectedInitPath: "some-init-path",
55+
},
56+
{
57+
config: &Config{
58+
CommonUnixConfig: CommonUnixConfig{
59+
DefaultInitBinary: "foo-init-bin",
60+
},
61+
},
62+
expectedInitPath: "foo-init-bin",
63+
},
64+
{
65+
config: &Config{
66+
InitPath: "init-path-A",
67+
CommonUnixConfig: CommonUnixConfig{
68+
DefaultInitBinary: "init-path-B",
69+
},
70+
},
71+
expectedInitPath: "init-path-A",
72+
},
73+
{
74+
config: &Config{},
75+
expectedInitPath: "docker-init",
76+
},
77+
}
78+
for _, tc := range testCases {
79+
initPath := tc.config.GetInitPath()
80+
if initPath != tc.expectedInitPath {
81+
t.Fatalf("expected initPath to be %v, got %v", tc.expectedInitPath, initPath)
82+
}
83+
}
84+
}

daemon/daemon.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ var (
6565
// containerd if none is specified
6666
DefaultRuntimeBinary = "docker-runc"
6767

68-
// DefaultInitBinary is the name of the default init binary
69-
DefaultInitBinary = "docker-init"
70-
7168
errSystemNotSupported = errors.New("The Docker daemon is not supported on this platform.")
7269
)
7370

daemon/info_unix.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/Sirupsen/logrus"
1111
"github.com/docker/docker/api/types"
12+
daemonconfig "github.com/docker/docker/daemon/config"
1213
"github.com/docker/docker/dockerversion"
1314
"github.com/docker/docker/pkg/sysinfo"
1415
"github.com/pkg/errors"
@@ -55,15 +56,15 @@ func (daemon *Daemon) FillPlatformInfo(v *types.Info, sysInfo *sysinfo.SysInfo)
5556
v.RuncCommit.ID = "N/A"
5657
}
5758

58-
if rv, err := exec.Command(DefaultInitBinary, "--version").Output(); err == nil {
59+
if rv, err := exec.Command(daemonconfig.DefaultInitBinary, "--version").Output(); err == nil {
5960
ver, err := parseInitVersion(string(rv))
6061

6162
if err != nil {
62-
logrus.Warnf("failed to retrieve %s version: %s", DefaultInitBinary, err)
63+
logrus.Warnf("failed to retrieve %s version: %s", daemonconfig.DefaultInitBinary, err)
6364
}
6465
v.InitCommit = ver
6566
} else {
66-
logrus.Warnf("failed to retrieve %s version: %s", DefaultInitBinary, err)
67+
logrus.Warnf("failed to retrieve %s version: %s", daemonconfig.DefaultInitBinary, err)
6768
v.InitCommit.ID = "N/A"
6869
}
6970
}

daemon/oci_linux.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
containertypes "github.com/docker/docker/api/types/container"
1616
"github.com/docker/docker/container"
1717
"github.com/docker/docker/daemon/caps"
18+
daemonconfig "github.com/docker/docker/daemon/config"
1819
"github.com/docker/docker/oci"
1920
"github.com/docker/docker/pkg/idtools"
2021
"github.com/docker/docker/pkg/mount"
@@ -624,7 +625,7 @@ func (daemon *Daemon) populateCommonSpec(s *specs.Spec, c *container.Container)
624625
s.Process.Args = append([]string{"/dev/init", "--", c.Path}, c.Args...)
625626
var path string
626627
if daemon.configStore.InitPath == "" && c.HostConfig.InitPath == "" {
627-
path, err = exec.LookPath(DefaultInitBinary)
628+
path, err = exec.LookPath(daemonconfig.DefaultInitBinary)
628629
if err != nil {
629630
return err
630631
}

0 commit comments

Comments
 (0)
0