Skip to content

Commit

Permalink
fix #4516: switching list delete to a (mostly) parallel operation
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Nov 22, 2022
1 parent d544292 commit 4f71c87
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
Expand Up @@ -21,15 +21,15 @@
public interface Timeoutable {

/**
* Wait for the given operation timeout. For list contexts it applies to each delete operation.
* Wait for the given operation timeout.
*
* @param timeout 0 indicates no wait
* @param unit
*/
Object withTimeout(long timeout, TimeUnit unit);

/**
* Wait for the given operation timeout in milliseconds. For list contexts it applies to each delete operation.
* Wait for the given operation timeout in milliseconds.
*
* @param timeoutInMillis 0 indicates no wait
*/
Expand Down
Expand Up @@ -43,6 +43,7 @@
import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.kubernetes.client.dsl.Waitable;
import io.fabric8.kubernetes.client.dsl.base.PatchContext;
import io.fabric8.kubernetes.client.dsl.base.PatchType;
import io.fabric8.kubernetes.client.extension.ExtensibleResource;
Expand Down Expand Up @@ -452,13 +453,17 @@ static void toStatusDetails(KubernetesResource obj, List<StatusDetails> details)
@Override
public List<StatusDetails> delete() {
List<StatusDetails> deleted = deleteAll();
if (this.context.getTimeout() > 0) {
waitForDelete(deleted, this.context, this);
return deleted;
}

static void waitForDelete(List<StatusDetails> deleted, OperationContext context,
Waitable<?, ? extends HasMetadata> waitable) {
if (context.getTimeout() > 0) {
Set<String> uids = deleted.stream().map(StatusDetails::getUid).collect(Collectors.toSet());
CompletableFuture<List<T>> delete = this
.informOnCondition(l -> l.stream().map(i -> i.getMetadata().getUid()).noneMatch(uid -> uids.contains(uid)));
Utils.waitUntilReadyOrFail(delete, this.context.getTimeout(), this.context.getTimeoutUnit());
waitable.waitUntilCondition(h -> h == null || !uids.contains(h.getMetadata().getUid()), context.getTimeout(),
context.getTimeoutUnit());
}
return deleted;
}

protected List<StatusDetails> deleteAll() {
Expand Down
Expand Up @@ -203,7 +203,9 @@ public List<HasMetadata> createOrReplace() {

@Override
public List<StatusDetails> delete() {
return resources().flatMap(r -> r.delete().stream()).collect(Collectors.toList());
List<StatusDetails> deleted = resources().flatMap(r -> r.delete().stream()).collect(Collectors.toList());
BaseOperation.waitForDelete(deleted, this.context, this);
return deleted;
}

@Override
Expand Down
Expand Up @@ -499,8 +499,7 @@ public <C extends Client> C clientInWriteContext(Class<C> clazz) {
// operationcontext
OperationContext newContext = HasMetadataOperationsImpl.defaultContext(client).withDryRun(getDryRun())
.withGracePeriodSeconds(getGracePeriodSeconds()).withPropagationPolicy(getPropagationPolicy())
.withReloadingFromServer(isReloadingFromServer()).withFieldValidation(this.fieldValidation)
.withTimeout(this.timeout, this.timeoutUnit);
.withReloadingFromServer(isReloadingFromServer()).withFieldValidation(this.fieldValidation);

// check before setting to prevent flipping the default flag
if (!Objects.equals(getNamespace(), newContext.getNamespace())
Expand Down

0 comments on commit 4f71c87

Please sign in to comment.