forked from hashicorp/nomad
/
connect.go
39 lines (33 loc) · 1.17 KB
/
connect.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package structs
// ConsulConfigEntries represents Consul ConfigEntry definitions from a job for
// a single Consul namespace.
type ConsulConfigEntries struct {
Ingress map[string]*ConsulIngressConfigEntry
Terminating map[string]*ConsulTerminatingConfigEntry
}
// ConfigEntries accumulates the Consul Configuration Entries defined in task groups
// of j, organized by Consul namespace.
func (j *Job) ConfigEntries() map[string]*ConsulConfigEntries {
collection := make(map[string]*ConsulConfigEntries)
for _, tg := range j.TaskGroups {
// accumulate config entries by namespace
ns := tg.Consul.GetNamespace()
if _, exists := collection[ns]; !exists {
collection[ns] = &ConsulConfigEntries{
Ingress: make(map[string]*ConsulIngressConfigEntry),
Terminating: make(map[string]*ConsulTerminatingConfigEntry),
}
}
for _, service := range tg.Services {
if service.Connect.IsGateway() {
gateway := service.Connect.Gateway
if ig := gateway.Ingress; ig != nil {
collection[ns].Ingress[service.Name] = ig
} else if term := gateway.Terminating; term != nil {
collection[ns].Terminating[service.Name] = term
}
}
}
}
return collection
}