@@ -86,7 +86,7 @@ public class Main {
86
86
private static final TuningParameters tuningAndConfig ;
87
87
private static final CallBuilderFactory callBuilderFactory = new CallBuilderFactory ();
88
88
private static Map <String , NamespaceStatus > namespaceStatuses = new ConcurrentHashMap <>();
89
- private static Map <String , AtomicBoolean > isNamespaceStopping = new ConcurrentHashMap <>();
89
+ private static Map <String , AtomicBoolean > namespaceStoppingMap = new ConcurrentHashMap <>();
90
90
private static final Map <String , ConfigMapWatcher > configMapWatchers = new ConcurrentHashMap <>();
91
91
private static final Map <String , DomainWatcher > domainWatchers = new ConcurrentHashMap <>();
92
92
private static final Map <String , EventWatcher > eventWatchers = new ConcurrentHashMap <>();
@@ -227,7 +227,7 @@ private static void begin() {
227
227
private static void completeBegin () {
228
228
try {
229
229
// start the REST server
230
- startRestServer (principal , isNamespaceStopping .keySet ());
230
+ startRestServer (principal , namespaceStoppingMap .keySet ());
231
231
232
232
// start periodic retry and recheck
233
233
int recheckInterval = tuningAndConfig .getMainTuning ().targetNamespaceRecheckIntervalSeconds ;
@@ -247,14 +247,23 @@ private static void completeBegin() {
247
247
}
248
248
}
249
249
250
- private static void stopNamespace (String ns , boolean remove ) {
251
- processor .stopNamespace (ns );
252
- AtomicBoolean stopping =
253
- remove ? isNamespaceStopping .remove (ns ) : isNamespaceStopping .get (ns );
250
+ private static void stopNamespace (String ns , boolean inTargetNamespaceList ) {
251
+ AtomicBoolean isNamespaceStopping = isNamespaceStopping (ns );
254
252
255
- if (stopping != null ) {
256
- stopping .set (true );
253
+ // Remove if namespace not in targetNamespace list
254
+ if (!inTargetNamespaceList ) {
255
+ namespaceStoppingMap .remove (ns );
257
256
}
257
+
258
+ // stop all Domains for namespace being stopped (not active)
259
+ if (isNamespaceStopping .get ()) {
260
+ processor .stopNamespace (ns );
261
+ }
262
+
263
+ // set flag to indicate namespace is stopping.
264
+ isNamespaceStopping .set (true );
265
+
266
+ // unsubscribe from resource events for given namespace
258
267
namespaceStatuses .remove (ns );
259
268
domainWatchers .remove (ns );
260
269
eventWatchers .remove (ns );
@@ -267,12 +276,12 @@ private static void stopNamespace(String ns, boolean remove) {
267
276
private static void stopNamespaces (Collection <String > targetNamespaces ,
268
277
Collection <String > namespacesToStop ) {
269
278
for (String ns : namespacesToStop ) {
270
- stopNamespace (ns , (! targetNamespaces .contains (ns ) ));
279
+ stopNamespace (ns , targetNamespaces .contains (ns ));
271
280
}
272
281
}
273
282
274
283
private static AtomicBoolean isNamespaceStopping (String ns ) {
275
- return isNamespaceStopping .computeIfAbsent (ns , (key ) -> new AtomicBoolean (false ));
284
+ return namespaceStoppingMap .computeIfAbsent (ns , (key ) -> new AtomicBoolean (false ));
276
285
}
277
286
278
287
private static void runSteps (Step firstStep ) {
@@ -294,7 +303,7 @@ static Runnable recheckDomains() {
294
303
295
304
// Check for namespaces that are removed from the operator's
296
305
// targetNamespaces list, or that are deleted from the Kubernetes cluster.
297
- Set <String > namespacesToStop = new TreeSet <>(isNamespaceStopping .keySet ());
306
+ Set <String > namespacesToStop = new TreeSet <>(namespaceStoppingMap .keySet ());
298
307
for (String ns : targetNamespaces ) {
299
308
// the active namespaces are the ones that will not be stopped
300
309
if (delegate .isNamespaceRunning (ns )) {
@@ -403,7 +412,7 @@ private static Collection<String> getTargetNamespaces() {
403
412
return isDedicated ()
404
413
? Collections .singleton (operatorNamespace )
405
414
: getTargetNamespaces (Optional .ofNullable (getHelmVariable .apply ("OPERATOR_TARGET_NAMESPACES" ))
406
- .orElse (tuningAndConfig .get ("targetNamespaces" )), operatorNamespace );
415
+ .orElse (tuningAndConfig .get ("targetNamespaces" )), operatorNamespace );
407
416
}
408
417
409
418
public static boolean isDedicated () {
@@ -450,7 +459,7 @@ private static void waitForDeath() {
450
459
Thread .currentThread ().interrupt ();
451
460
}
452
461
453
- isNamespaceStopping .forEach ((key , value ) -> value .set (true ));
462
+ namespaceStoppingMap .forEach ((key , value ) -> value .set (true ));
454
463
}
455
464
456
465
private static EventWatcher createEventWatcher (String ns , String initialResourceVersion ) {
@@ -528,15 +537,15 @@ private static void dispatchNamespaceWatch(Watch.Response<V1Namespace> item) {
528
537
runSteps (Step .chain (
529
538
ConfigMapHelper .createScriptConfigMapStep (operatorNamespace , ns ),
530
539
createConfigMapStep (ns )));
531
- isNamespaceStopping .put (ns , new AtomicBoolean (false ));
540
+ namespaceStoppingMap .put (ns , new AtomicBoolean (false ));
532
541
}
533
542
break ;
534
543
535
544
case "DELETED" :
536
545
// Mark the namespace as isStopping, which will cause the namespace be stopped
537
546
// the next time when recheckDomains is triggered
538
547
if (delegate .isNamespaceRunning (ns )) {
539
- isNamespaceStopping .put (ns , new AtomicBoolean (true ));
548
+ namespaceStoppingMap .put (ns , new AtomicBoolean (true ));
540
549
}
541
550
542
551
break ;
@@ -904,17 +913,17 @@ public NextAction onSuccess(Packet packet, CallResponse<V1NamespaceList> callRes
904
913
Step strategy = null ;
905
914
if (!namespacesToStart .isEmpty ()) {
906
915
strategy = Step .chain (createDomainCrdAndStartNamespaces (namespacesToStart ),
907
- new CreateNamespaceWatcherStep (intialResourceVersion ));
916
+ new CreateNamespaceWatcherStep (intialResourceVersion ));
908
917
} else {
909
918
strategy = CrdHelper .createDomainCrdStep (version ,
910
- new CreateNamespaceWatcherStep (intialResourceVersion ));
919
+ new CreateNamespaceWatcherStep (intialResourceVersion ));
911
920
}
912
921
return doNext (strategy , packet );
913
922
}
914
923
915
924
private Step createDomainCrdAndStartNamespaces (Collection <String > namespacesToStart ) {
916
925
return CrdHelper .createDomainCrdStep (version ,
917
- new StartNamespacesStep (namespacesToStart , false ));
926
+ new StartNamespacesStep (namespacesToStart , false ));
918
927
}
919
928
920
929
private String getInitialResourceVersion (V1NamespaceList result ) {
@@ -991,7 +1000,7 @@ public boolean isNamespaceRunning(String namespace) {
991
1000
// make sure the map entry is initialized the value to "false" if absent
992
1001
isNamespaceStopping (namespace );
993
1002
994
- return !isNamespaceStopping .get (namespace ).get ();
1003
+ return !namespaceStoppingMap .get (namespace ).get ();
995
1004
}
996
1005
997
1006
@ Override
0 commit comments