Allow getting service config from a common place connect_services

This commit is contained in:
Daniel Berteaud 2024-04-06 00:36:43 +02:00
parent 7cd3aeb29e
commit 2f03b5c8b5
1 changed files with 12 additions and 2 deletions

View File

@ -13,13 +13,23 @@
[[- range $idx, $upstream := .consul.connect.upstreams ]]
[[- $connect_services = append $upstream.destination_name $connect_services ]]
upstreams {
destination_name = [[ $upstream.destination_name | toJSON ]]
destination_name = "[[ $upstream.destination_name ]]"
[[- if has $upstream "local_bind_port" ]]
local_bind_port = [[ $upstream.local_bind_port ]]
[[- else if and (has $ "connect_services") (has $.connect_services $upstream.destination_name) (has (index $.connect_services $upstream.destination_name) "port") ]]
local_bind_port = [[ (index $.connect_services $upstream.destination_name).port ]]
[[- end ]]
# Work arround, see https://github.com/hashicorp/nomad/issues/18538
destination_type = "service"
[[- $config := dict ]]
[[- if has $upstream "config" ]]
[[- $config = $upstream.config ]]
[[- else if and (has $ "connect_services") (has $.connect_services $upstream.destination_name) (has (index $.connect_services $upstream.destination_name) "config") ]]
[[- $config = (index $.connect_services $upstream.destination_name).config ]]
[[- end ]]
[[- if gt (len $config) 0 ]]
config {
[[- range $k, $v := $upstream.config ]]
[[- range $k, $v := $config ]]
[[- if or (isKind "number" $v) (isKind "bool" $v) ]]
[[ $k ]] = [[ $v ]]
[[- else if isKind "string" $v ]]