Skip to content

Commit

Permalink
fix fabric8io#3982: removed MultiDeleteable, changed multi-delete ret…
Browse files Browse the repository at this point in the history
…urn to true
  • Loading branch information
shawkins committed Mar 28, 2022
1 parent bb9a613 commit 6fbc52a
Show file tree
Hide file tree
Showing 19 changed files with 161 additions and 237 deletions.
11 changes: 11 additions & 0 deletions doc/MIGRATION-v6.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [Object sorting](#object-sorting)
- [DSL Interface Changes](#dsl-interface-changes)
- [evict Changes](#evict-changes)
- [Delete Behavior](#delete-behavior)

## Namespace Changes

Expand Down Expand Up @@ -98,6 +99,7 @@ The group on the object being deserialized is not required to match the prospect
- Removed DefaultKubernetesClient and DefaultOpenShiftClient constructors directly referencing OkHttp - use OkHttpClientImpl to wrap the OkHttpClient, or the OkHttpClientFactory instead.
- Removed the AutoAdaptableKubernetesClient, use the new KubernetesClientBuilder instead
- Removed OpenShiftConfig OpenshiftApiGroupsEnabled methods
- Removed Recreateable, RecreateApplicable, and ApplicableAnd from the hierarchy of ParameterNamespaceListVisitFromServerGetDeleteRecreateWaitApplicable
### Extension Development
Expand All @@ -123,6 +125,10 @@ resource.delete();
resource.waitUntilCondition(Objects::isNull, 30, TimeUnit.SECONDS);
resource.create();
Similarly ParameterNamespaceListVisitFromServerGetDeleteRecreateWaitApplicable had the Recreateable interface removed, which requires the same logic as above to implement the deletingExisting behavior
If you are simply trying to emulate the kubectl apply feature, consider instead using an edit or the new server side apply feature.
## lists Removal
KuberentesClient.lists was removed. This entry point is effectively the same as KubernetesClient.resourceList or load. Please use one of those methods instead.
Expand Down Expand Up @@ -188,6 +194,8 @@ Client.adapt will no longer perform the isAdaptable check - that is you may free
- Informable.withIndexers has been deprecated. Indexers can be added/removed after the creation of the informer.
- The methods provided by MultiDeleteable have moved to FilterWatchListMultiDeletable and have been deprecated. You may use KubernetesClient.resourceList, or the individual resource methods to delete the items.
## Object Sorting
KubernetesList and Template will no longer automatically sort their objects by default. You may use the HasMetadataComparator to sort the items as needed.
Expand All @@ -204,3 +212,6 @@ KubernetesList and Template will no longer automatically sort their objects by d
Evictable.evict will throw an exception rather than returning false if the pod is not found. This ensures that false strictly means that the evict failed.
## Delete Behavior
Deleting a collection / list will always return true and 404s on individual items will simply be ignored.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
import io.fabric8.kubernetes.client.GracePeriodConfigurable;
import io.fabric8.kubernetes.client.PropagationPolicyConfigurable;

import java.util.List;

/**
* Created by iocanel on 9/15/16.
*/
public interface CascadingDeletable<T> extends Deletable,
Cascading<Deletable>,
GracePeriodConfigurable<CascadingDeletable<T>>,
PropagationPolicyConfigurable<CascadingDeletable<T>>,
Recreateable<Applicable<T>> {
Cascading<Deletable>,
GracePeriodConfigurable<CascadingDeletable<T>>,
PropagationPolicyConfigurable<CascadingDeletable<T>>,
Applicable<List<T>> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
public interface Deletable {

/**
* Deletes resource and all managed resources, returns null or false if not found.
* @return value indicating object was deleted or not
* If this is at a single item context, deletes resource and all managed resources, returns false if not found.
* <br>
* If this is at a list/collection context, it will always return true
*
* @return value false only if in a single item context the item is not deleted
* @throws io.fabric8.kubernetes.client.KubernetesClientException if an error occurs.
*/
boolean delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,36 @@
*/
package io.fabric8.kubernetes.client.dsl;

public interface FilterWatchListMultiDeletable<T, L, R> extends FilterWatchListDeletable<T, L, R>, MultiDeleteable<T> {
import io.fabric8.kubernetes.client.KubernetesClient;

import java.util.Arrays;
import java.util.List;

public interface FilterWatchListMultiDeletable<T, L, R> extends FilterWatchListDeletable<T, L, R>, Deletable {

/**
* Delete the given items.
*
* @param items
* @return true
*
* @deprecated use {@link KubernetesClient#resourceList(java.util.Collection)} delete instead
*
*/
@Deprecated
default boolean delete(T... items) {
return delete(Arrays.asList(items));
}

/**
* Delete the given items.
*
* @param items
* @return true
*
* @deprecated use {@link KubernetesClient#resourceList(java.util.Collection)} delete instead
*/
@Deprecated
boolean delete(List<T> items);

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

import java.util.List;

public interface ListVisitFromServerWritable<T> extends RecreateApplicable<List<T>, T>,
CascadingDeletable<List<T>>,
GracePeriodConfigurable<CascadingDeletable<List<T>>>,
PropagationPolicyConfigurable<CascadingDeletable<List<T>>> {
public interface ListVisitFromServerWritable<T> extends
CascadingDeletable<T>,
GracePeriodConfigurable<CascadingDeletable<T>>,
PropagationPolicyConfigurable<CascadingDeletable<T>> {

List<T> create();
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -449,17 +449,8 @@ public boolean delete() {
}
return false;
}
} else {
try {
deleteList();
return true;
} catch (KubernetesClientException e) {
if (e.getCode() != HttpURLConnection.HTTP_NOT_FOUND) {
throw e;
}
return false;
}
}
return delete(list().getItems());
}

@SafeVarargs
Expand All @@ -470,25 +461,21 @@ public final boolean delete(T... items) {

@Override
public boolean delete(List<T> items) {
boolean deleted = true;
if (items != null) {
for (T toDelete : items) {
if (toDelete == null) {
continue;
}
updateApiVersion(toDelete);

try {
deleted &= resource(toDelete).delete();
resource(toDelete).delete();
} catch (KubernetesClientException e) {
if (e.getCode() != HttpURLConnection.HTTP_NOT_FOUND) {
throw e;
}
return false;
}
}
}
return deleted;
return true;
}

@Override
Expand Down Expand Up @@ -537,10 +524,6 @@ void deleteThis() {
}
}

void deleteList() {
delete(list().getItems());
}

@Override
public BaseOperation<T, L, R> withResourceVersion(String resourceVersion) {
return newInstance(context.withResourceVersion(resourceVersion));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io.fabric8.kubernetes.client.KubernetesClientTimeoutException;
import io.fabric8.kubernetes.client.NamespaceableResourceAdapter;
import io.fabric8.kubernetes.client.ResourceHandler;
import io.fabric8.kubernetes.client.dsl.Applicable;
import io.fabric8.kubernetes.client.dsl.CascadingDeletable;
import io.fabric8.kubernetes.client.dsl.Deletable;
import io.fabric8.kubernetes.client.dsl.Gettable;
Expand Down Expand Up @@ -219,29 +218,15 @@ public List<HasMetadata> apply() {
public List<HasMetadata> createOrReplace() {
List<? extends Resource<HasMetadata>> operations = getResources();

if (!namespaceVisitOperationContext.isDeletingExisting()) {
return operations.stream()
.map(Resource::createOrReplace)
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
operations.stream().forEach(Resource::delete);
waitUntilCondition(Objects::isNull, 30, TimeUnit.SECONDS);
return create();
}

@Override
public Waitable<List<HasMetadata>, HasMetadata> createOrReplaceAnd() {
return newInstance(context.withItem(createOrReplace()), namespaceVisitOperationContext);
return operations.stream()
.map(Resource::createOrReplace)
.filter(Objects::nonNull)
.collect(Collectors.toList());
}

@Override
public boolean delete() {
for (Resource<HasMetadata> impl : getResources()) {
if (!impl.delete()) {
return false;
}
}
resources().forEach(Resource::delete);
return true;
}

Expand All @@ -261,11 +246,6 @@ public Gettable<List<HasMetadata>> fromServer() {
return newInstance(context.withReloadingFromServer(true), namespaceVisitOperationContext);
}

@Override
public Applicable<List<HasMetadata>> deletingExisting() {
return newInstance(context, namespaceVisitOperationContext.withDeletingExisting(true));
}

@Override
public ListVisitFromServerGetDeleteRecreateWaitApplicable<HasMetadata> accept(Visitor... visitors) {
return newInstance(context.withItem(getItems().stream()
Expand All @@ -274,12 +254,12 @@ public ListVisitFromServerGetDeleteRecreateWaitApplicable<HasMetadata> accept(Vi
}

@Override
public CascadingDeletable<List<HasMetadata>> withGracePeriod(long gracePeriodSeconds) {
public CascadingDeletable<HasMetadata> withGracePeriod(long gracePeriodSeconds) {
return newInstance(context.withGracePeriodSeconds(gracePeriodSeconds), namespaceVisitOperationContext);
}

@Override
public CascadingDeletable<List<HasMetadata>> withPropagationPolicy(DeletionPropagation propagationPolicy) {
public CascadingDeletable<HasMetadata> withPropagationPolicy(DeletionPropagation propagationPolicy) {
return newInstance(context.withPropagationPolicy(propagationPolicy), namespaceVisitOperationContext);
}

Expand Down
Loading

0 comments on commit 6fbc52a

Please sign in to comment.