Skip to content

Commit

Permalink
fix nomad config issues using environment variables
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Aguilera <[email protected]>
  • Loading branch information
jagedn committed Jul 2, 2024
1 parent 5fb5039 commit 656eb28
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions plugins/nf-nomad/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ dependencies {
test {
useJUnitPlatform()
jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED'
environment 'NOMAD_ADDR', 'http://test-nf-nomad'
}

jar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ class NomadClientOpts{

sysEnv = env==null ? new HashMap<String,String>(System.getenv()) : env

def tmp = (nomadClientOpts.address?.toString() ?: sysEnv.get('NOMAD_ADDR'))
def address = (nomadClientOpts.address?.toString() ?: sysEnv.get('NOMAD_ADDR'))
assert address != null, "Nomad Address is required"

if( !tmp.endsWith("/"))
tmp +="/"
this.address = tmp + API_VERSION
if( !address.endsWith("/"))
address +="/"
this.address = address + API_VERSION
this.token = nomadClientOpts.token ?: sysEnv.get('NOMAD_TOKEN')

//TODO: Add mTLS properties and env vars
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class NomadJobOpts{
NomadJobOpts(Map nomadJobOpts, Map<String,String> env=null){
assert nomadJobOpts!=null

sysEnv = env==null ? new HashMap<String,String>(System.getenv()) : env
sysEnv = env ?: new HashMap<String,String>(System.getenv())

deleteOnCompletion = nomadJobOpts.containsKey("deleteOnCompletion") ?
nomadJobOpts.deleteOnCompletion : false
Expand All @@ -53,7 +53,7 @@ class NomadJobOpts{
nomadJobOpts.datacenters : nomadJobOpts.datacenters.toString().split(","))
as List<String>).findAll{it.size()}.unique()
}else{
datacenters = List.of(sysEnv.get('NOMAD_DC'))
datacenters = (sysEnv.get('NOMAD_DC')?:"").split(",") as List<String>
}

region = nomadJobOpts.region ?: sysEnv.get('NOMAD_REGION')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class NomadConfigSpec extends Specification {

where:
ADDRESS | EXPECTED
null | "${System.getenv('NOMAD_ADDR')}/v1"
null | "http://test-nf-nomad/v1" // see build.gradle
"http://nomad" | "http://nomad/v1"
}

Expand Down

0 comments on commit 656eb28

Please sign in to comment.