From f5f4c5f6088707c86c43ca2bd70a70c14699e450 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Tue, 29 Oct 2019 11:34:49 -0400 Subject: [PATCH] 15734: Fix InstanceType logging: propagate to detached child. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- lib/dispatchcloud/worker/runner.go | 7 ++--- services/crunch-run/crunchrun.go | 42 +++++++----------------------- 2 files changed, 12 insertions(+), 37 deletions(-) diff --git a/lib/dispatchcloud/worker/runner.go b/lib/dispatchcloud/worker/runner.go index 91db824601..e819a6036b 100644 --- a/lib/dispatchcloud/worker/runner.go +++ b/lib/dispatchcloud/worker/runner.go @@ -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("", " ") diff --git a/services/crunch-run/crunchrun.go b/services/crunch-run/crunchrun.go index 082ca0ce9b..d1092e98ef 100644 --- a/services/crunch-run/crunchrun.go +++ b/services/crunch-run/crunchrun.go @@ -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 } -- 2.30.2