浏览代码

Merge pull request #45902 from thaJeztah/fix_volume_npe

Brian Goff 2 年之前
父节点
当前提交
7d548c6c00
共有 2 个文件被更改,包括 22 次插入0 次删除
  1. 4 0
      daemon/mounts.go
  2. 18 0
      integration/daemon/daemon_test.go

+ 4 - 0
daemon/mounts.go

@@ -18,6 +18,10 @@ func (daemon *Daemon) prepareMountPoints(container *container.Container) error {
 		if err := daemon.lazyInitializeVolume(container.ID, config); err != nil {
 		if err := daemon.lazyInitializeVolume(container.ID, config); err != nil {
 			return err
 			return err
 		}
 		}
+		if config.Volume == nil {
+			// FIXME(thaJeztah): should we check for config.Type here as well? (i.e., skip bind-mounts etc)
+			continue
+		}
 		if alive {
 		if alive {
 			log.G(context.TODO()).WithFields(logrus.Fields{
 			log.G(context.TODO()).WithFields(logrus.Fields{
 				"container": container.ID,
 				"container": container.ID,

+ 18 - 0
integration/daemon/daemon_test.go

@@ -436,6 +436,24 @@ func testLiveRestoreVolumeReferences(t *testing.T) {
 		err = c.VolumeRemove(ctx, v.Name, false)
 		err = c.VolumeRemove(ctx, v.Name, false)
 		assert.NilError(t, err)
 		assert.NilError(t, err)
 	})
 	})
+
+	// Make sure that we don't panic if the container has bind-mounts
+	// (which should not be "restored")
+	// Regression test for https://github.com/moby/moby/issues/45898
+	t.Run("container with bind-mounts", func(t *testing.T) {
+		m := mount.Mount{
+			Type:   mount.TypeBind,
+			Source: os.TempDir(),
+			Target: "/foo",
+		}
+		cID := container.Run(ctx, t, c, container.WithMount(m), container.WithCmd("top"))
+		defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true})
+
+		d.Restart(t, "--live-restore", "--iptables=false")
+
+		err := c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true})
+		assert.NilError(t, err)
+	})
 }
 }
 
 
 func TestDaemonDefaultBridgeWithFixedCidrButNoBip(t *testing.T) {
 func TestDaemonDefaultBridgeWithFixedCidrButNoBip(t *testing.T) {