@@ -82,10 +82,13 @@ public class Main {
82
82
private static final ConcurrentMap <String , Fiber > domainUpdaters = new ConcurrentHashMap <String , Fiber >();
83
83
private static final ConcurrentMap <String , DomainPresenceInfo > domains = new ConcurrentHashMap <String , DomainPresenceInfo >();
84
84
private static final AtomicBoolean stopping = new AtomicBoolean (false );
85
+ private static String principal ;
85
86
private static RestServer restServer = null ;
86
87
private static Thread livenessThread = null ;
87
88
private static Map <String , DomainWatcher > domainWatchers = new HashMap <>();
88
89
private static Map <String , PodWatcher > podWatchers = new HashMap <>();
90
+ private static Map <String , ServiceWatcher > serviceWatchers = new HashMap <>();
91
+ private static Map <String , IngressWatcher > ingressWatchers = new HashMap <>();
89
92
90
93
private static final Engine engine = new Engine ("operator" );
91
94
@@ -116,7 +119,7 @@ public static void main(String[] args) {
116
119
if (serviceAccountName == null ) {
117
120
serviceAccountName = "default" ;
118
121
}
119
- String principal = "system:serviceaccount:" + namespace + ":" + serviceAccountName ;
122
+ principal = "system:serviceaccount:" + namespace + ":" + serviceAccountName ;
120
123
121
124
LOGGER .info (MessageKeys .OP_CONFIG_NAMESPACE , namespace );
122
125
StringBuilder tns = new StringBuilder ();
@@ -160,8 +163,9 @@ public static void main(String[] args) {
160
163
// this would happen when the Domain was running BEFORE the Operator starts up
161
164
LOGGER .info (MessageKeys .LISTING_DOMAINS );
162
165
for (String ns : targetNamespaces ) {
163
- PodWatcher pw = createPodWatcher (ns );
164
- podWatchers .put (ns , pw );
166
+ podWatchers .put (ns , createPodWatcher (ns ));
167
+ serviceWatchers .put (ns , createServiceWatcher (ns ));
168
+ ingressWatchers .put (ns , createIngressWatcher (ns ));
165
169
166
170
Step domainList = CallBuilder .create ().listDomainAsync (ns , new ResponseStep <DomainList >(null ) {
167
171
@ Override
@@ -178,12 +182,12 @@ public NextAction onSuccess(Packet packet, DomainList result, int statusCode,
178
182
Map <String , List <String >> responseHeaders ) {
179
183
if (result != null ) {
180
184
for (Domain dom : result .getItems ()) {
181
- doCheckAndCreateDomainPresence (principal , dom );
185
+ doCheckAndCreateDomainPresence (dom );
182
186
}
183
187
}
184
188
185
189
// main logic now happens in the watch handlers
186
- domainWatchers .put (ns , createDomainWatcher (principal , ns , result != null ? result .getMetadata ().getResourceVersion () : "" ));
190
+ domainWatchers .put (ns , createDomainWatcher (ns , result != null ? result .getMetadata ().getResourceVersion () : "" ));
187
191
return doNext (packet );
188
192
}
189
193
});
@@ -357,7 +361,7 @@ public static void doRestartAdmin(String principal, String domainUID) {
357
361
if (info != null ) {
358
362
Domain dom = info .getDomain ();
359
363
if (dom != null ) {
360
- doCheckAndCreateDomainPresence (principal , dom , true , null , null );
364
+ doCheckAndCreateDomainPresence (dom , true , null , null );
361
365
}
362
366
}
363
367
}
@@ -374,7 +378,7 @@ public static void doRollingRestartServers(String principal, String domainUID, L
374
378
if (info != null ) {
375
379
Domain dom = info .getDomain ();
376
380
if (dom != null ) {
377
- doCheckAndCreateDomainPresence (principal , dom , false , servers , null );
381
+ doCheckAndCreateDomainPresence (dom , false , servers , null );
378
382
}
379
383
}
380
384
}
@@ -391,17 +395,17 @@ public static void doRollingRestartClusters(String principal, String domainUID,
391
395
if (info != null ) {
392
396
Domain dom = info .getDomain ();
393
397
if (dom != null ) {
394
- doCheckAndCreateDomainPresence (principal , dom , false , null , clusters );
398
+ doCheckAndCreateDomainPresence (dom , false , null , clusters );
395
399
}
396
400
}
397
401
}
398
402
399
- private static void doCheckAndCreateDomainPresence (String principal , Domain dom ) {
400
- doCheckAndCreateDomainPresence (principal , dom , false , null , null );
403
+ private static void doCheckAndCreateDomainPresence (Domain dom ) {
404
+ doCheckAndCreateDomainPresence (dom , false , null , null );
401
405
}
402
406
403
407
private static void doCheckAndCreateDomainPresence (
404
- String principal , Domain dom , boolean explicitRestartAdmin ,
408
+ Domain dom , boolean explicitRestartAdmin ,
405
409
List <String > explicitRestartServers , List <String > explicitRestartClusters ) {
406
410
LOGGER .entering ();
407
411
@@ -927,29 +931,14 @@ public ManagedServerDownStep(String serverName, ServerKubernetesObjects sko, Ste
927
931
928
932
@ Override
929
933
public NextAction apply (Packet packet ) {
930
- V1ObjectMeta meta = sko .getPod ().getMetadata ();
931
- V1DeleteOptions deleteOptions = new V1DeleteOptions ();
932
934
List <V1Service > services = new ArrayList <V1Service >();
933
935
services .add (sko .getService ());
934
936
services .addAll (sko .getChannels ().values ());
935
937
936
938
return doNext (IngressHelper .createRemoveServerStep (serverName , sko .getService (),
937
- new DeleteServiceListStep (services , CallBuilder .create ().deletePodAsync (meta .getName (), meta .getNamespace (), deleteOptions , new ResponseStep <V1Status >(next ) {
938
- @ Override
939
- public NextAction onFailure (Packet packet , ApiException e , int statusCode ,
940
- Map <String , List <String >> responseHeaders ) {
941
- if (statusCode == CallBuilder .NOT_FOUND ) {
942
- return onSuccess (packet , null , statusCode , responseHeaders );
943
- }
944
- return super .onFailure (packet , e , statusCode , responseHeaders );
945
- }
946
-
947
- @ Override
948
- public NextAction onSuccess (Packet packet , V1Status result , int statusCode ,
949
- Map <String , List <String >> responseHeaders ) {
950
- return doNext (new ManagedServerDownFinalizeStep (serverName , next ), packet );
951
- }
952
- }))), packet );
939
+ new DeleteServiceListStep (services ,
940
+ PodHelper .deletePodStep (sko ,
941
+ new ManagedServerDownFinalizeStep (serverName , next )))), packet );
953
942
}
954
943
}
955
944
@@ -1256,22 +1245,109 @@ public static boolean getStopping() {
1256
1245
return stopping .get ();
1257
1246
}
1258
1247
1259
- private static DomainWatcher createDomainWatcher (String principal , String namespace , String initialResourceVersion ) {
1260
- return DomainWatcher .create (namespace , initialResourceVersion , ( item ) -> { dispatchDomainWatch ( item , principal ); } , stopping );
1248
+ private static DomainWatcher createDomainWatcher (String namespace , String initialResourceVersion ) {
1249
+ return DomainWatcher .create (namespace , initialResourceVersion , Main :: dispatchDomainWatch , stopping );
1261
1250
}
1262
1251
1263
1252
private static PodWatcher createPodWatcher (String namespace ) {
1264
- return PodWatcher .create (namespace , "" , stopping );
1253
+ return PodWatcher .create (namespace , "" , Main :: dispatchPodWatch , stopping );
1265
1254
}
1266
1255
1256
+ private static void dispatchPodWatch (Watch .Response <V1Pod > item ) {
1257
+ switch (item .type ) {
1258
+ case "DELETED" :
1259
+ V1Pod p = item .object ;
1260
+ V1ObjectMeta metadata = p .getMetadata ();
1261
+ String domainUID = metadata .getLabels ().get (LabelConstants .DOMAINUID_LABEL );
1262
+ String serverName = metadata .getLabels ().get (LabelConstants .SERVERNAME_LABEL );
1263
+ if (domainUID != null ) {
1264
+ DomainPresenceInfo info = domains .get (domainUID );
1265
+ if (info != null && serverName != null ) {
1266
+ ServerKubernetesObjects sko = info .getServers ().get (serverName );
1267
+ if (sko != null ) {
1268
+ if (sko .getPod () != null ) {
1269
+ // Pod was deleted, but sko still contains a non-null entry
1270
+ LOGGER .info (MessageKeys .POD_DELETED , domainUID , metadata .getNamespace (), serverName );
1271
+ doCheckAndCreateDomainPresence (info .getDomain ());
1272
+ }
1273
+ }
1274
+ }
1275
+ }
1276
+ break ;
1277
+
1278
+ case "ERROR" :
1279
+ default :
1280
+ }
1281
+ }
1282
+
1283
+
1284
+ private static ServiceWatcher createServiceWatcher (String namespace ) {
1285
+ return ServiceWatcher .create (namespace , "" , Main ::dispatchServiceWatch , stopping );
1286
+ }
1287
+
1288
+ private static void dispatchServiceWatch (Watch .Response <V1Service > item ) {
1289
+ switch (item .type ) {
1290
+ case "DELETED" :
1291
+ V1Service s = item .object ;
1292
+ V1ObjectMeta metadata = s .getMetadata ();
1293
+ String domainUID = metadata .getLabels ().get (LabelConstants .DOMAINUID_LABEL );
1294
+ String serverName = metadata .getLabels ().get (LabelConstants .SERVERNAME_LABEL );
1295
+ String channelName = metadata .getLabels ().get (LabelConstants .CHANNELNAME_LABEL );
1296
+ if (domainUID != null ) {
1297
+ DomainPresenceInfo info = domains .get (domainUID );
1298
+ if (info != null && serverName != null ) {
1299
+ ServerKubernetesObjects sko = info .getServers ().get (serverName );
1300
+ if (sko != null ) {
1301
+ if ((channelName != null ? sko .getChannels ().get (channelName ) : sko .getService ()) != null ) {
1302
+ // Service was deleted, but sko still contains a non-null entry
1303
+ LOGGER .info (MessageKeys .SERVICE_DELETED , domainUID , metadata .getNamespace (), serverName );
1304
+ doCheckAndCreateDomainPresence (info .getDomain ());
1305
+ }
1306
+ }
1307
+ }
1308
+ }
1309
+ break ;
1310
+
1311
+ case "ERROR" :
1312
+ default :
1313
+ }
1314
+ }
1315
+
1316
+ private static IngressWatcher createIngressWatcher (String namespace ) {
1317
+ return IngressWatcher .create (namespace , "" , Main ::dispatchIngressWatch , stopping );
1318
+ }
1319
+
1320
+ private static void dispatchIngressWatch (Watch .Response <V1beta1Ingress > item ) {
1321
+ switch (item .type ) {
1322
+ case "DELETED" :
1323
+ V1beta1Ingress i = item .object ;
1324
+ V1ObjectMeta metadata = i .getMetadata ();
1325
+ String domainUID = metadata .getLabels ().get (LabelConstants .DOMAINUID_LABEL );
1326
+ String clusterName = metadata .getLabels ().get (LabelConstants .CLUSTERNAME_LABEL );
1327
+ if (domainUID != null ) {
1328
+ DomainPresenceInfo info = domains .get (domainUID );
1329
+ if (info != null && clusterName != null ) {
1330
+ if (clusterName != null && info .getIngresses ().get (clusterName ) != null ) {
1331
+ // Ingress was deleted, but sko still contains a non-null entry
1332
+ LOGGER .info (MessageKeys .INGRESS_DELETED , domainUID , metadata .getNamespace (), clusterName );
1333
+ doCheckAndCreateDomainPresence (info .getDomain ());
1334
+ }
1335
+ }
1336
+ }
1337
+ break ;
1338
+
1339
+ case "ERROR" :
1340
+ default :
1341
+ }
1342
+ }
1343
+
1267
1344
/**
1268
1345
* Dispatch the Domain event to the appropriate handler.
1269
1346
*
1270
1347
* @param item An item received from a Watch response.
1271
1348
* @param principal The name of the principal that will be used in this watch.
1272
1349
*/
1273
- public static void dispatchDomainWatch (Watch .Response <Domain > item , String principal ) {
1274
-
1350
+ private static void dispatchDomainWatch (Watch .Response <Domain > item ) {
1275
1351
try {
1276
1352
Domain d ;
1277
1353
String domainUID ;
@@ -1281,7 +1357,7 @@ public static void dispatchDomainWatch(Watch.Response<Domain> item, String princ
1281
1357
d = item .object ;
1282
1358
domainUID = d .getSpec ().getDomainUID ();
1283
1359
LOGGER .info (MessageKeys .WATCH_DOMAIN , domainUID );
1284
- doCheckAndCreateDomainPresence (principal , d );
1360
+ doCheckAndCreateDomainPresence (d );
1285
1361
break ;
1286
1362
1287
1363
case "DELETED" :
0 commit comments