Skip to content

Commit 31502ce

Browse files
metacosmcsviri
authored andcommitted
refactor: deleteBulkResource -> deleteTargetResource (#1544)
* refactor: deleteBulkResource -> deleteTargetResource * refactor: remove now unneeded class * refactor: deleteBulkResourcesIfRequired -> deleteExtraResources * fix: javadoc
1 parent ba69350 commit 31502ce

File tree

6 files changed

+15
-22
lines changed

6 files changed

+15
-22
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResource.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ public interface BulkDependentResource<R, P extends HasMetadata>
4141
Map<String, R> getSecondaryResources(P primary, Context<P> context);
4242

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

5355
/**
5456
* Determines whether the specified secondary resource matches the desired state with target index

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResourceReconciler.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public ReconcileResult<R> reconcile(P primary, Context<P> context) {
2828
Map<String, R> actualResources = bulkDependentResource.getSecondaryResources(primary, context);
2929

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

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

51-
private void deleteBulkResourcesIfRequired(Set<String> expectedKeys,
51+
private void deleteExtraResources(Set<String> expectedKeys,
5252
Map<String, R> actualResources, P primary, Context<P> context) {
5353
actualResources.forEach((key, value) -> {
5454
if (!expectedKeys.contains(key)) {
55-
bulkDependentResource.deleteBulkResource(primary, value, key, context);
55+
bulkDependentResource.deleteTargetResource(primary, value, key, context);
5656
}
5757
});
5858
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkResourceDiscriminatorFactory.java

-10
This file was deleted.

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkUpdater.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import io.javaoperatorsdk.operator.api.reconciler.Context;
55

66
/**
7-
* Helper for the Bulk Dependent Resources to make it more explicit that bulk needs to only
8-
* implement the index aware match method.
7+
* Helper for the buld Dependent Resources to make it more explicit that such dependents only to
8+
* implement {@link BulkDependentResource#match(Object,Object,HasMetadata,Context)}
99
*
1010
* @param <R> secondary resource type
1111
* @param <P> primary resource type

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ protected void handleDelete(P primary, Context<P> context) {
150150
}
151151

152152
@SuppressWarnings("unused")
153-
public void deleteBulkResource(P primary, R resource, String key, Context<P> context) {
153+
public void deleteTargetResource(P primary, R resource, String key, Context<P> context) {
154154
client.resource(resource).delete();
155155
}
156156

operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/external/ExternalBulkDependentResource.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public Map<String, ExternalResource> getSecondaryResources(
8686
}
8787

8888
@Override
89-
public void deleteBulkResource(BulkDependentTestCustomResource primary, ExternalResource resource,
89+
public void deleteTargetResource(BulkDependentTestCustomResource primary,
90+
ExternalResource resource,
9091
String key,
9192
Context<BulkDependentTestCustomResource> context) {
9293
externalServiceMock.delete(resource.getId());

0 commit comments

Comments
 (0)