Skip to content

Commit 818a519

Browse files
committedApr 6, 2016
Adding postRunProcessing infrastructure for hanlding Windows Update.
Signed-off-by: Stefan J. Wernli <[email protected]>
1 parent 8eb8a1d commit 818a519

11 files changed

+82
-29
lines changed
 

‎daemon/monitor.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ func (daemon *Daemon) StateChanged(id string, e libcontainerd.StateInfo) error {
4040
// FIXME: here is race condition between two RUN instructions in Dockerfile
4141
// because they share same runconfig and change image. Must be fixed
4242
// in builder/builder.go
43-
return c.ToDisk()
43+
if err := c.ToDisk(); err != nil {
44+
return err
45+
}
46+
return daemon.postRunProcessing(c, e)
4447
case libcontainerd.StateRestart:
4548
c.Lock()
4649
defer c.Unlock()
@@ -51,7 +54,10 @@ func (daemon *Daemon) StateChanged(id string, e libcontainerd.StateInfo) error {
5154
"exitCode": strconv.Itoa(int(e.ExitCode)),
5255
}
5356
daemon.LogContainerEventWithAttributes(c, "die", attributes)
54-
return c.ToDisk()
57+
if err := c.ToDisk(); err != nil {
58+
return err
59+
}
60+
return daemon.postRunProcessing(c, e)
5561
case libcontainerd.StateExitProcess:
5662
c.Lock()
5763
defer c.Unlock()

‎daemon/monitor_linux.go

+5
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ func platformConstructExitStatus(e libcontainerd.StateInfo) *container.ExitStatu
1212
OOMKilled: e.OOMKilled,
1313
}
1414
}
15+
16+
// postRunProcessing perfoms any processing needed on the container after it has stopped.
17+
func (daemon *Daemon) postRunProcessing(container *container.Container, e libcontainerd.StateInfo) error {
18+
return nil
19+
}

‎daemon/monitor_windows.go

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package daemon
22

33
import (
4+
"fmt"
5+
46
"github.com/docker/docker/container"
57
"github.com/docker/docker/libcontainerd"
68
)
@@ -11,3 +13,12 @@ func platformConstructExitStatus(e libcontainerd.StateInfo) *container.ExitStatu
1113
ExitCode: int(e.ExitCode),
1214
}
1315
}
16+
17+
// postRunProcessing perfoms any processing needed on the container after it has stopped.
18+
func (daemon *Daemon) postRunProcessing(container *container.Container, e libcontainerd.StateInfo) error {
19+
//TODO Windows - handle update processing here...
20+
if e.UpdatePending {
21+
return fmt.Errorf("Windows: Update handling not implemented.")
22+
}
23+
return nil
24+
}

‎libcontainerd/client_linux.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,10 @@ func (clnt *client) setExited(containerID string) error {
269269
}
270270

271271
err := clnt.backend.StateChanged(containerID, StateInfo{
272-
State: StateExit,
273-
ExitCode: exitCode,
274-
})
272+
CommonStateInfo: CommonStateInfo{
273+
State: StateExit,
274+
ExitCode: exitCode,
275+
}})
275276

276277
// Unmount and delete the bundle folder
277278
if mts, err := mount.GetMounts(); err == nil {

‎libcontainerd/client_liverestore_linux.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ func (clnt *client) restore(cont *containerd.Container, options ...CreateOption)
4848
clnt.appendContainer(container)
4949

5050
err = clnt.backend.StateChanged(containerID, StateInfo{
51-
State: StateRestore,
52-
Pid: container.systemPid,
53-
})
51+
CommonStateInfo: CommonStateInfo{
52+
State: StateRestore,
53+
Pid: container.systemPid,
54+
}})
5455

5556
if err != nil {
5657
return err
@@ -60,9 +61,10 @@ func (clnt *client) restore(cont *containerd.Container, options ...CreateOption)
6061
// This should only be a pause or resume event
6162
if event.Type == StatePause || event.Type == StateResume {
6263
return clnt.backend.StateChanged(containerID, StateInfo{
63-
State: event.Type,
64-
Pid: container.systemPid,
65-
})
64+
CommonStateInfo: CommonStateInfo{
65+
State: event.Type,
66+
Pid: container.systemPid,
67+
}})
6668
}
6769

6870
logrus.Warnf("unexpected backlog event: %#v", event)

‎libcontainerd/client_windows.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,10 @@ func (clnt *client) Restore(containerID string, unusedOnWindows ...CreateOption)
505505
// TODO Windows: Implement this. For now, just tell the backend the container exited.
506506
logrus.Debugf("lcd Restore %s", containerID)
507507
return clnt.backend.StateChanged(containerID, StateInfo{
508-
State: StateExit,
509-
ExitCode: 1 << 31,
510-
})
508+
CommonStateInfo: CommonStateInfo{
509+
State: StateExit,
510+
ExitCode: 1 << 31,
511+
}})
511512
}
512513

513514
// GetPidsForContainer returns a list of process IDs running in a container.

‎libcontainerd/container_linux.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ func (ctr *container) start() error {
8181
ctr.systemPid = systemPid(resp.Container)
8282

8383
return ctr.client.backend.StateChanged(ctr.containerID, StateInfo{
84-
State: StateStart,
85-
Pid: ctr.systemPid,
86-
})
84+
CommonStateInfo: CommonStateInfo{
85+
State: StateStart,
86+
Pid: ctr.systemPid,
87+
}})
8788
}
8889

8990
func (ctr *container) newProcess(friendlyName string) *process {
@@ -103,8 +104,10 @@ func (ctr *container) handleEvent(e *containerd.Event) error {
103104
switch e.Type {
104105
case StateExit, StatePause, StateResume, StateOOM:
105106
st := StateInfo{
106-
State: e.Type,
107-
ExitCode: e.Status,
107+
CommonStateInfo: CommonStateInfo{
108+
State: e.Type,
109+
ExitCode: e.Status,
110+
},
108111
OOMKilled: e.Type == StateExit && ctr.oom,
109112
}
110113
if e.Type == StateOOM {

‎libcontainerd/container_windows.go

+16-7
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ func (ctr *container) start() error {
103103

104104
// Tell the docker engine that the container has started.
105105
si := StateInfo{
106-
State: StateStart,
107-
Pid: ctr.systemPid, // Not sure this is needed? Double-check monitor.go in daemon BUGBUG @jhowardmsft
108-
}
106+
CommonStateInfo: CommonStateInfo{
107+
State: StateStart,
108+
Pid: ctr.systemPid, // Not sure this is needed? Double-check monitor.go in daemon BUGBUG @jhowardmsft
109+
}}
109110
return ctr.client.backend.StateChanged(ctr.containerID, si)
110111

111112
}
@@ -129,10 +130,13 @@ func (ctr *container) waitExit(pid uint32, processFriendlyName string, isFirstPr
129130

130131
// Assume the container has exited
131132
si := StateInfo{
132-
State: StateExit,
133-
ExitCode: uint32(exitCode),
134-
Pid: pid,
135-
ProcessID: processFriendlyName,
133+
CommonStateInfo: CommonStateInfo{
134+
State: StateExit,
135+
ExitCode: uint32(exitCode),
136+
Pid: pid,
137+
ProcessID: processFriendlyName,
138+
},
139+
UpdatePending: false,
136140
}
137141

138142
// But it could have been an exec'd process which exited
@@ -143,6 +147,11 @@ func (ctr *container) waitExit(pid uint32, processFriendlyName string, isFirstPr
143147
// If this is the init process, always call into vmcompute.dll to
144148
// shutdown the container after we have completed.
145149
if isFirstProcessToStart {
150+
151+
// TODO Windows - add call into hcsshim to check if an update
152+
// is pending once that is available.
153+
//si.UpdatePending = CHECK IF UPDATE NEEDED
154+
146155
logrus.Debugf("Shutting down container %s", ctr.containerID)
147156
// Explicit timeout here rather than hcsshim.TimeoutInfinte to avoid a
148157
// (remote) possibility that ShutdownComputeSystem hangs indefinitely.

‎libcontainerd/types.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ const (
1616
stateLive = "live"
1717
)
1818

19-
// StateInfo contains description about the new state container has entered.
20-
type StateInfo struct { // FIXME: event?
19+
// CommonStateInfo contains the state info common to all platforms.
20+
type CommonStateInfo struct { // FIXME: event?
2121
State string
2222
Pid uint32
2323
ExitCode uint32
2424
ProcessID string
25-
OOMKilled bool // TODO Windows containerd factor out
2625
}
2726

2827
// Backend defines callbacks that the client of the library needs to implement.

‎libcontainerd/types_linux.go

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ type Process struct {
3333
SelinuxLabel *string `json:"selinuxLabel,omitempty"`
3434
}
3535

36+
// StateInfo contains description about the new state container has entered.
37+
type StateInfo struct {
38+
CommonStateInfo
39+
40+
// Platform specific StateInfo
41+
OOMKilled bool
42+
}
43+
3644
// Stats contains a stats properties from containerd.
3745
type Stats containerd.StatsResponse
3846

‎libcontainerd/types_windows.go

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ type Summary struct {
1717
Command string
1818
}
1919

20+
// StateInfo contains description about the new state container has entered.
21+
type StateInfo struct {
22+
CommonStateInfo
23+
24+
// Platform specific StateInfo
25+
UpdatePending bool
26+
}
27+
2028
// Stats contains a stats properties from containerd.
2129
type Stats struct{}
2230

0 commit comments

Comments
 (0)
Please sign in to comment.