Skip to content

Commit 4de9343

Browse files
committed
Minimum watch retry delay
1 parent 42d8200 commit 4de9343

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

operator/src/main/java/oracle/kubernetes/operator/TuningParameters.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ public CallBuilderTuning(int callRequestLimit, int callMaxRetryCount, int callTi
6363

6464
public static class WatchTuning {
6565
public final int watchLifetime;
66+
public final int watchMinimumDelay;
6667

67-
public WatchTuning(int watchLifetime) {
68+
public WatchTuning(int watchLifetime, int watchMinimumDelay) {
6869
this.watchLifetime = watchLifetime;
70+
this.watchMinimumDelay = watchMinimumDelay;
6971
}
7072
}
7173

operator/src/main/java/oracle/kubernetes/operator/TuningParametersImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ private void update() {
6666
(int) readTuningParameter("callMaxRetryCount", 5),
6767
(int) readTuningParameter("callTimeoutSeconds", 10));
6868

69-
WatchTuning watch = new WatchTuning((int) readTuningParameter("watchLifetime", 300));
69+
WatchTuning watch =
70+
new WatchTuning(
71+
(int) readTuningParameter("watchLifetime", 300),
72+
(int) readTuningParameter("watchMinimumDelay", 5));
7073

7174
PodTuning pod =
7275
new PodTuning(

operator/src/main/java/oracle/kubernetes/operator/Watcher.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ abstract class Watcher<T> {
3838
private AtomicBoolean stopping;
3939
private WatchListener<T> listener;
4040
private Thread thread = null;
41+
private long lastInitialize = 0;
4142

4243
/**
4344
* Constructs a watcher without specifying a listener. Needed when the listener is the watch
@@ -120,6 +121,16 @@ protected boolean isStopping() {
120121
}
121122

122123
private void watchForEvents() {
124+
long now = System.currentTimeMillis();
125+
long delta = now - lastInitialize;
126+
if (lastInitialize != 0 && delta > (tuning.watchMinimumDelay * 1000)) {
127+
try {
128+
Thread.sleep(delta);
129+
} catch (InterruptedException ex) {
130+
LOGGER.warning(MessageKeys.EXCEPTION, ex);
131+
}
132+
lastInitialize = System.currentTimeMillis();
133+
}
123134
try (WatchI<T> watch =
124135
initiateWatch(
125136
new WatchBuilder()

operator/src/test/java/oracle/kubernetes/operator/WatcherTestBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public abstract class WatcherTestBase extends ThreadFactoryTestBase
4141

4242
private int resourceVersion = INITIAL_RESOURCE_VERSION;
4343

44-
protected WatchTuning tuning = new WatchTuning(30);
44+
protected WatchTuning tuning = new WatchTuning(30, 5);
4545

4646
private V1ObjectMeta createMetaData() {
4747
return createMetaData("test", NAMESPACE);

operator/src/test/java/oracle/kubernetes/operator/helpers/DomainIntrospectorJobTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ static String getJobName() {
290290
}
291291

292292
FiberTestSupport.StepFactory getStepFactory() {
293-
return next -> JobHelper.createDomainIntrospectorJobStep(new WatchTuning(30), next);
293+
return next -> JobHelper.createDomainIntrospectorJobStep(new WatchTuning(30, 5), next);
294294
}
295295

296296
V1PodList createListPods() {

0 commit comments

Comments
 (0)