github.com/bigcommerce/nomad@v0.9.3-bc/command/agent/consul/structs.go (about) 1 package consul 2 3 import ( 4 "github.com/hashicorp/nomad/client/allocrunner/taskrunner/interfaces" 5 "github.com/hashicorp/nomad/nomad/structs" 6 "github.com/hashicorp/nomad/plugins/drivers" 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 interfaces.ScriptExecutor 30 31 // DriverNetwork is the network specified by the driver and may be nil. 32 DriverNetwork *drivers.DriverNetwork 33 } 34 35 func NewTaskServices(alloc *structs.Allocation, task *structs.Task, restarter TaskRestarter, exec interfaces.ScriptExecutor, net *drivers.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 alloc.AllocatedResources != nil { 46 if tr, ok := alloc.AllocatedResources.Tasks[task.Name]; ok { 47 ts.Networks = tr.Networks 48 } 49 } else if task.Resources != nil { 50 // COMPAT(0.11): Remove in 0.11 51 ts.Networks = task.Resources.Networks 52 } 53 54 if alloc.DeploymentStatus != nil && alloc.DeploymentStatus.Canary { 55 ts.Canary = true 56 } 57 58 return &ts 59 } 60 61 // Copy method for easing tests 62 func (t *TaskServices) Copy() *TaskServices { 63 newTS := new(TaskServices) 64 *newTS = *t 65 66 // Deep copy Services 67 newTS.Services = make([]*structs.Service, len(t.Services)) 68 for i := range t.Services { 69 newTS.Services[i] = t.Services[i].Copy() 70 } 71 return newTS 72 }