@@ -127,19 +127,52 @@ func (k *K8s) EventEndpoints(ns *Namespace, data *Endpoints, syncHAproxySrvs fun
127127 ns .HAProxyRuntime [data .Service ] = make (map [string ]* RuntimeBackend )
128128 }
129129 logger .Tracef ("service %s : number of already existing backend(s) in this transaction for this endpoint: %d" , data .Service , len (ns .HAProxyRuntime [data .Service ]))
130+ // Standalone
131+ _ , ok = ns .HAProxyRuntimeStandalone [data .Service ]
132+ if ! ok {
133+ ns .HAProxyRuntimeStandalone [data .Service ] = make (map [string ]map [string ]* RuntimeBackend )
134+ }
130135 for key , value := range ns .HAProxyRuntime [data .Service ] {
131136 logger .Tracef ("service %s : port name %s, backend %+v" , data .Service , key , * value )
132137 }
138+ // Standalone
139+ for portName , backendsNames := range ns .HAProxyRuntimeStandalone [data .Service ] {
140+ for backendName := range backendsNames {
141+ logger .Tracef ("service %s : port name %s, backend %+v" , data .Service , portName , backendName )
142+ }
143+ }
133144 for portName , portEndpoints := range endpoints {
145+ // Make a copy of addresses for potential standalone runtime backend
146+ // as these addresses are consumed/removed in the process
147+ backendAddresses := utils .CopyMap (portEndpoints .Addresses )
134148 newBackend := & RuntimeBackend {Endpoints : portEndpoints }
135149 backend , ok := ns.HAProxyRuntime [data.Service ][portName ]
150+ // Make a copy of haproxy server list for potential standalone runtime backend
151+ // as this servere list is modified in the process
152+ var backendHAProxySrvs []* HAProxySrv
136153 if ok {
154+ backendHAProxySrvs = utils .CopySliceFunc (backend .HAProxySrvs , utils .CopyPointer )
137155 portUpdated := (newBackend .Endpoints .Port != backend .Endpoints .Port )
138156 newBackend .HAProxySrvs = backend .HAProxySrvs
139157 newBackend .Name = backend .Name
140158 logger .Warning (syncHAproxySrvs (newBackend , portUpdated ))
141159 }
142160 ns.HAProxyRuntime [data.Service ][portName ] = newBackend
161+
162+ // Reprocuce the same steps ar regular runtime backend for each standalone runtime backend
163+ // referring to the same port and service
164+ standaloneNewBackend := & RuntimeBackend {Endpoints : portEndpoints }
165+ for standaloneBackendName , standaloneRuntimeBackend := range ns.HAProxyRuntimeStandalone [data.Service ][portName ] {
166+ // Make own copy of regular runtime backend portEndpoint addresses
167+ standaloneNewBackend .Endpoints .Addresses = utils .CopyMap (backendAddresses )
168+ // Make own copy of regular runtime backend portEndpoint servers list
169+ standaloneNewBackend .HAProxySrvs = utils .CopySliceFunc (backendHAProxySrvs , utils .CopyPointer )
170+ standaloneNewBackend .Name = standaloneRuntimeBackend .Name
171+ standalonePortUpdated := (standaloneNewBackend .Endpoints .Port != standaloneRuntimeBackend .Endpoints .Port )
172+ logger .Warning (syncHAproxySrvs (standaloneNewBackend , standalonePortUpdated ))
173+ ns.HAProxyRuntimeStandalone [data.Service ][portName ][standaloneBackendName ] = standaloneNewBackend
174+ standaloneNewBackend = & RuntimeBackend {Endpoints : portEndpoints }
175+ }
143176 }
144177 return true
145178}
0 commit comments