Merge branch '15305-keep-balance-bytes'
[arvados.git] / lib / dispatchcloud / worker / runner.go
index c30ff9f2b7608410bbcf3450c62708fa3e5e2d09..e819a6036b341d5d2bbe28a242292296b5b36cd2 100644 (file)
@@ -11,7 +11,6 @@ import (
        "syscall"
        "time"
 
-       "git.curoverse.com/arvados.git/sdk/go/arvados"
        "github.com/sirupsen/logrus"
 )
 
@@ -20,7 +19,7 @@ import (
 type remoteRunner struct {
        uuid          string
        executor      Executor
-       arvClient     *arvados.Client
+       envJSON       json.RawMessage
        remoteUser    string
        timeoutTERM   time.Duration
        timeoutSignal time.Duration
@@ -36,10 +35,30 @@ type remoteRunner struct {
 // newRemoteRunner returns a new remoteRunner. Caller should ensure
 // Close() is called to release resources.
 func newRemoteRunner(uuid string, wkr *worker) *remoteRunner {
+       // 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("", "    ")
+       if err := enc.Encode(wkr.instType); err != nil {
+               panic(err)
+       }
+       env := map[string]string{
+               "ARVADOS_API_HOST":  wkr.wp.arvClient.APIHost,
+               "ARVADOS_API_TOKEN": wkr.wp.arvClient.AuthToken,
+               "InstanceType":      instJSON.String(),
+       }
+       if wkr.wp.arvClient.Insecure {
+               env["ARVADOS_API_HOST_INSECURE"] = "1"
+       }
+       envJSON, err := json.Marshal(env)
+       if err != nil {
+               panic(err)
+       }
        rr := &remoteRunner{
                uuid:          uuid,
                executor:      wkr.executor,
-               arvClient:     wkr.wp.arvClient,
+               envJSON:       envJSON,
                remoteUser:    wkr.instance.RemoteUser(),
                timeoutTERM:   wkr.wp.timeoutTERM,
                timeoutSignal: wkr.wp.timeoutSignal,
@@ -57,22 +76,11 @@ func newRemoteRunner(uuid string, wkr *worker) *remoteRunner {
 // assume the remote process _might_ have started, at least until it
 // probes the worker and finds otherwise.
 func (rr *remoteRunner) Start() {
-       env := map[string]string{
-               "ARVADOS_API_HOST":  rr.arvClient.APIHost,
-               "ARVADOS_API_TOKEN": rr.arvClient.AuthToken,
-       }
-       if rr.arvClient.Insecure {
-               env["ARVADOS_API_HOST_INSECURE"] = "1"
-       }
-       envJSON, err := json.Marshal(env)
-       if err != nil {
-               panic(err)
-       }
-       stdin := bytes.NewBuffer(envJSON)
        cmd := "crunch-run --detach --stdin-env '" + rr.uuid + "'"
        if rr.remoteUser != "root" {
                cmd = "sudo " + cmd
        }
+       stdin := bytes.NewBuffer(rr.envJSON)
        stdout, stderr, err := rr.executor.Execute(nil, cmd, stdin)
        if err != nil {
                rr.logger.WithField("stdout", string(stdout)).