Преглед изворни кода

LCOW: Add GCS debugging

Signed-off-by: John Howard <jhoward@microsoft.com>
John Howard пре 7 година
родитељ
комит
5a0e2beac3
3 измењених фајлова са 28 додато и 1 уклоњено
  1. 5 0
      libcontainerd/client_windows.go
  2. 5 0
      libcontainerd/container_windows.go
  3. 18 1
      libcontainerd/utils_windows.go

+ 5 - 0
libcontainerd/client_windows.go

@@ -439,6 +439,11 @@ func (clnt *client) AddProcess(ctx context.Context, containerID, processFriendly
 	if err != nil {
 		return -1, err
 	}
+
+	defer func() {
+		container.debugGCS()
+	}()
+
 	// Note we always tell HCS to
 	// create stdout as it's required regardless of '-i' or '-t' options, so that
 	// docker can always grab the output through logs. We also tell HCS to always

+ 5 - 0
libcontainerd/container_windows.go

@@ -50,6 +50,7 @@ func (ctr *container) start(attachStdio StdioCallback) error {
 	logrus.Debugln("libcontainerd: starting container ", ctr.containerID)
 	if err = ctr.hcsContainer.Start(); err != nil {
 		logrus.Errorf("libcontainerd: failed to start container: %s", err)
+		ctr.debugGCS() // Before terminating!
 		if err := ctr.terminate(); err != nil {
 			logrus.Errorf("libcontainerd: failed to cleanup after a failed Start. %s", err)
 		} else {
@@ -58,6 +59,10 @@ func (ctr *container) start(attachStdio StdioCallback) error {
 		return err
 	}
 
+	defer func() {
+		ctr.debugGCS()
+	}()
+
 	// Note we always tell HCS to
 	// create stdout as it's required regardless of '-i' or '-t' options, so that
 	// docker can always grab the output through logs. We also tell HCS to always

+ 18 - 1
libcontainerd/utils_windows.go

@@ -1,6 +1,10 @@
 package libcontainerd
 
-import "strings"
+import (
+	"strings"
+
+	opengcs "github.com/Microsoft/opengcs/client"
+)
 
 // setupEnvironmentVariables converts a string array of environment variables
 // into a map as required by the HCS. Source array is in format [v1=k1] [v2=k2] etc.
@@ -19,3 +23,16 @@ func setupEnvironmentVariables(a []string) map[string]string {
 func (s *LCOWOption) Apply(interface{}) error {
 	return nil
 }
+
+// DebugGCS is a dirty hack for debugging for Linux Utility VMs. It simply
+// runs a bunch of commands inside the UVM, but seriously aides in advanced debugging.
+func (c *container) debugGCS() {
+	if c == nil || c.isWindows || c.hcsContainer == nil {
+		return
+	}
+	cfg := opengcs.Config{
+		Uvm:               c.hcsContainer,
+		UvmTimeoutSeconds: 600,
+	}
+	cfg.DebugGCS()
+}