Skip to content

Commit

Permalink
removing declared interruptedexception
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins authored and manusa committed Jun 29, 2021
1 parent 3f88189 commit 64dce1f
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 32 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
##### DSL Changes:
- #3127 `StatusUpdatable.updateStatus` deprecated, please use patchStatus, editStatus, or replaceStatus
- #3239 deprecated methods on SharedInformerFactory directly dealing with the OperationContext, withName, and withNamespace - the Informable interface should be used instead.
- #3271 `Waitable.waitUntilReady` and `Waitable.waitUntilCondition` with throw a KubernetesClientTimeoutException instead of an IllegalArgumentException on timeout.
- #3271 `Waitable.waitUntilReady` and `Waitable.waitUntilCondition` with throw a KubernetesClientTimeoutException instead of an IllegalArgumentException on timeout. The methods will also no longer throw an interrupted exception.
`Waitable.withWaitRetryBackoff` and the associated constants are now deprecated.

##### Util Changes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public interface Waitable<T, P> {
@Deprecated
double DEFAULT_BACKOFF_MULTIPLIER = 2d;

T waitUntilReady(long amount, TimeUnit timeUnit) throws InterruptedException;
T waitUntilReady(long amount, TimeUnit timeUnit);

T waitUntilCondition(Predicate<P> condition, long amount, TimeUnit timeUnit) throws InterruptedException;
T waitUntilCondition(Predicate<P> condition, long amount, TimeUnit timeUnit);

/**
* Configure the backoff strategy to use when waiting for conditions, in case the watcher encounters a retryable error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,7 @@ public final T createOrReplace(T... items) {
CreateOrReplaceHelper<T> createOrReplaceHelper = new CreateOrReplaceHelper<>(
this::create,
this::replace,
m -> {
try {
return waitUntilCondition(Objects::nonNull, 1, TimeUnit.SECONDS);
} catch (InterruptedException interruptedException) {
LOG.warn("Interrupted while waiting for the resource to be created or replaced. Gracefully assuming the resource has not been created and doesn't exist. ({})", interruptedException.getMessage());
Thread.currentThread().interrupt();
}
return null;
},
m -> waitUntilCondition(Objects::nonNull, 1, TimeUnit.SECONDS),
m -> fromServer().get()
);

Expand Down Expand Up @@ -979,14 +971,12 @@ public final Boolean isReady() {
}

@Override
public T waitUntilReady(long amount, TimeUnit timeUnit) throws InterruptedException {
public T waitUntilReady(long amount, TimeUnit timeUnit) {
return waitUntilCondition(resource -> Objects.nonNull(resource) && getReadiness().isReady(resource), amount, timeUnit);
}

@Override
public T waitUntilCondition(Predicate<T> condition, long amount, TimeUnit timeUnit)
throws InterruptedException {

public T waitUntilCondition(Predicate<T> condition, long amount, TimeUnit timeUnit) {
CompletableFuture<T> future = new CompletableFuture<>();
// tests the condition, trapping any exceptions
Consumer<T> tester = obj -> {
Expand All @@ -1004,7 +994,7 @@ public T waitUntilCondition(Predicate<T> condition, long amount, TimeUnit timeUn
tester.accept(null);
}
}, new ResourceEventHandler<T>() {

@Override
public void onAdd(T obj) {
tester.accept(obj);
Expand All @@ -1024,6 +1014,9 @@ public void onDelete(T obj, boolean deletedFinalStateUnknown) {
future.whenComplete((r,t) -> informer.stop());
informer.run();
return future.get(amount, timeUnit);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw KubernetesClientException.launderThrowable(e.getCause());
} catch (ExecutionException e) {
throw KubernetesClientException.launderThrowable(e.getCause());
} catch (TimeoutException e) {
Expand Down Expand Up @@ -1071,7 +1064,7 @@ public SharedIndexInformer<T> inform(ResourceEventHandler<T> handler, long resyn
private DefaultSharedIndexInformer<T, L> createInformer(long resync, Consumer<L> onList, ResourceEventHandler<T> handler) {
T i = getItem();
String name = (Utils.isNotNullOrEmpty(getName()) || i != null) ? checkName(i) : null;

// use the local context / namespace
DefaultSharedIndexInformer<T, L> informer = new DefaultSharedIndexInformer<>(getType(), new ListerWatcher<T, L>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,15 @@ public final Boolean isReady() {
}

@Override
public HasMetadata waitUntilReady(long amount, TimeUnit timeUnit) throws InterruptedException {
public HasMetadata waitUntilReady(long amount, TimeUnit timeUnit) {
HasMetadata meta = acceptVisitors(asHasMetadata(get()), visitors);
ResourceHandler<HasMetadata, ?> h = handlerOf(meta);
return h.waitUntilReady(client, config, meta.getMetadata().getNamespace(), meta, amount, timeUnit);
try {
return h.waitUntilReady(client, config, meta.getMetadata().getNamespace(), meta, amount, timeUnit);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw KubernetesClientException.launderThrowable(e);
}
}

@Override
Expand All @@ -263,10 +268,15 @@ public VisitFromServerWritable<HasMetadata> dryRun(boolean isDryRun) {

@Override
public HasMetadata waitUntilCondition(Predicate<HasMetadata> condition, long amount,
TimeUnit timeUnit) throws InterruptedException {
TimeUnit timeUnit) {
HasMetadata meta = acceptVisitors(asHasMetadata(get()), visitors);
ResourceHandler<HasMetadata, ?> h = handlerOf(meta);
return h.waitUntilCondition(client, config, meta.getMetadata().getNamespace(), meta, condition, amount, timeUnit);
try {
return h.waitUntilCondition(client, config, meta.getMetadata().getNamespace(), meta, condition, amount, timeUnit);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw KubernetesClientException.launderThrowable(e);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ public class NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImp
private final Boolean cascading;

@Override
public List<HasMetadata> waitUntilReady(final long amount, final TimeUnit timeUnit) throws InterruptedException {
public List<HasMetadata> waitUntilReady(final long amount, final TimeUnit timeUnit) {
return waitUntilCondition(resource -> Objects.nonNull(resource) && getReadiness().isReady(resource), amount, timeUnit);
}

@Override
public List<HasMetadata> waitUntilCondition(Predicate<HasMetadata> condition,
long amount,
TimeUnit timeUnit) throws InterruptedException {
TimeUnit timeUnit) {
List<HasMetadata> items = acceptVisitors(asHasMetadata(item, true), visitors);
if (items.isEmpty()) {
return Collections.emptyList();
Expand Down Expand Up @@ -126,6 +126,9 @@ public List<HasMetadata> waitUntilCondition(Predicate<HasMetadata> condition,
} catch (ExecutionException e) {
itemsWithConditionNotMatched.add(meta);
logAsNotReady(e.getCause(), meta);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw KubernetesClientException.launderThrowable(e);
}
++i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ServiceOperationsImpl newInstance(OperationContext context) {
}

@Override
public Service waitUntilReady(long amount, TimeUnit timeUnit) throws InterruptedException {
public Service waitUntilReady(long amount, TimeUnit timeUnit) {
long started = System.nanoTime();
super.waitUntilReady(amount, timeUnit);
long alreadySpent = System.nanoTime() - started;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ public static void waitUntilReadyBeforeFetchingLogs(PodResource<Pod> podOperatio
if (pod != null && pod.getStatus() != null && pod.getStatus().getPhase().equals("Pending")) {
podOperation.waitUntilReady(logWaitTimeout, TimeUnit.SECONDS);
}
} catch (InterruptedException interruptedException) {
Thread.currentThread().interrupt();
LOG.debug("Interrupted while waiting for Pod to become Ready: {}", interruptedException.getMessage());
} catch (Exception otherException) {
LOG.debug("Error while waiting for Pod to become Ready: {}", otherException.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
import io.fabric8.kubernetes.api.model.PodList;
import io.fabric8.kubernetes.api.model.batch.v1.Job;
import io.fabric8.kubernetes.api.model.batch.v1.JobBuilder;
import io.fabric8.kubernetes.client.*;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -74,9 +77,6 @@ public static void main(String[] args) {

} catch (KubernetesClientException e) {
logger.error("Unable to create job", e);
} catch (InterruptedException interruptedException) {
logger.warn("Interrupted while waiting for the job to be ready: {}", interruptedException.getMessage());
Thread.currentThread().interrupt();
}
}
}

0 comments on commit 64dce1f

Please sign in to comment.