@@ -131,19 +131,52 @@ func (k *K8s) EventEndpoints(ns *Namespace, data *Endpoints, syncHAproxySrvs fun
131
131
ns .HAProxyRuntime [data .Service ] = make (map [string ]* RuntimeBackend )
132
132
}
133
133
logger .Tracef ("service %s : number of already existing backend(s) in this transaction for this endpoint: %d" , data .Service , len (ns .HAProxyRuntime [data .Service ]))
134
+ // Standalone
135
+ _ , ok = ns .HAProxyRuntimeStandalone [data .Service ]
136
+ if ! ok {
137
+ ns .HAProxyRuntimeStandalone [data .Service ] = make (map [string ]map [string ]* RuntimeBackend )
138
+ }
134
139
for key , value := range ns .HAProxyRuntime [data .Service ] {
135
140
logger .Tracef ("service %s : port name %s, backend %+v" , data .Service , key , * value )
136
141
}
142
+ // Standalone
143
+ for portName , backendsNames := range ns .HAProxyRuntimeStandalone [data .Service ] {
144
+ for backendName := range backendsNames {
145
+ logger .Tracef ("service %s : port name %s, backend %+v" , data .Service , portName , backendName )
146
+ }
147
+ }
137
148
for portName , portEndpoints := range endpoints {
149
+ // Make a copy of addresses for potential standalone runtime backend
150
+ // as these addresses are consumed/removed in the process
151
+ backendAddresses := utils .CopyMap (portEndpoints .Addresses )
138
152
newBackend := & RuntimeBackend {Endpoints : portEndpoints }
139
153
backend , ok := ns.HAProxyRuntime [data.Service ][portName ]
154
+ // Make a copy of haproxy server list for potential standalone runtime backend
155
+ // as this servere list is modified in the process
156
+ var backendHAProxySrvs []* HAProxySrv
140
157
if ok {
158
+ backendHAProxySrvs = utils .CopySliceFunc (backend .HAProxySrvs , utils .CopyPointer )
141
159
portUpdated := (newBackend .Endpoints .Port != backend .Endpoints .Port )
142
160
newBackend .HAProxySrvs = backend .HAProxySrvs
143
161
newBackend .Name = backend .Name
144
162
logger .Warning (syncHAproxySrvs (newBackend , portUpdated ))
145
163
}
146
164
ns.HAProxyRuntime [data.Service ][portName ] = newBackend
165
+
166
+ // Reprocuce the same steps ar regular runtime backend for each standalone runtime backend
167
+ // referring to the same port and service
168
+ standaloneNewBackend := & RuntimeBackend {Endpoints : portEndpoints }
169
+ for standaloneBackendName , standaloneRuntimeBackend := range ns.HAProxyRuntimeStandalone [data.Service ][portName ] {
170
+ // Make own copy of regular runtime backend portEndpoint addresses
171
+ standaloneNewBackend .Endpoints .Addresses = utils .CopyMap (backendAddresses )
172
+ // Make own copy of regular runtime backend portEndpoint servers list
173
+ standaloneNewBackend .HAProxySrvs = utils .CopySliceFunc (backendHAProxySrvs , utils .CopyPointer )
174
+ standaloneNewBackend .Name = standaloneRuntimeBackend .Name
175
+ standalonePortUpdated := (standaloneNewBackend .Endpoints .Port != standaloneRuntimeBackend .Endpoints .Port )
176
+ logger .Warning (syncHAproxySrvs (standaloneNewBackend , standalonePortUpdated ))
177
+ ns.HAProxyRuntimeStandalone [data.Service ][portName ][standaloneBackendName ] = standaloneNewBackend
178
+ standaloneNewBackend = & RuntimeBackend {Endpoints : portEndpoints }
179
+ }
147
180
}
148
181
return true
149
182
}
0 commit comments