Skip to content

Commit 63efc12

Browse files
committed
Remove further references to the daemon within containers.
Signed-off-by: David Calavera <david.calavera@gmail.com>
1 parent 444c82d commit 63efc12

15 files changed

+49
-39
lines changed

daemon/archive.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (daemon *Daemon) containerStatPath(container *Container, path string) (stat
142142
}
143143
defer daemon.Unmount(container)
144144

145-
err = container.mountVolumes()
145+
err = daemon.mountVolumes(container)
146146
defer container.unmountVolumes(true)
147147
if err != nil {
148148
return nil, err
@@ -184,7 +184,7 @@ func (daemon *Daemon) containerArchivePath(container *Container, path string) (c
184184
}
185185
}()
186186

187-
if err = container.mountVolumes(); err != nil {
187+
if err = daemon.mountVolumes(container); err != nil {
188188
return nil, nil, err
189189
}
190190

@@ -239,7 +239,7 @@ func (daemon *Daemon) containerExtractToDir(container *Container, path string, n
239239
}
240240
defer daemon.Unmount(container)
241241

242-
err = container.mountVolumes()
242+
err = daemon.mountVolumes(container)
243243
defer container.unmountVolumes(true)
244244
if err != nil {
245245
return err
@@ -348,7 +348,7 @@ func (daemon *Daemon) containerCopy(container *Container, resource string) (rc i
348348
}
349349
}()
350350

351-
if err := container.mountVolumes(); err != nil {
351+
if err := daemon.mountVolumes(container); err != nil {
352352
return nil, err
353353
}
354354

daemon/container.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,8 @@ func (container *Container) shouldRestart() bool {
498498
(container.hostConfig.RestartPolicy.Name == "on-failure" && container.ExitCode != 0)
499499
}
500500

501-
func (container *Container) mountVolumes() error {
502-
mounts, err := container.setupMounts()
501+
func (daemon *Daemon) mountVolumes(container *Container) error {
502+
mounts, err := daemon.setupMounts(container)
503503
if err != nil {
504504
return err
505505
}

daemon/container_unix.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -744,14 +744,14 @@ func (daemon *Daemon) updateNetworkSettings(container *Container, n libnetwork.N
744744
return nil
745745
}
746746

747-
func (container *Container) updateEndpointNetworkSettings(n libnetwork.Network, ep libnetwork.Endpoint) error {
747+
func (daemon *Daemon) updateEndpointNetworkSettings(container *Container, n libnetwork.Network, ep libnetwork.Endpoint) error {
748748
networkSettings, err := container.buildEndpointInfo(n, ep, container.NetworkSettings)
749749
if err != nil {
750750
return err
751751
}
752752

753753
if container.hostConfig.NetworkMode == runconfig.NetworkMode("bridge") {
754-
networkSettings.Bridge = container.daemon.configStore.Bridge.Iface
754+
networkSettings.Bridge = daemon.configStore.Bridge.Iface
755755
}
756756

757757
return nil
@@ -1006,7 +1006,7 @@ func (daemon *Daemon) connectToNetwork(container *Container, idOrName string, up
10061006
}
10071007
}()
10081008

1009-
if err := container.updateEndpointNetworkSettings(n, ep); err != nil {
1009+
if err := daemon.updateEndpointNetworkSettings(container, n, ep); err != nil {
10101010
return err
10111011
}
10121012

@@ -1075,13 +1075,13 @@ func (daemon *Daemon) initializeNetworking(container *Container) error {
10751075

10761076
// called from the libcontainer pre-start hook to set the network
10771077
// namespace configuration linkage to the libnetwork "sandbox" entity
1078-
func (daemon *Daemon) setNetworkNamespaceKey(containerId string, pid int) error {
1078+
func (daemon *Daemon) setNetworkNamespaceKey(containerID string, pid int) error {
10791079
path := fmt.Sprintf("/proc/%d/ns/net", pid)
10801080
var sandbox libnetwork.Sandbox
1081-
search := libnetwork.SandboxContainerWalker(&sandbox, containerId)
1081+
search := libnetwork.SandboxContainerWalker(&sandbox, containerID)
10821082
daemon.netController.WalkSandboxes(search)
10831083
if sandbox == nil {
1084-
return derr.ErrorCodeNoSandbox.WithArgs(containerId)
1084+
return derr.ErrorCodeNoSandbox.WithArgs(containerID)
10851085
}
10861086

10871087
return sandbox.SetKey(path)
@@ -1126,16 +1126,16 @@ func (container *Container) setupWorkingDirectory() error {
11261126
return nil
11271127
}
11281128

1129-
func (daemon *Daemon) getNetworkedContainer(containerId, connectedContainerId string) (*Container, error) {
1130-
nc, err := daemon.Get(connectedContainerId)
1129+
func (daemon *Daemon) getNetworkedContainer(containerID, connectedContainerID string) (*Container, error) {
1130+
nc, err := daemon.Get(connectedContainerID)
11311131
if err != nil {
11321132
return nil, err
11331133
}
1134-
if containerId == nc.ID {
1134+
if containerID == nc.ID {
11351135
return nil, derr.ErrorCodeJoinSelf
11361136
}
11371137
if !nc.IsRunning() {
1138-
return nil, derr.ErrorCodeJoinRunning.WithArgs(connectedContainerId)
1138+
return nil, derr.ErrorCodeJoinRunning.WithArgs(connectedContainerID)
11391139
}
11401140
return nc, nil
11411141
}

daemon/container_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (daemon *Daemon) getSize(container *Container) (int64, int64) {
149149
}
150150

151151
// setNetworkNamespaceKey is a no-op on Windows.
152-
func (daemon *Daemon) setNetworkNamespaceKey(containerId string, pid int) error {
152+
func (daemon *Daemon) setNetworkNamespaceKey(containerID string, pid int) error {
153153
return nil
154154
}
155155

daemon/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (daemon *Daemon) create(params *ContainerCreateConfig) (retC *Container, re
119119
}
120120
defer daemon.Unmount(container)
121121

122-
if err := createContainerPlatformSpecificSettings(container, params.Config, params.HostConfig, img); err != nil {
122+
if err := daemon.createContainerPlatformSpecificSettings(container, params.Config, params.HostConfig, img); err != nil {
123123
return nil, err
124124
}
125125

daemon/create_unix.go

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

1717
// createContainerPlatformSpecificSettings performs platform specific container create functionality
18-
func createContainerPlatformSpecificSettings(container *Container, config *runconfig.Config, hostConfig *runconfig.HostConfig, img *image.Image) error {
18+
func (daemon *Daemon) createContainerPlatformSpecificSettings(container *Container, config *runconfig.Config, hostConfig *runconfig.HostConfig, img *image.Image) error {
1919
for spec := range config.Volumes {
2020
name := stringid.GenerateNonCryptoID()
2121
destination := filepath.Clean(spec)
@@ -45,7 +45,7 @@ func createContainerPlatformSpecificSettings(container *Container, config *runco
4545
}
4646
}
4747

48-
v, err := container.daemon.createVolume(name, volumeDriver, nil)
48+
v, err := daemon.createVolume(name, volumeDriver, nil)
4949
if err != nil {
5050
return err
5151
}

daemon/create_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
// createContainerPlatformSpecificSettings performs platform specific container create functionality
13-
func createContainerPlatformSpecificSettings(container *Container, config *runconfig.Config, hostConfig *runconfig.HostConfig, img *image.Image) error {
13+
func (daemon *Daemon) createContainerPlatformSpecificSettings(container *Container, config *runconfig.Config, hostConfig *runconfig.HostConfig, img *image.Image) error {
1414
for spec := range config.Volumes {
1515

1616
mp, err := volume.ParseMountSpec(spec, hostConfig.VolumeDriver)
@@ -41,7 +41,7 @@ func createContainerPlatformSpecificSettings(container *Container, config *runco
4141

4242
// Create the volume in the volume driver. If it doesn't exist,
4343
// a new one will be created.
44-
v, err := container.daemon.createVolume(mp.Name, volumeDriver, nil)
44+
v, err := daemon.createVolume(mp.Name, volumeDriver, nil)
4545
if err != nil {
4646
return err
4747
}

daemon/daemon.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (daemon *Daemon) load(id string) (*Container, error) {
194194

195195
// Register makes a container object usable by the daemon as <container.ID>
196196
func (daemon *Daemon) Register(container *Container) error {
197-
if container.daemon != nil || daemon.Exists(container.ID) {
197+
if daemon.Exists(container.ID) {
198198
return fmt.Errorf("Container is already loaded")
199199
}
200200
if err := validateID(container.ID); err != nil {
@@ -204,8 +204,6 @@ func (daemon *Daemon) Register(container *Container) error {
204204
return err
205205
}
206206

207-
container.daemon = daemon
208-
209207
// Attach to stdout and stderr
210208
container.stderr = new(broadcaster.Unbuffered)
211209
container.stdout = new(broadcaster.Unbuffered)
@@ -954,7 +952,8 @@ func (daemon *Daemon) Unmount(container *Container) error {
954952
return daemon.driver.Put(container.ID)
955953
}
956954

957-
func (daemon *Daemon) run(c *Container, pipes *execdriver.Pipes, startCallback execdriver.DriverCallback) (execdriver.ExitStatus, error) {
955+
// Run uses the execution driver to run a given container
956+
func (daemon *Daemon) Run(c *Container, pipes *execdriver.Pipes, startCallback execdriver.DriverCallback) (execdriver.ExitStatus, error) {
958957
hooks := execdriver.Hooks{
959958
Start: startCallback,
960959
}
@@ -1303,6 +1302,12 @@ func (daemon *Daemon) SearchRegistryForImages(term string,
13031302
return daemon.RegistryService.Search(term, authConfig, headers)
13041303
}
13051304

1305+
// IsShuttingDown tells whether the daemon is shutting down or not
1306+
func (daemon *Daemon) IsShuttingDown() bool {
1307+
return daemon.shutdown
1308+
}
1309+
1310+
// GetContainerStats collects all the stats published by a container
13061311
func (daemon *Daemon) GetContainerStats(container *Container) (*execdriver.ResourceStats, error) {
13071312
stats, err := daemon.stats(container)
13081313
if err != nil {

daemon/exec.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ func (d *Daemon) containerExecIds() map[string]struct{} {
331331
return ids
332332
}
333333

334-
func (daemon *Daemon) containerExec(container *Container, ec *ExecConfig) error {
334+
func (d *Daemon) containerExec(container *Container, ec *ExecConfig) error {
335335
container.Lock()
336336
defer container.Unlock()
337337

@@ -350,7 +350,7 @@ func (daemon *Daemon) containerExec(container *Container, ec *ExecConfig) error
350350

351351
// We use a callback here instead of a goroutine and an chan for
352352
// synchronization purposes
353-
cErr := promise.Go(func() error { return daemon.monitorExec(container, ec, callback) })
353+
cErr := promise.Go(func() error { return d.monitorExec(container, ec, callback) })
354354

355355
// Exec should not return until the process is actually running
356356
select {
@@ -362,13 +362,13 @@ func (daemon *Daemon) containerExec(container *Container, ec *ExecConfig) error
362362
return nil
363363
}
364364

365-
func (daemon *Daemon) monitorExec(container *Container, ExecConfig *ExecConfig, callback execdriver.DriverCallback) error {
365+
func (d *Daemon) monitorExec(container *Container, ExecConfig *ExecConfig, callback execdriver.DriverCallback) error {
366366
var (
367367
err error
368368
exitCode int
369369
)
370370
pipes := execdriver.NewPipes(ExecConfig.streamConfig.stdin, ExecConfig.streamConfig.stdout, ExecConfig.streamConfig.stderr, ExecConfig.OpenStdin)
371-
exitCode, err = daemon.Exec(container, ExecConfig, pipes, callback)
371+
exitCode, err = d.Exec(container, ExecConfig, pipes, callback)
372372
if err != nil {
373373
logrus.Errorf("Error running command in existing container %s: %s", container.ID, err)
374374
}

daemon/monitor.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ type containerSupervisor interface {
2525
Cleanup(*Container)
2626
// StartLogging starts the logging driver for the container
2727
StartLogging(*Container) error
28+
// Run starts a container
29+
Run(c *Container, pipes *execdriver.Pipes, startCallback execdriver.DriverCallback) (execdriver.ExitStatus, error)
30+
// IsShuttingDown tells whether the supervisor is shutting down or not
31+
IsShuttingDown() bool
2832
}
2933

3034
// containerMonitor monitors the execution of a container's main process.
@@ -156,7 +160,7 @@ func (m *containerMonitor) Start() error {
156160

157161
m.lastStartTime = time.Now()
158162

159-
if exitStatus, err = m.container.daemon.run(m.container, pipes, m.callback); err != nil {
163+
if exitStatus, err = m.supervisor.Run(m.container, pipes, m.callback); err != nil {
160164
// if we receive an internal error from the initial start of a container then lets
161165
// return it instead of entering the restart loop
162166
if m.container.RestartCount == 0 {
@@ -236,7 +240,7 @@ func (m *containerMonitor) shouldRestart(exitCode int) bool {
236240

237241
// do not restart if the user or docker has requested that this container be stopped
238242
if m.shouldStop {
239-
m.container.HasBeenManuallyStopped = !m.container.daemon.shutdown
243+
m.container.HasBeenManuallyStopped = !m.supervisor.IsShuttingDown()
240244
return false
241245
}
242246

0 commit comments

Comments
 (0)