@@ -558,10 +558,9 @@ func (g *gatewayModule) SetNamedProxy(wlID string, config zos.GatewayNameProxy)
558558 ctx , cancel := context .WithTimeout (context .Background (), 1 * time .Minute )
559559 defer cancel ()
560560
561- if len (config .Backends ) != 1 {
562- return "" , fmt .Errorf ("only one backend is supported got '%d'" , len (config .Backends ))
561+ if len (config .Backends ) == 0 {
562+ return "" , fmt .Errorf ("at least one backend is needed got '%d'" , len (config .Backends ))
563563 }
564-
565564 twinID , _ , _ , err := gridtypes .WorkloadID (wlID ).Parts ()
566565 if err != nil {
567566 return "" , errors .Wrap (err , "invalid workload id" )
@@ -600,10 +599,9 @@ func (g *gatewayModule) SetFQDNProxy(wlID string, config zos.GatewayFQDNProxy) e
600599 ctx , cancel := context .WithTimeout (context .Background (), 1 * time .Minute )
601600 defer cancel ()
602601
603- if len (config .Backends ) != 1 {
604- return fmt .Errorf ("only one backend is supported got '%d'" , len (config .Backends ))
602+ if len (config .Backends ) == 0 {
603+ return fmt .Errorf ("at least one backend is needed got '%d'" , len (config .Backends ))
605604 }
606-
607605 cfg , err := g .ensureGateway (ctx , false )
608606 if err != nil {
609607 return err
@@ -631,14 +629,12 @@ func (g *gatewayModule) setupRouting(ctx context.Context, wlID string, fqdn stri
631629 g .domainLock .Lock ()
632630 defer g .domainLock .Unlock ()
633631
634- backend := config .Backends [0 ]
635-
636- if err := backend .Valid (config .TLSPassthrough ); err != nil {
637- return errors .Wrapf (err , "failed to validate backend '%s'" , backend )
632+ if err := zos .ValidateBackends (config .Backends , config .TLSPassthrough ); err != nil {
633+ return err
638634 }
639635
640636 if _ , ok := g .getReservedDomain (fqdn ); ok {
641- return errors .New ("domain already registered" )
637+ return errors .Errorf ("domain already registered: %s" , fqdn )
642638 }
643639
644640 if config .Network == nil {
@@ -661,23 +657,28 @@ func (g *gatewayModule) setupRouting(ctx context.Context, wlID string, fqdn stri
661657 return errors .Wrap (err , "failed to get user network" )
662658 }
663659 ns := net .Namespace (ctx , netID )
664- backend , err = g .nncEnsure (wlID , ns , config .Backends [0 ])
665- if err != nil {
666- return errors .Wrap (err , "failed to ensure local gateway" )
667- }
668660
669- if ! config .TLSPassthrough {
670- // if tls passthrough is disabled traefik expecting backend
671- // to be in the format http://<ip>:port
672- backend = zos .Backend (fmt .Sprintf ("http://%s" , backend ))
661+ processedBackends := []zos.Backend {}
662+ for _ , backend := range config .Backends {
663+ processedBackend , err := g .nncEnsure (wlID , ns , backend )
664+ if err != nil {
665+ return errors .Wrap (err , "failed to ensure local gateway" )
666+ }
667+
668+ if ! config .TLSPassthrough {
669+ // Format for non-TLS passthrough
670+ processedBackend = zos .Backend (fmt .Sprintf ("http://%s" , processedBackend ))
671+ }
672+
673+ processedBackends = append (processedBackends , processedBackend )
674+
673675 }
674676
675- config .Backends = []zos. Backend { backend }
677+ config .Backends = processedBackends
676678 return g .setupRoutingGeneric (wlID , fqdn , tlsConfig , config )
677679}
678680
679681func (g * gatewayModule ) setupRoutingGeneric (wlID string , fqdn string , tlsConfig TlsConfig , config zos.GatewayBase ) error {
680- backend := config .Backends [0 ]
681682 var rule string
682683 if config .TLSPassthrough {
683684 rule = fmt .Sprintf ("HostSNI(`%s`)" , fqdn )
@@ -688,11 +689,15 @@ func (g *gatewayModule) setupRoutingGeneric(wlID string, fqdn string, tlsConfig
688689 rule = fmt .Sprintf ("Host(`%s`)" , fqdn )
689690 }
690691
691- var server Server
692- if config .TLSPassthrough {
693- server = Server {Address : string (backend )}
694- } else {
695- server = Server {Url : string (backend )}
692+ servers := []Server {}
693+ for _ , backend := range config .Backends {
694+ var server Server
695+ if config .TLSPassthrough {
696+ server = Server {Address : string (backend )}
697+ } else {
698+ server = Server {Url : string (backend )}
699+ }
700+ servers = append (servers , server )
696701 }
697702
698703 route := fmt .Sprintf ("%s-route" , wlID )
@@ -709,7 +714,7 @@ func (g *gatewayModule) setupRoutingGeneric(wlID string, fqdn string, tlsConfig
709714 Services : map [string ]Service {
710715 wlID : {
711716 LoadBalancer : LoadBalancer {
712- Servers : [] Server { server } ,
717+ Servers : servers ,
713718 },
714719 },
715720 },
0 commit comments