github.com/nir0s/nomad@v0.8.7-rc1/command/agent/consul/structs.go (about) 1 package consul 2 3 import ( 4 "github.com/hashicorp/nomad/client/driver" 5 cstructs "github.com/hashicorp/nomad/client/structs" 6 "github.com/hashicorp/nomad/nomad/structs" 7 ) 8 9 type TaskServices struct { 10 AllocID string 11 12 // Name of the task 13 Name string 14 15 // Canary indicates whether or not the allocation is a canary 16 Canary bool 17 18 // Restarter allows restarting the task depending on the task's 19 // check_restart stanzas. 20 Restarter TaskRestarter 21 22 // Services and checks to register for the task. 23 Services []*structs.Service 24 25 // Networks from the task's resources stanza. 26 Networks structs.Networks 27 28 // DriverExec is the script executor for the task's driver. 29 DriverExec driver.ScriptExecutor 30 31 // DriverNetwork is the network specified by the driver and may be nil. 32 DriverNetwork *cstructs.DriverNetwork 33 } 34 35 func NewTaskServices(alloc *structs.Allocation, task *structs.Task, restarter TaskRestarter, exec driver.ScriptExecutor, net *cstructs.DriverNetwork) *TaskServices { 36 ts := TaskServices{ 37 AllocID: alloc.ID, 38 Name: task.Name, 39 Restarter: restarter, 40 Services: task.Services, 41 DriverExec: exec, 42 DriverNetwork: net, 43 } 44 45 if task.Resources != nil { 46 ts.Networks = task.Resources.Networks 47 } 48 49 if alloc.DeploymentStatus != nil && alloc.DeploymentStatus.Canary { 50 ts.Canary = true 51 } 52 53 return &ts 54 } 55 56 // Copy method for easing tests 57 func (t *TaskServices) Copy() *TaskServices { 58 newTS := new(TaskServices) 59 *newTS = *t 60 61 // Deep copy Services 62 newTS.Services = make([]*structs.Service, len(t.Services)) 63 for i := range t.Services { 64 newTS.Services[i] = t.Services[i].Copy() 65 } 66 return newTS 67 }