Bladeren bron

Adding postRunProcessing infrastructure for hanlding Windows Update.

Signed-off-by: Stefan J. Wernli <swernli@microsoft.com>
Stefan J. Wernli 9 jaren geleden
bovenliggende
commit
818a5198e4

+ 8 - 2
daemon/monitor.go

@@ -40,7 +40,10 @@ func (daemon *Daemon) StateChanged(id string, e libcontainerd.StateInfo) error {
 		// FIXME: here is race condition between two RUN instructions in Dockerfile
 		// FIXME: here is race condition between two RUN instructions in Dockerfile
 		// because they share same runconfig and change image. Must be fixed
 		// because they share same runconfig and change image. Must be fixed
 		// in builder/builder.go
 		// in builder/builder.go
-		return c.ToDisk()
+		if err := c.ToDisk(); err != nil {
+			return err
+		}
+		return daemon.postRunProcessing(c, e)
 	case libcontainerd.StateRestart:
 	case libcontainerd.StateRestart:
 		c.Lock()
 		c.Lock()
 		defer c.Unlock()
 		defer c.Unlock()
@@ -51,7 +54,10 @@ func (daemon *Daemon) StateChanged(id string, e libcontainerd.StateInfo) error {
 			"exitCode": strconv.Itoa(int(e.ExitCode)),
 			"exitCode": strconv.Itoa(int(e.ExitCode)),
 		}
 		}
 		daemon.LogContainerEventWithAttributes(c, "die", attributes)
 		daemon.LogContainerEventWithAttributes(c, "die", attributes)
-		return c.ToDisk()
+		if err := c.ToDisk(); err != nil {
+			return err
+		}
+		return daemon.postRunProcessing(c, e)
 	case libcontainerd.StateExitProcess:
 	case libcontainerd.StateExitProcess:
 		c.Lock()
 		c.Lock()
 		defer c.Unlock()
 		defer c.Unlock()

+ 5 - 0
daemon/monitor_linux.go

@@ -12,3 +12,8 @@ func platformConstructExitStatus(e libcontainerd.StateInfo) *container.ExitStatu
 		OOMKilled: e.OOMKilled,
 		OOMKilled: e.OOMKilled,
 	}
 	}
 }
 }
+
+// postRunProcessing perfoms any processing needed on the container after it has stopped.
+func (daemon *Daemon) postRunProcessing(container *container.Container, e libcontainerd.StateInfo) error {
+	return nil
+}

+ 11 - 0
daemon/monitor_windows.go

@@ -1,6 +1,8 @@
 package daemon
 package daemon
 
 
 import (
 import (
+	"fmt"
+
 	"github.com/docker/docker/container"
 	"github.com/docker/docker/container"
 	"github.com/docker/docker/libcontainerd"
 	"github.com/docker/docker/libcontainerd"
 )
 )
@@ -11,3 +13,12 @@ func platformConstructExitStatus(e libcontainerd.StateInfo) *container.ExitStatu
 		ExitCode: int(e.ExitCode),
 		ExitCode: int(e.ExitCode),
 	}
 	}
 }
 }
+
+// postRunProcessing perfoms any processing needed on the container after it has stopped.
+func (daemon *Daemon) postRunProcessing(container *container.Container, e libcontainerd.StateInfo) error {
+	//TODO Windows - handle update processing here...
+	if e.UpdatePending {
+		return fmt.Errorf("Windows: Update handling not implemented.")
+	}
+	return nil
+}

+ 4 - 3
libcontainerd/client_linux.go

@@ -269,9 +269,10 @@ func (clnt *client) setExited(containerID string) error {
 	}
 	}
 
 
 	err := clnt.backend.StateChanged(containerID, StateInfo{
 	err := clnt.backend.StateChanged(containerID, StateInfo{
-		State:    StateExit,
-		ExitCode: exitCode,
-	})
+		CommonStateInfo: CommonStateInfo{
+			State:    StateExit,
+			ExitCode: exitCode,
+		}})
 
 
 	// Unmount and delete the bundle folder
 	// Unmount and delete the bundle folder
 	if mts, err := mount.GetMounts(); err == nil {
 	if mts, err := mount.GetMounts(); err == nil {

+ 8 - 6
libcontainerd/client_liverestore_linux.go

@@ -48,9 +48,10 @@ func (clnt *client) restore(cont *containerd.Container, options ...CreateOption)
 	clnt.appendContainer(container)
 	clnt.appendContainer(container)
 
 
 	err = clnt.backend.StateChanged(containerID, StateInfo{
 	err = clnt.backend.StateChanged(containerID, StateInfo{
-		State: StateRestore,
-		Pid:   container.systemPid,
-	})
+		CommonStateInfo: CommonStateInfo{
+			State: StateRestore,
+			Pid:   container.systemPid,
+		}})
 
 
 	if err != nil {
 	if err != nil {
 		return err
 		return err
@@ -60,9 +61,10 @@ func (clnt *client) restore(cont *containerd.Container, options ...CreateOption)
 		// This should only be a pause or resume event
 		// This should only be a pause or resume event
 		if event.Type == StatePause || event.Type == StateResume {
 		if event.Type == StatePause || event.Type == StateResume {
 			return clnt.backend.StateChanged(containerID, StateInfo{
 			return clnt.backend.StateChanged(containerID, StateInfo{
-				State: event.Type,
-				Pid:   container.systemPid,
-			})
+				CommonStateInfo: CommonStateInfo{
+					State: event.Type,
+					Pid:   container.systemPid,
+				}})
 		}
 		}
 
 
 		logrus.Warnf("unexpected backlog event: %#v", event)
 		logrus.Warnf("unexpected backlog event: %#v", event)

+ 4 - 3
libcontainerd/client_windows.go

@@ -505,9 +505,10 @@ func (clnt *client) Restore(containerID string, unusedOnWindows ...CreateOption)
 	// TODO Windows: Implement this. For now, just tell the backend the container exited.
 	// TODO Windows: Implement this. For now, just tell the backend the container exited.
 	logrus.Debugf("lcd Restore %s", containerID)
 	logrus.Debugf("lcd Restore %s", containerID)
 	return clnt.backend.StateChanged(containerID, StateInfo{
 	return clnt.backend.StateChanged(containerID, StateInfo{
-		State:    StateExit,
-		ExitCode: 1 << 31,
-	})
+		CommonStateInfo: CommonStateInfo{
+			State:    StateExit,
+			ExitCode: 1 << 31,
+		}})
 }
 }
 
 
 // GetPidsForContainer returns a list of process IDs running in a container.
 // GetPidsForContainer returns a list of process IDs running in a container.

+ 8 - 5
libcontainerd/container_linux.go

@@ -81,9 +81,10 @@ func (ctr *container) start() error {
 	ctr.systemPid = systemPid(resp.Container)
 	ctr.systemPid = systemPid(resp.Container)
 
 
 	return ctr.client.backend.StateChanged(ctr.containerID, StateInfo{
 	return ctr.client.backend.StateChanged(ctr.containerID, StateInfo{
-		State: StateStart,
-		Pid:   ctr.systemPid,
-	})
+		CommonStateInfo: CommonStateInfo{
+			State: StateStart,
+			Pid:   ctr.systemPid,
+		}})
 }
 }
 
 
 func (ctr *container) newProcess(friendlyName string) *process {
 func (ctr *container) newProcess(friendlyName string) *process {
@@ -103,8 +104,10 @@ func (ctr *container) handleEvent(e *containerd.Event) error {
 	switch e.Type {
 	switch e.Type {
 	case StateExit, StatePause, StateResume, StateOOM:
 	case StateExit, StatePause, StateResume, StateOOM:
 		st := StateInfo{
 		st := StateInfo{
-			State:     e.Type,
-			ExitCode:  e.Status,
+			CommonStateInfo: CommonStateInfo{
+				State:    e.Type,
+				ExitCode: e.Status,
+			},
 			OOMKilled: e.Type == StateExit && ctr.oom,
 			OOMKilled: e.Type == StateExit && ctr.oom,
 		}
 		}
 		if e.Type == StateOOM {
 		if e.Type == StateOOM {

+ 16 - 7
libcontainerd/container_windows.go

@@ -103,9 +103,10 @@ func (ctr *container) start() error {
 
 
 	// Tell the docker engine that the container has started.
 	// Tell the docker engine that the container has started.
 	si := StateInfo{
 	si := StateInfo{
-		State: StateStart,
-		Pid:   ctr.systemPid, // Not sure this is needed? Double-check monitor.go in daemon BUGBUG @jhowardmsft
-	}
+		CommonStateInfo: CommonStateInfo{
+			State: StateStart,
+			Pid:   ctr.systemPid, // Not sure this is needed? Double-check monitor.go in daemon BUGBUG @jhowardmsft
+		}}
 	return ctr.client.backend.StateChanged(ctr.containerID, si)
 	return ctr.client.backend.StateChanged(ctr.containerID, si)
 
 
 }
 }
@@ -129,10 +130,13 @@ func (ctr *container) waitExit(pid uint32, processFriendlyName string, isFirstPr
 
 
 	// Assume the container has exited
 	// Assume the container has exited
 	si := StateInfo{
 	si := StateInfo{
-		State:     StateExit,
-		ExitCode:  uint32(exitCode),
-		Pid:       pid,
-		ProcessID: processFriendlyName,
+		CommonStateInfo: CommonStateInfo{
+			State:     StateExit,
+			ExitCode:  uint32(exitCode),
+			Pid:       pid,
+			ProcessID: processFriendlyName,
+		},
+		UpdatePending: false,
 	}
 	}
 
 
 	// But it could have been an exec'd process which exited
 	// But it could have been an exec'd process which exited
@@ -143,6 +147,11 @@ func (ctr *container) waitExit(pid uint32, processFriendlyName string, isFirstPr
 	// If this is the init process, always call into vmcompute.dll to
 	// If this is the init process, always call into vmcompute.dll to
 	// shutdown the container after we have completed.
 	// shutdown the container after we have completed.
 	if isFirstProcessToStart {
 	if isFirstProcessToStart {
+
+		// TODO Windows - add call into hcsshim to check if an update
+		// is pending once that is available.
+		//si.UpdatePending = CHECK IF UPDATE NEEDED
+
 		logrus.Debugf("Shutting down container %s", ctr.containerID)
 		logrus.Debugf("Shutting down container %s", ctr.containerID)
 		// Explicit timeout here rather than hcsshim.TimeoutInfinte to avoid a
 		// Explicit timeout here rather than hcsshim.TimeoutInfinte to avoid a
 		// (remote) possibility that ShutdownComputeSystem hangs indefinitely.
 		// (remote) possibility that ShutdownComputeSystem hangs indefinitely.

+ 2 - 3
libcontainerd/types.go

@@ -16,13 +16,12 @@ const (
 	stateLive         = "live"
 	stateLive         = "live"
 )
 )
 
 
-// StateInfo contains description about the new state container has entered.
-type StateInfo struct { // FIXME: event?
+// CommonStateInfo contains the state info common to all platforms.
+type CommonStateInfo struct { // FIXME: event?
 	State     string
 	State     string
 	Pid       uint32
 	Pid       uint32
 	ExitCode  uint32
 	ExitCode  uint32
 	ProcessID string
 	ProcessID string
-	OOMKilled bool // TODO Windows containerd factor out
 }
 }
 
 
 // Backend defines callbacks that the client of the library needs to implement.
 // Backend defines callbacks that the client of the library needs to implement.

+ 8 - 0
libcontainerd/types_linux.go

@@ -33,6 +33,14 @@ type Process struct {
 	SelinuxLabel *string `json:"selinuxLabel,omitempty"`
 	SelinuxLabel *string `json:"selinuxLabel,omitempty"`
 }
 }
 
 
+// StateInfo contains description about the new state container has entered.
+type StateInfo struct {
+	CommonStateInfo
+
+	// Platform specific StateInfo
+	OOMKilled bool
+}
+
 // Stats contains a stats properties from containerd.
 // Stats contains a stats properties from containerd.
 type Stats containerd.StatsResponse
 type Stats containerd.StatsResponse
 
 

+ 8 - 0
libcontainerd/types_windows.go

@@ -17,6 +17,14 @@ type Summary struct {
 	Command string
 	Command string
 }
 }
 
 
+// StateInfo contains description about the new state container has entered.
+type StateInfo struct {
+	CommonStateInfo
+
+	// Platform specific StateInfo
+	UpdatePending bool
+}
+
 // Stats contains a stats properties from containerd.
 // Stats contains a stats properties from containerd.
 type Stats struct{}
 type Stats struct{}