2020-12-15 20:38:33 +00:00
|
|
|
package structs
|
|
|
|
|
2021-04-19 17:29:36 +00:00
|
|
|
// ConsulConfigEntries represents Consul ConfigEntry definitions from a job for
|
|
|
|
// a single Consul namespace.
|
2020-12-15 20:38:33 +00:00
|
|
|
type ConsulConfigEntries struct {
|
|
|
|
Ingress map[string]*ConsulIngressConfigEntry
|
|
|
|
Terminating map[string]*ConsulTerminatingConfigEntry
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConfigEntries accumulates the Consul Configuration Entries defined in task groups
|
2021-04-19 17:29:36 +00:00
|
|
|
// of j, organized by Consul namespace.
|
|
|
|
func (j *Job) ConfigEntries() map[string]*ConsulConfigEntries {
|
|
|
|
collection := make(map[string]*ConsulConfigEntries)
|
2020-12-15 20:38:33 +00:00
|
|
|
|
|
|
|
for _, tg := range j.TaskGroups {
|
2021-04-19 17:29:36 +00:00
|
|
|
|
|
|
|
// 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),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-15 20:38:33 +00:00
|
|
|
for _, service := range tg.Services {
|
|
|
|
if service.Connect.IsGateway() {
|
|
|
|
gateway := service.Connect.Gateway
|
|
|
|
if ig := gateway.Ingress; ig != nil {
|
2021-04-19 17:29:36 +00:00
|
|
|
collection[ns].Ingress[service.Name] = ig
|
|
|
|
} else if term := gateway.Terminating; term != nil {
|
|
|
|
collection[ns].Terminating[service.Name] = term
|
|
|
|
}
|
2020-12-15 20:38:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-19 17:29:36 +00:00
|
|
|
return collection
|
2020-12-15 20:38:33 +00:00
|
|
|
}
|