mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
Interpolating service tags
This commit is contained in:
@@ -388,6 +388,9 @@ func (e *UniversalExecutor) SyncServices(ctx *ConsulContext) error {
|
||||
cs.SetDelegatedChecks(e.createCheckMap(), e.createCheck)
|
||||
e.consulService = cs
|
||||
}
|
||||
if e.ctx != nil {
|
||||
e.interpolateServices(e.ctx.Task)
|
||||
}
|
||||
err := e.consulService.SyncTask(e.ctx.Task)
|
||||
go e.consulService.PeriodicSync()
|
||||
return err
|
||||
@@ -541,3 +544,10 @@ func (e *UniversalExecutor) createCheck(check *structs.ServiceCheck, checkID str
|
||||
}
|
||||
return nil, fmt.Errorf("couldn't create check for %v", check.Name)
|
||||
}
|
||||
|
||||
func (e *UniversalExecutor) interpolateServices(task *structs.Task) {
|
||||
e.ctx.TaskEnv.Build()
|
||||
for _, service := range task.Services {
|
||||
service.Tags = e.ctx.TaskEnv.ParseAndReplace(service.Tags)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -267,3 +268,18 @@ func TestExecutor_MakeExecutable(t *testing.T) {
|
||||
t.Fatalf("expected permissions %v; got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecutorInterpolateServices(t *testing.T) {
|
||||
task := mock.Job().TaskGroups[0].Tasks[0]
|
||||
// Make a fake exececutor
|
||||
ctx := testExecutorContext(t)
|
||||
defer ctx.AllocDir.Destroy()
|
||||
executor := NewExecutor(log.New(os.Stdout, "", log.LstdFlags))
|
||||
|
||||
executor.(*UniversalExecutor).ctx = ctx
|
||||
executor.(*UniversalExecutor).interpolateServices(task)
|
||||
expected := []string{"pci:true", "datacenter:dc1"}
|
||||
if !reflect.DeepEqual(task.Services[0].Tags, expected) {
|
||||
t.Fatalf("expected: %v, actual: %v", expected, task.Services[0].Tags)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user