Skip to content

Commit e0ac3cd

Browse files
authored
fix: naming and minor structural improvements (#1130)
1 parent fa484e5 commit e0ac3cd

File tree

13 files changed

+42
-37
lines changed

13 files changed

+42
-37
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,36 @@ public interface InformerConfiguration<R extends HasMetadata, P extends HasMetad
2020
class DefaultInformerConfiguration<R extends HasMetadata, P extends HasMetadata> extends
2121
DefaultResourceConfiguration<R> implements InformerConfiguration<R, P> {
2222

23-
private final SecondaryToPrimaryMapper<R> secondaryToPrimaryResourcesIdSet;
24-
private final PrimaryToSecondaryMapper<P> associatedWith;
23+
private final SecondaryToPrimaryMapper<R> secondaryToPrimaryMapper;
24+
private final PrimaryToSecondaryMapper<P> primaryToSecondaryMapper;
2525

2626
protected DefaultInformerConfiguration(String labelSelector,
2727
Class<R> resourceClass,
28-
SecondaryToPrimaryMapper<R> secondaryToPrimaryResourcesIdSet,
29-
PrimaryToSecondaryMapper<P> associatedWith,
28+
SecondaryToPrimaryMapper<R> secondaryToPrimaryMapper,
29+
PrimaryToSecondaryMapper<P> primaryToSecondaryMapper,
3030
Set<String> namespaces) {
3131
super(labelSelector, resourceClass, namespaces);
32-
this.secondaryToPrimaryResourcesIdSet =
33-
Objects.requireNonNullElse(secondaryToPrimaryResourcesIdSet,
32+
this.secondaryToPrimaryMapper =
33+
Objects.requireNonNullElse(secondaryToPrimaryMapper,
3434
Mappers.fromOwnerReference());
35-
this.associatedWith =
36-
Objects.requireNonNullElseGet(associatedWith, () -> ResourceID::fromResource);
35+
this.primaryToSecondaryMapper =
36+
Objects.requireNonNullElseGet(primaryToSecondaryMapper, () -> ResourceID::fromResource);
3737
}
3838

3939

40-
public SecondaryToPrimaryMapper<R> getPrimaryResourcesRetriever() {
41-
return secondaryToPrimaryResourcesIdSet;
40+
public SecondaryToPrimaryMapper<R> getSecondaryToPrimaryMapper() {
41+
return secondaryToPrimaryMapper;
4242
}
4343

44-
public PrimaryToSecondaryMapper<P> getAssociatedResourceIdentifier() {
45-
return associatedWith;
44+
public PrimaryToSecondaryMapper<P> getPrimaryToSecondaryMapper() {
45+
return primaryToSecondaryMapper;
4646
}
4747

4848
}
4949

50-
SecondaryToPrimaryMapper<R> getPrimaryResourcesRetriever();
50+
SecondaryToPrimaryMapper<R> getSecondaryToPrimaryMapper();
5151

52-
PrimaryToSecondaryMapper<P> getAssociatedResourceIdentifier();
52+
PrimaryToSecondaryMapper<P> getPrimaryToSecondaryMapper();
5353

5454
@SuppressWarnings("unused")
5555
class InformerConfigurationBuilder<R extends HasMetadata, P extends HasMetadata> {
@@ -116,7 +116,7 @@ static <R extends HasMetadata, P extends HasMetadata> InformerConfigurationBuild
116116
.withNamespaces(configuration.getNamespaces())
117117
.withLabelSelector(configuration.getLabelSelector())
118118
.withAssociatedSecondaryResourceIdentifier(
119-
configuration.getAssociatedResourceIdentifier())
120-
.withPrimaryResourcesRetriever(configuration.getPrimaryResourcesRetriever());
119+
configuration.getPrimaryToSecondaryMapper())
120+
.withPrimaryResourcesRetriever(configuration.getSecondaryToPrimaryMapper());
121121
}
122122
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ public Stream<R> list(Predicate<R> predicate) {
4343
return cache.list(predicate);
4444
}
4545

46-
47-
4846
protected UpdatableCache<R> initCache() {
4947
return new ConcurrentHashMapCache<>();
5048
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
@FunctionalInterface
77
public interface PrimaryToSecondaryMapper<P extends HasMetadata> {
8-
ResourceID associatedSecondaryID(P primary);
8+
ResourceID toSecondaryResourceID(P primary);
99
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
@FunctionalInterface
88
public interface SecondaryToPrimaryMapper<T> {
9-
Set<ResourceID> associatedPrimaryResources(T dependentResource);
9+
Set<ResourceID> toPrimaryResourceIDs(T dependentResource);
1010
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,6 @@ private void handleKubernetesClientException(Exception e) {
103103

104104
@Override
105105
public Optional<T> getSecondaryResource(T primary) {
106-
return get(ResourceID.fromResource(primary));
106+
throw new IllegalStateException("This method should not be called here. Primary: " + primary);
107107
}
108108
}

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,17 @@ public InformerEventSource(InformerConfiguration<R, P> configuration, Kubernetes
8585

8686
@Override
8787
public void onAdd(R resource) {
88+
if (log.isDebugEnabled()) {
89+
log.debug("On add event received for resource id: {}", ResourceID.fromResource(resource));
90+
}
8891
onAddOrUpdate("add", resource, () -> InformerEventSource.super.onAdd(resource));
8992
}
9093

9194
@Override
9295
public void onUpdate(R oldObject, R newObject) {
96+
if (log.isDebugEnabled()) {
97+
log.debug("On update event received for resource id: {}", ResourceID.fromResource(newObject));
98+
}
9399
onAddOrUpdate("update", newObject,
94100
() -> InformerEventSource.super.onUpdate(oldObject, newObject));
95101
}
@@ -118,14 +124,17 @@ private synchronized void onAddOrUpdate(String operation, R newObject, Runnable
118124
}
119125

120126
@Override
121-
public void onDelete(R r, boolean b) {
122-
super.onDelete(r, b);
123-
propagateEvent(r);
127+
public void onDelete(R resource, boolean b) {
128+
if (log.isDebugEnabled()) {
129+
log.debug("On delete event received for resource id: {}", ResourceID.fromResource(resource));
130+
}
131+
super.onDelete(resource, b);
132+
propagateEvent(resource);
124133
}
125134

126135
private void propagateEvent(R object) {
127136
var primaryResourceIdSet =
128-
configuration.getPrimaryResourcesRetriever().associatedPrimaryResources(object);
137+
configuration.getSecondaryToPrimaryMapper().toPrimaryResourceIDs(object);
129138
if (primaryResourceIdSet.isEmpty()) {
130139
return;
131140
}
@@ -153,7 +162,7 @@ private void propagateEvent(R object) {
153162
*/
154163
@Override
155164
public Optional<R> getSecondaryResource(P resource) {
156-
final var id = configuration.getAssociatedResourceIdentifier().associatedSecondaryID(resource);
165+
final var id = configuration.getPrimaryToSecondaryMapper().toSecondaryResourceID(resource);
157166
return get(id);
158167
}
159168

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ public Optional<R> get(ResourceID resourceID) {
9595
}
9696

9797
@Override
98-
public Optional<R> getSecondaryResource(P primary) {
99-
return get(ResourceID.fromResource(primary));
100-
}
98+
public abstract Optional<R> getSecondaryResource(P primary);
10199

102100
@Override
103101
public Optional<R> getCachedValue(ResourceID resourceID) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public synchronized void putAddedResource(T newResource) {
5353
ResourceID resourceID = ResourceID.fromResource(newResource);
5454
if (managedInformerEventSource.get(resourceID).isEmpty()) {
5555
log.debug("Putting resource to cache with ID: {}", resourceID);
56-
cache.put(ResourceID.fromResource(newResource), newResource);
56+
cache.put(resourceID, newResource);
5757
} else {
5858
log.debug("Won't put resource into cache found already informer cache: {}", resourceID);
5959
}

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSourceTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ void setup() {
4949
.thenReturn(labeledResourceClientMock);
5050
when(labeledResourceClientMock.runnableInformer(0)).thenReturn(informer);
5151

52-
when(informerConfiguration.getPrimaryResourcesRetriever())
52+
when(informerConfiguration.getSecondaryToPrimaryMapper())
5353
.thenReturn(mock(SecondaryToPrimaryMapper.class));
5454

5555
informerEventSource = new InformerEventSource<>(informerConfiguration, clientMock);
5656
informerEventSource.setTemporalResourceCache(temporaryResourceCacheMock);
5757
informerEventSource.setEventHandler(eventHandlerMock);
5858

5959
SecondaryToPrimaryMapper secondaryToPrimaryMapper = mock(SecondaryToPrimaryMapper.class);
60-
when(informerConfiguration.getPrimaryResourcesRetriever())
60+
when(informerConfiguration.getSecondaryToPrimaryMapper())
6161
.thenReturn(secondaryToPrimaryMapper);
62-
when(secondaryToPrimaryMapper.associatedPrimaryResources(any()))
62+
when(secondaryToPrimaryMapper.toPrimaryResourceIDs(any()))
6363
.thenReturn(Set.of(ResourceID.fromResource(testDeployment())));
6464
}
6565

operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected ConfigMap desired(OrderedManagedDependentCustomResource primary,
4646
}
4747

4848
@Override
49-
public ResourceID associatedSecondaryID(OrderedManagedDependentCustomResource primary) {
49+
public ResourceID toSecondaryResourceID(OrderedManagedDependentCustomResource primary) {
5050
return new ResourceID(primary.getMetadata().getName() + "1",
5151
primary.getMetadata().getNamespace());
5252
}

operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected ConfigMap desired(OrderedManagedDependentCustomResource primary,
4646
}
4747

4848
@Override
49-
public ResourceID associatedSecondaryID(OrderedManagedDependentCustomResource primary) {
49+
public ResourceID toSecondaryResourceID(OrderedManagedDependentCustomResource primary) {
5050
return new ResourceID(primary.getMetadata().getName() + "2",
5151
primary.getMetadata().getNamespace());
5252
}

sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/dependent/SecretDependentResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public Result<Secret> match(Secret actual, MySQLSchema primary, Context<MySQLSch
5959
}
6060

6161
@Override
62-
public ResourceID associatedSecondaryID(MySQLSchema primary) {
62+
public ResourceID toSecondaryResourceID(MySQLSchema primary) {
6363
return new ResourceID(
6464
getSecretName(primary.getMetadata().getName()), primary.getMetadata().getNamespace());
6565
}

sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/ConfigMapDependentResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public ConfigMap update(ConfigMap actual, ConfigMap target, WebPage primary,
5959
}
6060

6161
@Override
62-
public ResourceID associatedSecondaryID(WebPage primary) {
62+
public ResourceID toSecondaryResourceID(WebPage primary) {
6363
return new ResourceID(configMapName(primary), primary.getMetadata().getNamespace());
6464
}
6565
}

0 commit comments

Comments
 (0)