Skip to content

refactor: deleteBulkResource -> deleteTargetResource #1544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ public interface BulkDependentResource<R, P extends HasMetadata>
Map<String, R> getSecondaryResources(P primary, Context<P> context);

/**
* Used to delete resource if the desired count is lower than the actual count of a resource.
* Deletes the actual resource identified by the specified key if it's not in the set of desired
* secondary resources for the specified primary.
*
* @param primary resource
* @param resource actual resource from the cache for the index
* @param primary the primary resource for which we want to remove now undesired secondary
* resources still present on the cluster
* @param resource the actual resource existing on the cluster that needs to be removed
* @param key key of the resource
* @param context actual context
*/
void deleteBulkResource(P primary, R resource, String key, Context<P> context);
void deleteTargetResource(P primary, R resource, String key, Context<P> context);

/**
* Determines whether the specified secondary resource matches the desired state with target index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ReconcileResult<R> reconcile(P primary, Context<P> context) {
Map<String, R> actualResources = bulkDependentResource.getSecondaryResources(primary, context);

// remove existing resources that are not needed anymore according to the primary state
deleteBulkResourcesIfRequired(desiredResources.keySet(), actualResources, primary, context);
deleteExtraResources(desiredResources.keySet(), actualResources, primary, context);

final List<ReconcileResult<R>> results = new ArrayList<>(desiredResources.size());
final var updatable = bulkDependentResource instanceof Updater;
Expand All @@ -45,14 +45,14 @@ public ReconcileResult<R> reconcile(P primary, Context<P> context) {
@Override
public void delete(P primary, Context<P> context) {
var actualResources = bulkDependentResource.getSecondaryResources(primary, context);
deleteBulkResourcesIfRequired(Collections.emptySet(), actualResources, primary, context);
deleteExtraResources(Collections.emptySet(), actualResources, primary, context);
}

private void deleteBulkResourcesIfRequired(Set<String> expectedKeys,
private void deleteExtraResources(Set<String> expectedKeys,
Map<String, R> actualResources, P primary, Context<P> context) {
actualResources.forEach((key, value) -> {
if (!expectedKeys.contains(key)) {
bulkDependentResource.deleteBulkResource(primary, value, key, context);
bulkDependentResource.deleteTargetResource(primary, value, key, context);
}
});
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import io.javaoperatorsdk.operator.api.reconciler.Context;

/**
* Helper for the Bulk Dependent Resources to make it more explicit that bulk needs to only
* implement the index aware match method.
* Helper for the buld Dependent Resources to make it more explicit that such dependents only to
* implement {@link BulkDependentResource#match(Object,Object,HasMetadata,Context)}
*
* @param <R> secondary resource type
* @param <P> primary resource type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ protected void handleDelete(P primary, Context<P> context) {
}

@SuppressWarnings("unused")
public void deleteBulkResource(P primary, R resource, String key, Context<P> context) {
public void deleteTargetResource(P primary, R resource, String key, Context<P> context) {
client.resource(resource).delete();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public Map<String, ExternalResource> getSecondaryResources(
}

@Override
public void deleteBulkResource(BulkDependentTestCustomResource primary, ExternalResource resource,
public void deleteTargetResource(BulkDependentTestCustomResource primary,
ExternalResource resource,
String key,
Context<BulkDependentTestCustomResource> context) {
externalServiceMock.delete(resource.getId());
Expand Down