github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/command/agent/consul/structs.go (about)

     1  package consul
     2  
     3  import (
     4  	"github.com/hashicorp/nomad/client/serviceregistration"
     5  	"github.com/hashicorp/nomad/client/taskenv"
     6  	"github.com/hashicorp/nomad/nomad/mock"
     7  	"github.com/hashicorp/nomad/nomad/structs"
     8  	"github.com/hashicorp/nomad/plugins/drivers"
     9  )
    10  
    11  func BuildAllocServices(
    12  	node *structs.Node, alloc *structs.Allocation, restarter serviceregistration.WorkloadRestarter) *serviceregistration.WorkloadServices {
    13  
    14  	//TODO(schmichael) only support one network for now
    15  	net := alloc.AllocatedResources.Shared.Networks[0]
    16  
    17  	tg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)
    18  
    19  	ws := &serviceregistration.WorkloadServices{
    20  		AllocInfo: structs.AllocInfo{
    21  			AllocID: alloc.ID,
    22  			Group:   alloc.TaskGroup,
    23  		},
    24  		Services: taskenv.InterpolateServices(taskenv.NewBuilder(mock.Node(), alloc, nil, alloc.Job.Region).Build(), tg.Services),
    25  		Networks: alloc.AllocatedResources.Shared.Networks,
    26  
    27  		//TODO(schmichael) there's probably a better way than hacking driver network
    28  		DriverNetwork: &drivers.DriverNetwork{
    29  			AutoAdvertise: true,
    30  			IP:            net.IP,
    31  			// Copy PortLabels from group network
    32  			PortMap: net.PortLabels(),
    33  		},
    34  
    35  		Restarter:  restarter,
    36  		DriverExec: nil,
    37  	}
    38  
    39  	if alloc.DeploymentStatus != nil {
    40  		ws.Canary = alloc.DeploymentStatus.Canary
    41  	}
    42  
    43  	return ws
    44  }