19166: Don't set up a reverse tunnel if we won't be advertising it.
authorTom Clegg <tom@curii.com>
Fri, 1 Jul 2022 18:10:38 +0000 (14:10 -0400)
committerTom Clegg <tom@curii.com>
Fri, 1 Jul 2022 18:10:38 +0000 (14:10 -0400)
Avoids wasting long-lived connections between crunch-run and
controller.

Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

lib/crunchrun/crunchrun.go

index df3abe630900fdc32cdb383239569855879e1c83..ff02257f2b36739ccd241f4d49e7c4aa4acb2c1c 100644 (file)
@@ -1905,32 +1905,26 @@ func (command) RunCommand(prog string, args []string, stdin io.Reader, stdout, s
                // not safe to run a gateway service without an auth
                // secret
                cr.CrunchLog.Printf("Not starting a gateway server (GatewayAuthSecret was not provided by dispatcher)")
-       } else if gwListen := os.Getenv("GatewayAddress"); gwListen == "" {
-               // dispatcher did not tell us which external IP
-               // address to advertise --> no gateway service
-               cr.CrunchLog.Printf("Not starting a gateway server (GatewayAddress was not provided by dispatcher)")
        } else {
+               gwListen := os.Getenv("GatewayAddress")
                cr.gateway = Gateway{
                        Address:       gwListen,
                        AuthSecret:    gwAuthSecret,
                        ContainerUUID: containerUUID,
                        Target:        cr.executor,
                        Log:           cr.CrunchLog,
-                       ArvadosClient: cr.dispatcherClient,
-                       UpdateTunnelURL: func(url string) {
-                               if gwListen != "" {
-                                       // prefer connecting directly
-                                       return
-                               }
-                               // direct connection won't work, so we
-                               // use the gateway_address field to
-                               // indicate the internalURL of the
-                               // controller process that has the
-                               // current tunnel connection.
+               }
+               if gwListen == "" {
+                       // Direct connection won't work, so we use the
+                       // gateway_address field to indicate the
+                       // internalURL of the controller process that
+                       // has the current tunnel connection.
+                       cr.gateway.ArvadosClient = cr.dispatcherClient
+                       cr.gateway.UpdateTunnelURL = func(url string) {
                                cr.gateway.Address = "tunnel " + url
                                cr.DispatcherArvClient.Update("containers", containerUUID,
                                        arvadosclient.Dict{"container": arvadosclient.Dict{"gateway_address": cr.gateway.Address}}, nil)
-                       },
+                       }
                }
                err = cr.gateway.Start()
                if err != nil {