Sfoglia il codice sorgente

Merge pull request #32469 from darkowlzz/32314-fix-default-init-binary-value

Fix missing Init Binary in docker info output
Brian Goff 8 anni fa
parent
commit
d291888047

+ 2 - 0
daemon/config/config.go

@@ -41,6 +41,8 @@ const (
 	DefaultNetworkMtu = 1500
 	// DisableNetworkBridge is the default value of the option to disable network bridge
 	DisableNetworkBridge = "none"
+	// DefaultInitBinary is the name of the default init binary
+	DefaultInitBinary = "docker-init"
 )
 
 // flatOptions contains configuration keys

+ 4 - 1
daemon/config/config_common_unix.go

@@ -66,5 +66,8 @@ func (conf *Config) GetInitPath() string {
 	if conf.InitPath != "" {
 		return conf.InitPath
 	}
-	return conf.DefaultInitBinary
+	if conf.DefaultInitBinary != "" {
+		return conf.DefaultInitBinary
+	}
+	return DefaultInitBinary
 }

+ 41 - 0
daemon/config/config_common_unix_test.go

@@ -41,3 +41,44 @@ func TestCommonUnixValidateConfigurationErrors(t *testing.T) {
 		}
 	}
 }
+
+func TestCommonUnixGetInitPath(t *testing.T) {
+	testCases := []struct {
+		config           *Config
+		expectedInitPath string
+	}{
+		{
+			config: &Config{
+				InitPath: "some-init-path",
+			},
+			expectedInitPath: "some-init-path",
+		},
+		{
+			config: &Config{
+				CommonUnixConfig: CommonUnixConfig{
+					DefaultInitBinary: "foo-init-bin",
+				},
+			},
+			expectedInitPath: "foo-init-bin",
+		},
+		{
+			config: &Config{
+				InitPath: "init-path-A",
+				CommonUnixConfig: CommonUnixConfig{
+					DefaultInitBinary: "init-path-B",
+				},
+			},
+			expectedInitPath: "init-path-A",
+		},
+		{
+			config:           &Config{},
+			expectedInitPath: "docker-init",
+		},
+	}
+	for _, tc := range testCases {
+		initPath := tc.config.GetInitPath()
+		if initPath != tc.expectedInitPath {
+			t.Fatalf("expected initPath to be %v, got %v", tc.expectedInitPath, initPath)
+		}
+	}
+}

+ 0 - 3
daemon/daemon.go

@@ -65,9 +65,6 @@ var (
 	// containerd if none is specified
 	DefaultRuntimeBinary = "docker-runc"
 
-	// DefaultInitBinary is the name of the default init binary
-	DefaultInitBinary = "docker-init"
-
 	errSystemNotSupported = errors.New("The Docker daemon is not supported on this platform.")
 )
 

+ 4 - 3
daemon/info_unix.go

@@ -9,6 +9,7 @@ import (
 
 	"github.com/Sirupsen/logrus"
 	"github.com/docker/docker/api/types"
+	daemonconfig "github.com/docker/docker/daemon/config"
 	"github.com/docker/docker/dockerversion"
 	"github.com/docker/docker/pkg/sysinfo"
 	"github.com/pkg/errors"
@@ -55,15 +56,15 @@ func (daemon *Daemon) FillPlatformInfo(v *types.Info, sysInfo *sysinfo.SysInfo)
 		v.RuncCommit.ID = "N/A"
 	}
 
-	if rv, err := exec.Command(DefaultInitBinary, "--version").Output(); err == nil {
+	if rv, err := exec.Command(daemonconfig.DefaultInitBinary, "--version").Output(); err == nil {
 		ver, err := parseInitVersion(string(rv))
 
 		if err != nil {
-			logrus.Warnf("failed to retrieve %s version: %s", DefaultInitBinary, err)
+			logrus.Warnf("failed to retrieve %s version: %s", daemonconfig.DefaultInitBinary, err)
 		}
 		v.InitCommit = ver
 	} else {
-		logrus.Warnf("failed to retrieve %s version: %s", DefaultInitBinary, err)
+		logrus.Warnf("failed to retrieve %s version: %s", daemonconfig.DefaultInitBinary, err)
 		v.InitCommit.ID = "N/A"
 	}
 }

+ 2 - 1
daemon/oci_linux.go

@@ -15,6 +15,7 @@ import (
 	containertypes "github.com/docker/docker/api/types/container"
 	"github.com/docker/docker/container"
 	"github.com/docker/docker/daemon/caps"
+	daemonconfig "github.com/docker/docker/daemon/config"
 	"github.com/docker/docker/oci"
 	"github.com/docker/docker/pkg/idtools"
 	"github.com/docker/docker/pkg/mount"
@@ -624,7 +625,7 @@ func (daemon *Daemon) populateCommonSpec(s *specs.Spec, c *container.Container)
 			s.Process.Args = append([]string{"/dev/init", "--", c.Path}, c.Args...)
 			var path string
 			if daemon.configStore.InitPath == "" && c.HostConfig.InitPath == "" {
-				path, err = exec.LookPath(DefaultInitBinary)
+				path, err = exec.LookPath(daemonconfig.DefaultInitBinary)
 				if err != nil {
 					return err
 				}