From ddec2f1617c28cdf8c4f9041d7c4bea1dae0ac2d Mon Sep 17 00:00:00 2001 From: Lasse Dalegaard Date: Tue, 26 Sep 2017 10:20:57 +0200 Subject: [PATCH] Turn rkt network status failure into Start failure If the rkt driver cannot get the network status, for a task with a configured port mapping, it will now fail the Start() call and kill the task instead of simply logging. This matches the Docker behavior. If no port map is specified, the warnings will be logged but the task will be allowed to start. --- client/driver/rkt.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/client/driver/rkt.go b/client/driver/rkt.go index 906b96081..986e1e1de 100644 --- a/client/driver/rkt.go +++ b/client/driver/rkt.go @@ -593,13 +593,8 @@ func (d *RktDriver) Start(ctx *ExecContext, task *structs.Task) (*StartResponse, d.logger.Printf("[DEBUG] driver.rkt: retrieving status for pod %q (UUID %s) for task %q with", img, uuid, d.taskName) deadline := time.Now().Add(rktNetworkDeadline) var driverNetwork *cstructs.DriverNetwork - var notFirst bool +networkLoop: for driverNetwork == nil && time.Now().Before(deadline) { - if notFirst { - time.Sleep(400 * time.Millisecond) - } - notFirst = true - status, err := rktGetStatus(uuid) if err != nil { continue @@ -616,20 +611,29 @@ func (d *RktDriver) Start(ctx *ExecContext, task *structs.Task) (*StartResponse, if err == nil { portmap, err = rktManifestMakePortMap(manifest, driverConfig.PortMap) if err != nil { - d.logger.Printf("[DEBUG] driver.rkt: could not create manifest-based portmap for %q (UUID %s) for task %q: %v", img, uuid, d.taskName, err) + d.logger.Printf("[WARN] driver.rkt: could not create manifest-based portmap for %q (UUID %s) for task %q: %v", img, uuid, d.taskName, err) + break networkLoop } } else { d.logger.Printf("[WARN] driver.rkt: could get not pod manifest for %q (UUID %s) for task %q: %v", img, uuid, d.taskName, err) + break networkLoop } driverNetwork = &cstructs.DriverNetwork{ PortMap: portmap, IP: status.Networks[0].IP.String(), } - break + break networkLoop } + + time.Sleep(400 * time.Millisecond) } if driverNetwork == nil { + // If a portmap was given, this turns into a fatal error + if len(driverConfig.PortMap) != 0 { + pluginClient.Kill() + return nil, fmt.Errorf("Trying to map ports but driver could not determine network information") + } d.logger.Printf("[WARN] driver.rkt: network status retrieval for pod %q (UUID %s) for task %q failed", img, uuid, d.taskName) }