cluster/services/ways: don't render empty upstream blocks

This commit is contained in:
Max Headroom 2024-08-10 03:00:22 +02:00
parent 415fd7f076
commit a285c57d5b

View file

@ -69,11 +69,16 @@ in
{
source = let
upstreams = lib.mapAttrsToList (_: cfg: ''
{{ if ne (len (service "${cfg.consulService}~_agent")) 0 }}
# ${cfg.consulService}
upstream ${cfg.nginxUpstreamName} {
{{ range $i, $e := service "${cfg.consulService}~_agent" -}}
server {{ .Address }}:{{ .Port }}{{ if ne $i 0 }} backup{{ end }};
{{ end }}
}
{{ else }}
# upstream ${cfg.nginxUpstreamName} (${cfg.consulService}): no servers available
{{ end }}
'') consulServiceWays;
in pkgs.writeText "ways-upstreams.ctmpl" (lib.concatStringsSep "\n" (lib.unique upstreams));
destination = "/run/consul-template/nginx-ways-upstreams.conf";