Skip to content

Commit 9ca4aa4

Browse files
committed
Merge pull request moby#15798 from calavera/volume_driver_host_config
Move VolumeDriver to HostConfig to make containers portable.
2 parents a58aa9d + 6549d65 commit 9ca4aa4

22 files changed

+181
-78
lines changed

api/server/container.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"io"
66
"net/http"
7-
"runtime"
87
"strconv"
98
"strings"
109
"time"
@@ -20,22 +19,6 @@ import (
2019
"github.com/docker/docker/runconfig"
2120
)
2221

23-
func (s *Server) getContainersByName(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
24-
if vars == nil {
25-
return fmt.Errorf("Missing parameter")
26-
}
27-
28-
if version.LessThan("1.20") && runtime.GOOS != "windows" {
29-
return getContainersByNameDownlevel(w, s, vars["name"])
30-
}
31-
32-
containerJSON, err := s.daemon.ContainerInspect(vars["name"])
33-
if err != nil {
34-
return err
35-
}
36-
return writeJSON(w, http.StatusOK, containerJSON)
37-
}
38-
3922
func (s *Server) getContainersJSON(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
4023
if err := parseForm(r); err != nil {
4124
return err

api/server/inspect.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package server
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
7+
"github.com/docker/docker/pkg/version"
8+
)
9+
10+
// getContainersByName inspects containers configuration and serializes it as json.
11+
func (s *Server) getContainersByName(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
12+
if vars == nil {
13+
return fmt.Errorf("Missing parameter")
14+
}
15+
16+
var json interface{}
17+
var err error
18+
19+
switch {
20+
case version.LessThan("1.20"):
21+
json, err = s.daemon.ContainerInspectPre120(vars["name"])
22+
case version.Equal("1.20"):
23+
json, err = s.daemon.ContainerInspect120(vars["name"])
24+
default:
25+
json, err = s.daemon.ContainerInspect(vars["name"])
26+
}
27+
28+
if err != nil {
29+
return err
30+
}
31+
32+
return writeJSON(w, http.StatusOK, json)
33+
}

api/server/server_unix.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,6 @@ func allocateDaemonPort(addr string) error {
103103
return nil
104104
}
105105

106-
// getContainersByNameDownlevel performs processing for pre 1.20 APIs. This
107-
// is only relevant on non-Windows daemons.
108-
func getContainersByNameDownlevel(w http.ResponseWriter, s *Server, namevar string) error {
109-
containerJSONRaw, err := s.daemon.ContainerInspectPre120(namevar)
110-
if err != nil {
111-
return err
112-
}
113-
return writeJSON(w, http.StatusOK, containerJSONRaw)
114-
}
115-
116106
// listenFD returns the specified socket activated files as a slice of
117107
// net.Listeners or all of the activated files if "*" is given.
118108
func listenFD(addr string) ([]net.Listener, error) {

api/server/server_windows.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,3 @@ func (s *Server) AcceptConnections(d *daemon.Daemon) {
5656
func allocateDaemonPort(addr string) error {
5757
return nil
5858
}
59-
60-
// getContainersByNameDownlevel performs processing for pre 1.20 APIs. This
61-
// is only relevant on non-Windows daemons.
62-
func getContainersByNameDownlevel(w http.ResponseWriter, s *Server, namevar string) error {
63-
return nil
64-
}

api/types/types.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,24 +274,39 @@ type ContainerJSON struct {
274274
Config *runconfig.Config
275275
}
276276

277-
// ContainerJSONPre120 is a backcompatibility struct along with ContainerConfig.
277+
// ContainerJSON120 is a backcompatibility struct along with ContainerConfig120.
278+
type ContainerJSON120 struct {
279+
*ContainerJSONBase
280+
Mounts []MountPoint
281+
Config *ContainerConfig120
282+
}
283+
284+
// ContainerJSONPre120 is a backcompatibility struct along with ContainerConfigPre120.
278285
// Note this is not used by the Windows daemon.
279286
type ContainerJSONPre120 struct {
280287
*ContainerJSONBase
281288
Volumes map[string]string
282289
VolumesRW map[string]bool
283-
Config *ContainerConfig
290+
Config *ContainerConfigPre120
284291
}
285292

286-
// ContainerConfig is a backcompatibility struct used in ContainerJSONPre120
287-
type ContainerConfig struct {
293+
// ContainerConfigPre120 is a backcompatibility struct used in ContainerJSONPre120
294+
type ContainerConfigPre120 struct {
288295
*runconfig.Config
289296

290297
// backward compatibility, they now live in HostConfig
291-
Memory int64
292-
MemorySwap int64
293-
CPUShares int64 `json:"CpuShares"`
294-
CPUSet string `json:"CpuSet"`
298+
VolumeDriver string
299+
Memory int64
300+
MemorySwap int64
301+
CPUShares int64 `json:"CpuShares"`
302+
CPUSet string `json:"CpuSet"`
303+
}
304+
305+
// ContainerConfig120 is a backcompatibility struct used in ContainerJSON120
306+
type ContainerConfig120 struct {
307+
*runconfig.Config
308+
// backward compatibility, it lives now in HostConfig
309+
VolumeDriver string
295310
}
296311

297312
// MountPoint represents a mount point configuration inside the container.

daemon/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (daemon *Daemon) Create(config *runconfig.Config, hostConfig *runconfig.Hos
106106
}
107107
defer container.Unmount()
108108

109-
if err := createContainerPlatformSpecificSettings(container, config, img); err != nil {
109+
if err := createContainerPlatformSpecificSettings(container, config, hostConfig, img); err != nil {
110110
return nil, nil, err
111111
}
112112

daemon/create_unix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
// createContainerPlatformSpecificSettings performs platform specific container create functionality
19-
func createContainerPlatformSpecificSettings(container *Container, config *runconfig.Config, img *image.Image) error {
19+
func createContainerPlatformSpecificSettings(container *Container, config *runconfig.Config, hostConfig *runconfig.HostConfig, img *image.Image) error {
2020
for spec := range config.Volumes {
2121
var (
2222
name, destination string
@@ -44,7 +44,7 @@ func createContainerPlatformSpecificSettings(container *Container, config *runco
4444
return fmt.Errorf("cannot mount volume over existing file, file exists %s", path)
4545
}
4646

47-
volumeDriver := config.VolumeDriver
47+
volumeDriver := hostConfig.VolumeDriver
4848
if destination != "" && img != nil {
4949
if _, ok := img.ContainerConfig.Volumes[destination]; ok {
5050
// check for whether bind is not specified and then set to local

daemon/create_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ import (
66
)
77

88
// createContainerPlatformSpecificSettings performs platform specific container create functionality
9-
func createContainerPlatformSpecificSettings(container *Container, config *runconfig.Config, img *image.Image) error {
9+
func createContainerPlatformSpecificSettings(container *Container, config *runconfig.Config, hostConfig *runconfig.HostConfig, img *image.Image) error {
1010
return nil
1111
}

daemon/inspect.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,30 @@ func (daemon *Daemon) ContainerInspect(name string) (*types.ContainerJSON, error
2929
return &types.ContainerJSON{base, mountPoints, container.Config}, nil
3030
}
3131

32+
// ContainerInspect120 serializes the master version of a container into a json type.
33+
func (daemon *Daemon) ContainerInspect120(name string) (*types.ContainerJSON120, error) {
34+
container, err := daemon.Get(name)
35+
if err != nil {
36+
return nil, err
37+
}
38+
39+
container.Lock()
40+
defer container.Unlock()
41+
42+
base, err := daemon.getInspectData(container)
43+
if err != nil {
44+
return nil, err
45+
}
46+
47+
mountPoints := addMountPoints(container)
48+
config := &types.ContainerConfig120{
49+
container.Config,
50+
container.hostConfig.VolumeDriver,
51+
}
52+
53+
return &types.ContainerJSON120{base, mountPoints, config}, nil
54+
}
55+
3256
func (daemon *Daemon) getInspectData(container *Container) (*types.ContainerJSONBase, error) {
3357
// make a copy to play with
3458
hostConfig := *container.hostConfig

daemon/inspect_unix.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func setPlatformSpecificContainerFields(container *Container, contJSONBase *type
1414
return contJSONBase
1515
}
1616

17-
// ContainerInspectPre120 is for backwards compatibility with pre v1.20 clients.
17+
// ContainerInspectPre120 gets containers for pre 1.20 APIs.
1818
func (daemon *Daemon) ContainerInspectPre120(name string) (*types.ContainerJSONPre120, error) {
1919
container, err := daemon.Get(name)
2020
if err != nil {
@@ -36,8 +36,9 @@ func (daemon *Daemon) ContainerInspectPre120(name string) (*types.ContainerJSONP
3636
volumesRW[m.Destination] = m.RW
3737
}
3838

39-
config := &types.ContainerConfig{
39+
config := &types.ContainerConfigPre120{
4040
container.Config,
41+
container.hostConfig.VolumeDriver,
4142
container.hostConfig.Memory,
4243
container.hostConfig.MemorySwap,
4344
container.hostConfig.CPUShares,

0 commit comments

Comments
 (0)