Skip to content

Commit fcace92

Browse files
committed
refactor: rename methods so that it's clearer they're not about caching
1 parent 7e8e06d commit fcace92

File tree

5 files changed

+32
-15
lines changed

5 files changed

+32
-15
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ public interface ResourceOwner<R, P extends HasMetadata> {
1414
Class<R> resourceType();
1515

1616
/**
17-
* Retrieves the resource associated with the specified primary one
17+
* Retrieves the resource associated with the specified primary one, returning the actual state of
18+
* the resource. Typically, this state might come from a local cache, updated after
19+
* reconciliation.
1820
*
1921
* @param primary the primary resource for which we want to retrieve the secondary resource
2022
* @return an {@link Optional} containing the secondary resource or {@link Optional#empty()} if it

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,34 @@ private void logForOperation(String operation, P primary, R desired) {
7171
protected R handleCreate(R desired, P primary, Context<P> context) {
7272
ResourceID resourceID = ResourceID.fromResource(primary);
7373
R created = creator.create(desired, primary, context);
74-
cacheAfterCreate(resourceID, created);
74+
processPostCreate(resourceID, created);
7575
return created;
7676
}
7777

78-
protected abstract void cacheAfterCreate(ResourceID resourceID, R created);
78+
/**
79+
* Allows sub-classes to perform additional processing (e.g. caching) on the created resource if
80+
* needed.
81+
*
82+
* @param primaryResourceId the {@link ResourceID} of the primary resource associated with the
83+
* newly created resource
84+
* @param created the newly created resource
85+
*/
86+
protected abstract void processPostCreate(ResourceID primaryResourceId, R created);
7987

80-
protected abstract void cacheAfterUpdate(R actual, ResourceID resourceID, R updated);
88+
/**
89+
* Allows sub-classes to perform additional processing on the updated resource if needed.
90+
*
91+
* @param primaryResourceId the {@link ResourceID} of the primary resource associated with the
92+
* newly updated resource
93+
* @param updated the updated resource
94+
* @param actual the resource as it was before the update
95+
*/
96+
protected abstract void processPostUpdate(ResourceID primaryResourceId, R updated, R actual);
8197

8298
protected R handleUpdate(R actual, R desired, P primary, Context<P> context) {
8399
ResourceID resourceID = ResourceID.fromResource(primary);
84100
R updated = updater.update(actual, desired, primary, context);
85-
cacheAfterUpdate(actual, resourceID, updated);
101+
processPostUpdate(resourceID, updated, actual);
86102
return updated;
87103
}
88104

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ protected R handleUpdate(R actual, R desired, P primary, Context<P> context) {
8686
}
8787

8888

89-
protected void cacheAfterCreate(ResourceID resourceID, R created) {
89+
protected void processPostCreate(ResourceID primaryResourceId, R created) {
9090
if (isCacheFillerEventSource) {
91-
recentOperationCacheFiller().handleRecentResourceCreate(resourceID, created);
91+
recentOperationCacheFiller().handleRecentResourceCreate(primaryResourceId, created);
9292
}
9393
}
9494

95-
protected void cacheAfterUpdate(R actual, ResourceID resourceID, R updated) {
95+
protected void processPostUpdate(ResourceID primaryResourceId, R updated, R actual) {
9696
if (isCacheFillerEventSource) {
97-
recentOperationCacheFiller().handleRecentResourceUpdate(resourceID, updated, actual);
97+
recentOperationCacheFiller().handleRecentResourceUpdate(primaryResourceId, updated, actual);
9898
}
9999
}
100100

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ public final void delete(P primary, Context<P> context) {
5959
protected abstract void deleteResource(P primary, Context<P> context);
6060

6161
@Override
62-
protected void cacheAfterCreate(ResourceID resourceID, R created) {
63-
cache.put(resourceID, created);
62+
protected void processPostCreate(ResourceID primaryResourceId, R created) {
63+
cache.put(primaryResourceId, created);
6464
}
6565

6666
@Override
67-
protected void cacheAfterUpdate(R actual, ResourceID resourceID, R updated) {
68-
cache.put(resourceID, updated);
67+
protected void processPostUpdate(ResourceID primaryResourceId, R updated, R actual) {
68+
cache.put(primaryResourceId, updated);
6969
}
7070

7171
public Matcher.Result<R> match(R actualResource, P primary, Context<P> context) {

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ public InformerConfiguration<R, P> getConfiguration() {
165165
public synchronized void handleRecentResourceUpdate(ResourceID resourceID, R resource,
166166
R previousResourceVersion) {
167167
handleRecentCreateOrUpdate(resource,
168-
() -> super.handleRecentResourceUpdate(resourceID, resource,
169-
previousResourceVersion));
168+
() -> super.handleRecentResourceUpdate(resourceID, resource, previousResourceVersion));
170169
}
171170

172171
@Override

0 commit comments

Comments
 (0)