59
59
import io .fabric8 .kubernetes .client .informers .impl .DefaultSharedIndexInformer ;
60
60
import io .fabric8 .kubernetes .client .internal .readiness .Readiness ;
61
61
import io .fabric8 .kubernetes .client .utils .HttpClientUtils ;
62
+ import io .fabric8 .kubernetes .client .utils .KubernetesResourceUtil ;
62
63
import io .fabric8 .kubernetes .client .utils .URLUtils ;
63
64
import io .fabric8 .kubernetes .client .utils .Utils ;
64
65
import io .fabric8 .kubernetes .client .utils .WatcherToggle ;
@@ -123,8 +124,6 @@ public class BaseOperation<T extends HasMetadata, L extends KubernetesResourceLi
123
124
private final boolean reloadingFromServer ;
124
125
private final long gracePeriodSeconds ;
125
126
private final DeletionPropagation propagationPolicy ;
126
- private final long watchRetryInitialBackoffMillis ;
127
- private final double watchRetryBackoffMultiplier ;
128
127
129
128
protected String apiVersion ;
130
129
@@ -146,8 +145,6 @@ protected BaseOperation(OperationContext ctx) {
146
145
this .labelsNotIn = ctx .getLabelsNotIn ();
147
146
this .fields = ctx .getFields ();
148
147
this .fieldsNot = ctx .getFieldsNot ();
149
- this .watchRetryInitialBackoffMillis = ctx .getWatchRetryInitialBackoffMillis ();
150
- this .watchRetryBackoffMultiplier = ctx .getWatchRetryBackoffMultiplier ();
151
148
}
152
149
153
150
public BaseOperation <T , L , R > newInstance (OperationContext context ) {
@@ -1126,42 +1123,27 @@ public T waitUntilReady(long amount, TimeUnit timeUnit) throws InterruptedExcept
1126
1123
@ Override
1127
1124
public T waitUntilCondition (Predicate <T > condition , long amount , TimeUnit timeUnit )
1128
1125
throws InterruptedException {
1129
- return waitUntilConditionWithRetries (condition , timeUnit .toNanos (amount ), watchRetryInitialBackoffMillis );
1130
- }
1131
-
1132
- private T waitUntilConditionWithRetries (Predicate <T > condition , long timeoutNanos , long backoffMillis )
1133
- throws InterruptedException {
1134
- ListOptions options = null ;
1135
1126
1136
- if (resourceVersion != null ) {
1137
- options = createListOptions (resourceVersion );
1138
- }
1139
-
1140
- long currentBackOff = backoffMillis ;
1141
- long remainingNanosToWait = timeoutNanos ;
1127
+ long remainingNanosToWait = timeUnit .toNanos (amount );
1142
1128
while (remainingNanosToWait > 0 ) {
1143
1129
1144
1130
T item = fromServer ().get ();
1145
1131
if (condition .test (item )) {
1146
1132
return item ;
1147
- } else if (options == null ) {
1148
- options = createListOptions (getResourceVersion (item ));
1149
1133
}
1150
1134
1151
1135
final WaitForConditionWatcher <T > watcher = new WaitForConditionWatcher <>(condition );
1152
1136
final long startTime = System .nanoTime ();
1153
- try (Watch ignored = watch (options , watcher )) {
1137
+ try (Watch ignored = watch (KubernetesResourceUtil . getResourceVersion ( item ) , watcher )) {
1154
1138
return watcher .getFuture ().get (remainingNanosToWait , NANOSECONDS );
1155
1139
} catch (ExecutionException e ) {
1156
1140
Throwable cause = e .getCause ();
1157
- if (cause instanceof WatcherException && ((WatcherException ) cause ).isShouldRetry ()) {
1158
- LOG .debug ("retryable watch exception encountered, retrying after {} millis" , currentBackOff , cause );
1159
- Thread .sleep (currentBackOff );
1160
- currentBackOff *= watchRetryBackoffMultiplier ;
1141
+ if (cause instanceof WatcherException && ((WatcherException )cause ).isHttpGone ()) {
1142
+ LOG .debug ("Restarting the watch due to http gone" );
1161
1143
remainingNanosToWait -= (System .nanoTime () - startTime );
1162
- } else {
1163
- throw KubernetesClientException .launderThrowable (cause );
1144
+ continue ;
1164
1145
}
1146
+ throw KubernetesClientException .launderThrowable (cause );
1165
1147
} catch (TimeoutException e ) {
1166
1148
break ;
1167
1149
}
@@ -1171,16 +1153,6 @@ private T waitUntilConditionWithRetries(Predicate<T> condition, long timeoutNano
1171
1153
throw new IllegalArgumentException (type .getSimpleName () + " with name:[" + name + "] in namespace:[" + namespace + "] matching condition not found!" );
1172
1154
}
1173
1155
1174
- private static String getResourceVersion (HasMetadata item ) {
1175
- return (item == null ) ? null : item .getMetadata ().getResourceVersion ();
1176
- }
1177
-
1178
- private static ListOptions createListOptions (String resourceVersion ) {
1179
- return new ListOptionsBuilder ()
1180
- .withResourceVersion (resourceVersion )
1181
- .build ();
1182
- }
1183
-
1184
1156
public void setType (Class <T > type ) {
1185
1157
this .type = type ;
1186
1158
}
0 commit comments