2018-04-23 23:34:53 +00:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
2022-03-15 08:38:30 +00:00
|
|
|
"github.com/hashicorp/nomad/client/serviceregistration"
|
2019-11-18 18:04:01 +00:00
|
|
|
"github.com/hashicorp/nomad/client/taskenv"
|
|
|
|
"github.com/hashicorp/nomad/nomad/mock"
|
2018-04-23 23:34:53 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
2019-01-04 23:01:35 +00:00
|
|
|
"github.com/hashicorp/nomad/plugins/drivers"
|
2018-04-23 23:34:53 +00:00
|
|
|
)
|
|
|
|
|
2022-03-15 08:38:30 +00:00
|
|
|
func BuildAllocServices(
|
|
|
|
node *structs.Node, alloc *structs.Allocation, restarter WorkloadRestarter) *serviceregistration.WorkloadServices {
|
2019-11-18 18:04:01 +00:00
|
|
|
|
|
|
|
//TODO(schmichael) only support one network for now
|
|
|
|
net := alloc.AllocatedResources.Shared.Networks[0]
|
|
|
|
|
|
|
|
tg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)
|
|
|
|
|
2022-03-15 08:38:30 +00:00
|
|
|
ws := &serviceregistration.WorkloadServices{
|
2019-11-18 18:04:01 +00:00
|
|
|
AllocID: alloc.ID,
|
|
|
|
Group: alloc.TaskGroup,
|
|
|
|
Services: taskenv.InterpolateServices(taskenv.NewBuilder(mock.Node(), alloc, nil, alloc.Job.Region).Build(), tg.Services),
|
|
|
|
Networks: alloc.AllocatedResources.Shared.Networks,
|
|
|
|
|
|
|
|
//TODO(schmichael) there's probably a better way than hacking driver network
|
|
|
|
DriverNetwork: &drivers.DriverNetwork{
|
|
|
|
AutoAdvertise: true,
|
|
|
|
IP: net.IP,
|
|
|
|
// Copy PortLabels from group network
|
|
|
|
PortMap: net.PortLabels(),
|
|
|
|
},
|
2018-04-23 23:34:53 +00:00
|
|
|
|
2019-11-18 18:04:01 +00:00
|
|
|
Restarter: restarter,
|
|
|
|
DriverExec: nil,
|
2018-04-23 23:34:53 +00:00
|
|
|
}
|
|
|
|
|
2019-11-18 18:04:01 +00:00
|
|
|
if alloc.DeploymentStatus != nil {
|
|
|
|
ws.Canary = alloc.DeploymentStatus.Canary
|
2018-04-23 23:34:53 +00:00
|
|
|
}
|
|
|
|
|
2019-11-18 18:04:01 +00:00
|
|
|
return ws
|
2018-04-23 23:34:53 +00:00
|
|
|
}
|