mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
connect: add group.service stanza support
This commit is contained in:
committed by
Nick Ethier
parent
1ff85f09f3
commit
eb2a2cd76e
@@ -686,6 +686,7 @@ func ApiTgToStructsTG(taskGroup *api.TaskGroup, tg *structs.TaskGroup) {
|
||||
tg.Constraints = ApiConstraintsToStructs(taskGroup.Constraints)
|
||||
tg.Affinities = ApiAffinitiesToStructs(taskGroup.Affinities)
|
||||
tg.Networks = ApiNetworkResourceToStructs(taskGroup.Networks)
|
||||
tg.Services = ApiServicesToStructs(taskGroup.Services)
|
||||
|
||||
tg.RestartPolicy = &structs.RestartPolicy{
|
||||
Attempts: *taskGroup.RestartPolicy.Attempts,
|
||||
@@ -926,6 +927,7 @@ func ApiNetworkResourceToStructs(in []*api.NetworkResource) []*structs.NetworkRe
|
||||
out[i].DynamicPorts[j] = structs.Port{
|
||||
Label: dp.Label,
|
||||
Value: dp.Value,
|
||||
To: dp.To,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -936,6 +938,7 @@ func ApiNetworkResourceToStructs(in []*api.NetworkResource) []*structs.NetworkRe
|
||||
out[i].ReservedPorts[j] = structs.Port{
|
||||
Label: rp.Label,
|
||||
Value: rp.Value,
|
||||
To: rp.To,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -944,6 +947,87 @@ func ApiNetworkResourceToStructs(in []*api.NetworkResource) []*structs.NetworkRe
|
||||
return out
|
||||
}
|
||||
|
||||
//TODO(schmichael) refactor and reuse in service parsing above
|
||||
func ApiServicesToStructs(in []*api.Service) []*structs.Service {
|
||||
if len(in) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
out := make([]*structs.Service, len(in))
|
||||
for i, s := range in {
|
||||
out[i] = &structs.Service{
|
||||
Name: s.Name,
|
||||
PortLabel: s.PortLabel,
|
||||
Tags: s.Tags,
|
||||
CanaryTags: s.CanaryTags,
|
||||
AddressMode: s.AddressMode,
|
||||
}
|
||||
|
||||
if l := len(s.Checks); l != 0 {
|
||||
out[i].Checks = make([]*structs.ServiceCheck, l)
|
||||
for j, check := range s.Checks {
|
||||
out[i].Checks[j] = &structs.ServiceCheck{
|
||||
Name: check.Name,
|
||||
Type: check.Type,
|
||||
Command: check.Command,
|
||||
Args: check.Args,
|
||||
Path: check.Path,
|
||||
Protocol: check.Protocol,
|
||||
PortLabel: check.PortLabel,
|
||||
AddressMode: check.AddressMode,
|
||||
Interval: check.Interval,
|
||||
Timeout: check.Timeout,
|
||||
InitialStatus: check.InitialStatus,
|
||||
TLSSkipVerify: check.TLSSkipVerify,
|
||||
Header: check.Header,
|
||||
Method: check.Method,
|
||||
GRPCService: check.GRPCService,
|
||||
GRPCUseTLS: check.GRPCUseTLS,
|
||||
}
|
||||
if check.CheckRestart != nil {
|
||||
out[i].Checks[j].CheckRestart = &structs.CheckRestart{
|
||||
Limit: check.CheckRestart.Limit,
|
||||
Grace: *check.CheckRestart.Grace,
|
||||
IgnoreWarnings: check.CheckRestart.IgnoreWarnings,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if s.Connect == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
out[i].Connect = &structs.ConsulConnect{}
|
||||
|
||||
if s.Connect.SidecarService == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
out[i].Connect.SidecarService = &structs.ConsulSidecarService{
|
||||
Port: s.Connect.SidecarService.Port,
|
||||
}
|
||||
|
||||
if s.Connect.SidecarService.Proxy == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
out[i].Connect.SidecarService.Proxy = &structs.ConsulProxy{}
|
||||
|
||||
upstreams := make([]*structs.ConsulUpstream, len(s.Connect.SidecarService.Proxy.Upstreams))
|
||||
for i, p := range s.Connect.SidecarService.Proxy.Upstreams {
|
||||
upstreams[i] = &structs.ConsulUpstream{
|
||||
DestinationName: p.DestinationName,
|
||||
LocalBindPort: p.LocalBindPort,
|
||||
}
|
||||
}
|
||||
|
||||
out[i].Connect.SidecarService.Proxy.Upstreams = upstreams
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
func ApiConstraintsToStructs(in []*api.Constraint) []*structs.Constraint {
|
||||
if in == nil {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user