github.com/hernad/nomad@v1.6.112/command/agent/consul/structs.go (about)

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