github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/nomad/structs/alloc.go (about) 1 package structs 2 3 const ( 4 // AllocServiceRegistrationsRPCMethod is the RPC method for listing all 5 // service registrations assigned to a specific allocation. 6 // 7 // Args: AllocServiceRegistrationsRequest 8 // Reply: AllocServiceRegistrationsResponse 9 AllocServiceRegistrationsRPCMethod = "Alloc.GetServiceRegistrations" 10 ) 11 12 // AllocServiceRegistrationsRequest is the request object used to list all 13 // service registrations belonging to the specified Allocation.ID. 14 type AllocServiceRegistrationsRequest struct { 15 AllocID string 16 QueryOptions 17 } 18 19 // AllocServiceRegistrationsResponse is the response object when performing a 20 // listing of services belonging to an allocation. 21 type AllocServiceRegistrationsResponse struct { 22 Services []*ServiceRegistration 23 QueryMeta 24 } 25 26 // ServiceProviderNamespace returns the namespace within which the allocations 27 // services should be registered. This takes into account the different 28 // providers that can provide service registrations. In the event no services 29 // are found, the function will return the Consul namespace which allows hooks 30 // to work as they did before this feature. 31 // 32 // It currently assumes that all services within an allocation use the same 33 // provider and therefore the same namespace. 34 func (a *Allocation) ServiceProviderNamespace() string { 35 tg := a.Job.LookupTaskGroup(a.TaskGroup) 36 37 if len(tg.Services) > 0 { 38 switch tg.Services[0].Provider { 39 case ServiceProviderNomad: 40 return a.Job.Namespace 41 default: 42 return tg.Consul.GetNamespace() 43 } 44 } 45 46 for _, task := range tg.Tasks { 47 if len(task.Services) > 0 { 48 switch task.Services[0].Provider { 49 case ServiceProviderNomad: 50 return a.Job.Namespace 51 default: 52 return tg.Consul.GetNamespace() 53 } 54 } 55 } 56 57 return tg.Consul.GetNamespace() 58 } 59 60 type AllocInfo struct { 61 AllocID string 62 63 // Group in which the service belongs for a group-level service, or the 64 // group in which task belongs for a task-level service. 65 Group string 66 67 // Task in which the service belongs for task-level service. Will be empty 68 // for a group-level service. 69 Task string 70 71 // JobID provides additional context for providers regarding which job 72 // caused this registration. 73 JobID string 74 75 // NomadNamespace provides additional context for providers regarding which 76 // nomad namespace caused this registration. 77 Namespace string 78 }