Skip to content

Commit

Permalink
removing declared interruptedexception
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Jun 29, 2021
1 parent 1b1a26f commit 85382a1
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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 @@ -18,8 +18,6 @@
import io.fabric8.kubernetes.api.model.ObjectReference;
import io.fabric8.kubernetes.client.dsl.WritableOperation;
import io.fabric8.kubernetes.client.utils.CreateOrReplaceHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.fabric8.kubernetes.api.builder.TypedVisitor;
import io.fabric8.kubernetes.api.builder.Visitor;
Expand Down Expand Up @@ -95,7 +93,6 @@ public class BaseOperation<T extends HasMetadata, L extends KubernetesResourceLi
MixedOperation<T, L, R>,
Resource<T> {

private static final Logger LOG = LoggerFactory.getLogger(BaseOperation.class);
private static final String INVOLVED_OBJECT_NAME = "involvedObject.name";
private static final String INVOLVED_OBJECT_NAMESPACE = "involvedObject.namespace";
private static final String INVOLVED_OBJECT_KIND = "involvedObject.kind";
Expand Down Expand Up @@ -405,15 +402,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 @@ -1113,14 +1102,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 Down Expand Up @@ -1158,6 +1145,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
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 85382a1

Please sign in to comment.