@@ -250,7 +250,7 @@ def disconnect(self, network, container, scope):
250250 if self .config_data .has_backend (container ):
251251 try :
252252 backend = BackendTarget .from_container (self .client .containers .get (container ))
253- if not self .update_backend (backend ):
253+ if not self .update_backend (backend , replace_existing = True ):
254254 self .remove_backend (
255255 container
256256 ) # remove_backend not implemented yet, using remove_container (it takes ID)
@@ -286,23 +286,23 @@ def connect(self, network, container, scope):
286286 # print(f"Skipping network connect for service task container {container}")
287287 return
288288 backend = BackendTarget .from_container (container_obj )
289- self .update_backend (backend )
289+ self .update_backend (backend , replace_existing = True )
290290 except docker .errors .NotFound :
291291 return
292292 except (KeyboardInterrupt , SystemExit ):
293293 raise
294294 except Exception as e :
295295 print (f"Error processing connect for container { container } : { e } " , file = sys .stderr )
296296
297- def update_backend (self , backend : BackendTarget ):
297+ def update_backend (self , backend : BackendTarget , replace_existing : bool = False ):
298298 """
299299 Rescan the backend to detect changes. And update nginx configuration if necessary.
300300 :param backend: BackendTarget object
301301 :return: true if state change affected the nginx configuration else false
302302 """
303303 try :
304304 existing_backend = self .config_data .has_backend (backend .id )
305- if existing_backend and backend .type != "service" :
305+ if existing_backend and backend .type != "service" and not replace_existing :
306306 return False
307307
308308 removed = None
0 commit comments