15734: Fix InstanceType logging: propagate to detached child.
authorTom Clegg <tclegg@veritasgenetics.com>
Tue, 29 Oct 2019 15:34:49 +0000 (11:34 -0400)
committerTom Clegg <tclegg@veritasgenetics.com>
Tue, 29 Oct 2019 15:34:49 +0000 (11:34 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>

lib/dispatchcloud/worker/runner.go
services/crunch-run/crunchrun.go

index 91db8246012ec62630276c34ba391c5e55609bcf..e819a6036b341d5d2bbe28a242292296b5b36cd2 100644 (file)
@@ -35,11 +35,8 @@ type remoteRunner struct {
 // newRemoteRunner returns a new remoteRunner. Caller should ensure
 // Close() is called to release resources.
 func newRemoteRunner(uuid string, wkr *worker) *remoteRunner {
-       // Early (<1.5) versions of crunch-run error out if they see
-       // non-string values in the env map -- so here we send the
-       // instance type record as a JSON doc. Once worker images are
-       // updated, we can skip the extra encoding, and just include
-       // {"InstanceType": wkr.instType} in the env map.
+       // Send the instance type record as a JSON doc so crunch-run
+       // can log it.
        var instJSON bytes.Buffer
        enc := json.NewEncoder(&instJSON)
        enc.SetIndent("", "    ")
index 082ca0ce9b72e26c26d122555888b3faca7c8d68..d1092e98ef50cd221fdbb9c18df0ad6efe8bdd96 100644 (file)
@@ -116,9 +116,6 @@ type ContainerRunner struct {
        ContainerArvClient  IArvadosClient
        ContainerKeepClient IKeepClient
 
-       // environment provided by arvados-dispatch-cloud
-       dispatchEnv map[string]interface{}
-
        Container       arvados.Container
        ContainerConfig dockercontainer.Config
        HostConfig      dockercontainer.HostConfig
@@ -856,7 +853,7 @@ func (runner *ContainerRunner) LogContainerRecord() error {
 // LogNodeRecord logs the current host's InstanceType config entry (or
 // the arvados#node record, if running via crunch-dispatch-slurm).
 func (runner *ContainerRunner) LogNodeRecord() error {
-       if it, ok := runner.dispatchEnv["InstanceType"]; ok {
+       if it := os.Getenv("InstanceType"); it != "" {
                // Dispatched via arvados-dispatch-cloud. Save
                // InstanceType config fragment received from
                // dispatcher on stdin.
@@ -865,22 +862,9 @@ func (runner *ContainerRunner) LogNodeRecord() error {
                        return err
                }
                defer w.Close()
-               if it, ok := it.(string); ok {
-                       // dispatcher supplied JSON data (in order to
-                       // stay compatible with old crunch-run
-                       // versions)
-                       _, err = io.WriteString(w, it)
-                       if err != nil {
-                               return err
-                       }
-               } else {
-                       // dispatcher supplied struct
-                       enc := json.NewEncoder(w)
-                       enc.SetIndent("", "    ")
-                       err = enc.Encode(it)
-                       if err != nil {
-                               return err
-                       }
+               _, err = io.WriteString(w, it)
+               if err != nil {
+                       return err
                }
                return w.Close()
        } else {
@@ -1811,12 +1795,11 @@ func main() {
 
        flag.Parse()
 
-       var env map[string]interface{}
        if *stdinEnv && !ignoreDetachFlag {
                // Load env vars on stdin if asked (but not in a
                // detached child process, in which case stdin is
                // /dev/null).
-               env = loadEnv(os.Stdin)
+               loadEnv(os.Stdin)
        }
 
        switch {
@@ -1871,8 +1854,6 @@ func main() {
                os.Exit(1)
        }
 
-       cr.dispatchEnv = env
-
        parentTemp, tmperr := cr.MkTempDir("", "crunch-run."+containerId+".")
        if tmperr != nil {
                log.Fatalf("%s: %v", containerId, tmperr)
@@ -1912,23 +1893,20 @@ func main() {
        }
 }
 
-func loadEnv(rdr io.Reader) map[string]interface{} {
+func loadEnv(rdr io.Reader) {
        buf, err := ioutil.ReadAll(rdr)
        if err != nil {
                log.Fatalf("read stdin: %s", err)
        }
-       var env map[string]interface{}
+       var env map[string]string
        err = json.Unmarshal(buf, &env)
        if err != nil {
                log.Fatalf("decode stdin: %s", err)
        }
        for k, v := range env {
-               if v, ok := v.(string); ok {
-                       err = os.Setenv(k, v)
-                       if err != nil {
-                               log.Fatalf("setenv(%q): %s", k, err)
-                       }
+               err = os.Setenv(k, v)
+               if err != nil {
+                       log.Fatalf("setenv(%q): %s", k, err)
                }
        }
-       return env
 }