|
3 | 3 |
|
4 | 4 | package oracle.kubernetes.operator; |
5 | 5 |
|
| 6 | +import java.io.IOException; |
6 | 7 | import java.util.ArrayList; |
7 | 8 | import java.util.Collection; |
8 | 9 | import java.util.Collections; |
@@ -91,19 +92,34 @@ public class Main { |
91 | 92 | private static final FiberGate domainUpdaters = new FiberGate(engine); |
92 | 93 | private static final ConcurrentMap<String, DomainPresenceInfo> domains = new ConcurrentHashMap<String, DomainPresenceInfo>(); |
93 | 94 |
|
94 | | - private static final ConfigMapConsumer config = new ConfigMapConsumer("/operator/config"); |
| 95 | + private static final ConfigMapConsumer config; |
| 96 | + static { |
| 97 | + try { |
| 98 | + config = new ConfigMapConsumer(engine.getExecutor(), "/operator/config", () -> { |
| 99 | + LOGGER.info(MessageKeys.TUNING_PARAMETERS); |
| 100 | + setTuningParameters(); |
| 101 | + }); |
| 102 | + } catch (IOException e) { |
| 103 | + LOGGER.warning(MessageKeys.EXCEPTION, e); |
| 104 | + throw new RuntimeException(e); |
| 105 | + } |
| 106 | + } |
95 | 107 |
|
96 | 108 | // tuning parameters |
97 | | - private static final int statusUpdateTimeoutSeconds = (int) readTuningParameter("statusUpdateTimeoutSeconds", 10); |
98 | | - private static final int unchangedCountToDelayStatusRecheck = (int) readTuningParameter("statueUpdateUnchangedCountToDelayStatusRecheck", 10); |
99 | | - private static final long initialShortDelay = readTuningParameter("statusUpdateInitialShortDelay", 3); |
100 | | - private static final long eventualLongDelay = readTuningParameter("statusUpdateEventualLongDelay", 30); |
101 | | - static { |
102 | | - int callRequestLimit = (int) readTuningParameter("callRequestLimit", 500); |
103 | | - int callMaxRetryCount = (int) readTuningParameter("callMaxRetryCount", 5); |
104 | | - int callTimeoutSeconds = (int) readTuningParameter("callTimeoutSeconds", 10); |
| 109 | + private static int statusUpdateTimeoutSeconds; |
| 110 | + private static int unchangedCountToDelayStatusRecheck; |
| 111 | + private static long initialShortDelay; |
| 112 | + private static long eventualLongDelay; |
| 113 | + private static void setTuningParameters() { |
| 114 | + statusUpdateTimeoutSeconds = (int) config.readTuningParameter("statusUpdateTimeoutSeconds", 10); |
| 115 | + unchangedCountToDelayStatusRecheck = (int) config.readTuningParameter("statueUpdateUnchangedCountToDelayStatusRecheck", 10); |
| 116 | + initialShortDelay = config.readTuningParameter("statusUpdateInitialShortDelay", 3); |
| 117 | + eventualLongDelay = config.readTuningParameter("statusUpdateEventualLongDelay", 30); |
| 118 | + int callRequestLimit = (int) config.readTuningParameter("callRequestLimit", 500); |
| 119 | + int callMaxRetryCount = (int) config.readTuningParameter("callMaxRetryCount", 5); |
| 120 | + int callTimeoutSeconds = (int) config.readTuningParameter("callTimeoutSeconds", 10); |
105 | 121 | CallBuilder.setTuningParameters(callRequestLimit, callMaxRetryCount, callTimeoutSeconds); |
106 | | - int watchLifetime = (int) readTuningParameter("watchLifetime", 45); |
| 122 | + int watchLifetime = (int) config.readTuningParameter("watchLifetime", 45); |
107 | 123 | WatchBuilder.setTuningParameters(watchLifetime); |
108 | 124 | } |
109 | 125 |
|
@@ -426,19 +442,6 @@ private static void normalizeDomainSpec(DomainSpec spec) { |
426 | 442 | } |
427 | 443 | } |
428 | 444 |
|
429 | | - private static long readTuningParameter(String parameter, long defaultValue) { |
430 | | - String val = config.get(parameter); |
431 | | - if (val != null) { |
432 | | - try { |
433 | | - return Long.parseLong(val); |
434 | | - } catch (NumberFormatException nfe) { |
435 | | - LOGGER.warning(MessageKeys.EXCEPTION, nfe); |
436 | | - } |
437 | | - } |
438 | | - |
439 | | - return defaultValue; |
440 | | - } |
441 | | - |
442 | 445 | /** |
443 | 446 | * Restarts the admin server, if already running |
444 | 447 | * @param principal Service principal |
@@ -499,7 +502,7 @@ private static void scheduleDomainStatusUpdating(DomainPresenceInfo info) { |
499 | 502 | public void run() { |
500 | 503 | Runnable r = this; // resolve visibility |
501 | 504 | Packet packet = new Packet(); |
502 | | - packet.getComponents().put(ProcessingConstants.DOMAIN_COMPONENT_NAME, Component.createFor(info, version)); |
| 505 | + packet.getComponents().put(ProcessingConstants.DOMAIN_COMPONENT_NAME, Component.createFor(info, version, config)); |
503 | 506 | Step strategy = DomainStatusUpdater.createStatusStep(statusUpdateTimeoutSeconds, null); |
504 | 507 | domainUpdaters.startFiberIfNoCurrentFiber(domainUID, strategy, packet, new CompletionCallback() { |
505 | 508 | @Override |
@@ -601,7 +604,7 @@ private static void doCheckAndCreateDomainPresence( |
601 | 604 | String ns = dom.getMetadata().getNamespace(); |
602 | 605 | if (initialized.getOrDefault(ns, Boolean.FALSE)) { |
603 | 606 | PodWatcher pw = podWatchers.get(ns); |
604 | | - p.getComponents().put(ProcessingConstants.DOMAIN_COMPONENT_NAME, Component.createFor(info, version, pw)); |
| 607 | + p.getComponents().put(ProcessingConstants.DOMAIN_COMPONENT_NAME, Component.createFor(info, version, pw, config)); |
605 | 608 | p.put(ProcessingConstants.PRINCIPAL, principal); |
606 | 609 |
|
607 | 610 | if (explicitRestartAdmin) { |
@@ -1514,8 +1517,7 @@ public NextAction onSuccess(Packet packet, V1Status result, int statusCode, Map< |
1514 | 1517 | private static Collection<String> getTargetNamespaces(String namespace) { |
1515 | 1518 | Collection<String> targetNamespaces = new ArrayList<String>(); |
1516 | 1519 |
|
1517 | | - ConfigMapConsumer cmc = new ConfigMapConsumer("/operator/config"); |
1518 | | - String tnValue = cmc.get("targetNamespaces"); |
| 1520 | + String tnValue = config.get("targetNamespaces"); |
1519 | 1521 | if (tnValue != null) { |
1520 | 1522 | StringTokenizer st = new StringTokenizer(tnValue, ","); |
1521 | 1523 | while (st.hasMoreTokens()) { |
|
0 commit comments