From 394cbc81b602eb10ef29c6a0203549bf9bfdd8c6 Mon Sep 17 00:00:00 2001 From: Nick Ethier Date: Mon, 29 Oct 2018 21:43:19 -0400 Subject: [PATCH] plugins/drivers: nil gaurd driver config when building executor config --- plugins/drivers/utils/utils.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/plugins/drivers/utils/utils.go b/plugins/drivers/utils/utils.go index 53addf206..d5a9ce1c5 100644 --- a/plugins/drivers/utils/utils.go +++ b/plugins/drivers/utils/utils.go @@ -17,6 +17,16 @@ import ( "github.com/hashicorp/nomad/plugins/base" ) +const ( + // ExecutorDefaultMaxPort is the default max port used by the executor for + // searching for an available port + ExecutorDefaultMaxPort = 14512 + + // ExecutorDefaultMinPort is the default min port used by the executor for + // searching for an available port + ExecutorDefaultMinPort = 14000 +) + // CgroupsMounted returns true if the cgroups are mounted on a system otherwise // returns false func CgroupsMounted(node *structs.Node) bool { @@ -26,7 +36,7 @@ func CgroupsMounted(node *structs.Node) bool { // CreateExecutor launches an executor plugin and returns an instance of the // Executor interface -func CreateExecutor(w io.Writer, level hclog.Level, nomadConfig *base.ClientDriverConfig, +func CreateExecutor(w io.Writer, level hclog.Level, driverConfig *base.ClientDriverConfig, executorConfig *dstructs.ExecutorConfig) (executor.Executor, *plugin.Client, error) { c, err := json.Marshal(executorConfig) @@ -44,8 +54,13 @@ func CreateExecutor(w io.Writer, level hclog.Level, nomadConfig *base.ClientDriv config.HandshakeConfig = driver.HandshakeConfig config.Plugins = driver.GetPluginMap(w, level, executorConfig.FSIsolation) - config.MaxPort = nomadConfig.ClientMaxPort - config.MinPort = nomadConfig.ClientMinPort + if driverConfig != nil { + config.MaxPort = driverConfig.ClientMaxPort + config.MinPort = driverConfig.ClientMinPort + } else { + config.MaxPort = ExecutorDefaultMaxPort + config.MinPort = ExecutorDefaultMinPort + } // setting the setsid of the plugin process so that it doesn't get signals sent to // the nomad client.