@@ -558,9 +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 ))
563- }
561+ // if len(config.Backends) != 1 {
562+ // return "", fmt.Errorf("only one backend is supported got '%d'", len(config.Backends))
563+ // }
564564
565565 twinID , _ , _ , err := gridtypes .WorkloadID (wlID ).Parts ()
566566 if err != nil {
@@ -631,10 +631,10 @@ func (g *gatewayModule) setupRouting(ctx context.Context, wlID string, fqdn stri
631631 g .domainLock .Lock ()
632632 defer g .domainLock .Unlock ()
633633
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 )
634+ for _ , backend := range config .Backends {
635+ if err := backend . Valid ( config . TLSPassthrough ); err != nil {
636+ return errors . New ( "domain already registered" )
637+ }
638638 }
639639
640640 if _ , ok := g .getReservedDomain (fqdn ); ok {
@@ -661,23 +661,28 @@ func (g *gatewayModule) setupRouting(ctx context.Context, wlID string, fqdn stri
661661 return errors .Wrap (err , "failed to get user network" )
662662 }
663663 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- }
668-
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 ))
673- }
674-
675- config .Backends = []zos.Backend {backend }
664+
665+ processedBackends := make ([]zos.Backend , 0 , len (config .Backends ))
666+ for _ , backend := range config .Backends {
667+ processedBackend , err := g .nncEnsure (wlID , ns , backend )
668+ if err != nil {
669+ return errors .Wrap (err , "failed to ensure local gateway" )
670+ }
671+
672+ if ! config .TLSPassthrough {
673+ // Format for non-TLS passthrough
674+ processedBackend = zos .Backend (fmt .Sprintf ("http://%s" , processedBackend ))
675+ }
676+
677+ processedBackends = append (processedBackends , processedBackend )
678+
679+ }
680+
681+ config .Backends = processedBackends
676682 return g .setupRoutingGeneric (wlID , fqdn , tlsConfig , config )
677683}
678684
679685func (g * gatewayModule ) setupRoutingGeneric (wlID string , fqdn string , tlsConfig TlsConfig , config zos.GatewayBase ) error {
680- backend := config .Backends [0 ]
681686 var rule string
682687 if config .TLSPassthrough {
683688 rule = fmt .Sprintf ("HostSNI(`%s`)" , fqdn )
@@ -688,11 +693,15 @@ func (g *gatewayModule) setupRoutingGeneric(wlID string, fqdn string, tlsConfig
688693 rule = fmt .Sprintf ("Host(`%s`)" , fqdn )
689694 }
690695
691- var server Server
692- if config .TLSPassthrough {
693- server = Server {Address : string (backend )}
694- } else {
695- server = Server {Url : string (backend )}
696+ servers := make ([]Server , 0 , len (config .Backends ))
697+ for _ , backend := range config .Backends {
698+ var server Server
699+ if config .TLSPassthrough {
700+ server = Server {Address : string (backend )}
701+ } else {
702+ server = Server {Url : string (backend )}
703+ }
704+ servers = append (servers , server )
696705 }
697706
698707 route := fmt .Sprintf ("%s-route" , wlID )
@@ -709,7 +718,7 @@ func (g *gatewayModule) setupRoutingGeneric(wlID string, fqdn string, tlsConfig
709718 Services : map [string ]Service {
710719 wlID : {
711720 LoadBalancer : LoadBalancer {
712- Servers : [] Server { server } ,
721+ Servers : servers ,
713722 },
714723 },
715724 },
0 commit comments