Skip to content

fix: rename getAssiciatedResource to getSecondaryResource #1100

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 2 commits into from
Mar 29, 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 @@ -32,7 +32,7 @@ public Optional<RetryInfo> getRetryInfo() {
public <T> Optional<T> getSecondaryResource(Class<T> expectedType, String eventSourceName) {
return controller.getEventSourceManager()
.getResourceEventSourceFor(expectedType, eventSourceName)
.flatMap(es -> es.getAssociatedResource(primaryResource));
.flatMap(es -> es.getSecondaryResource(primaryResource));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ public interface ResourceOwner<R, P extends HasMetadata> {
* @return an {@link Optional} containing the secondary resource or {@link Optional#empty()} if it
* doesn't exist
*/
Optional<R> getAssociatedResource(P primary);
Optional<R> getSecondaryResource(P primary);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public AbstractDependentResource() {

@Override
public ReconcileResult<R> reconcile(P primary, Context<P> context) {
var maybeActual = getAssociatedResource(primary);
var maybeActual = getSecondaryResource(primary);
if (creatable || updatable) {
if (maybeActual.isEmpty()) {
if (creatable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected AbstractCachingDependentResource(Class<R> resourceType) {
}

public Optional<R> fetchResource(P primaryResource) {
return eventSource().getAssociatedResource(primaryResource);
return eventSource().getSecondaryResource(primaryResource);
}

@Override
Expand All @@ -25,7 +25,7 @@ public Class<R> resourceType() {
}

@Override
public Optional<R> getAssociatedResource(P primaryResource) {
return eventSource().getAssociatedResource(primaryResource);
public Optional<R> getSecondaryResource(P primaryResource) {
return eventSource().getSecondaryResource(primaryResource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public AbstractSimpleDependentResource(UpdatableCache<R> cache) {
}

@Override
public Optional<R> getAssociatedResource(HasMetadata primaryResource) {
public Optional<R> getSecondaryResource(HasMetadata primaryResource) {
return cache.get(ResourceID.fromResource(primaryResource));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public Result<R> match(R actualResource, P primary, Context<P> context) {

public void delete(P primary, Context<P> context) {
if (!addOwnerReference()) {
var resource = getAssociatedResource(primary);
var resource = getSecondaryResource(primary);
resource.ifPresent(r -> client.resource(r).delete());
}
}
Expand Down Expand Up @@ -134,8 +134,8 @@ public Class<R> resourceType() {
}

@Override
public Optional<R> getAssociatedResource(P primaryResource) {
return eventSource().getAssociatedResource(primaryResource);
public Optional<R> getSecondaryResource(P primaryResource) {
return eventSource().getSecondaryResource(primaryResource);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Optional<R> getCachedValue(ResourceID resourceID) {
}

@Override
public Optional<R> getAssociatedResource(P primary) {
public Optional<R> getSecondaryResource(P primary) {
return cache.get(ResourceID.fromResource(primary));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private void handleKubernetesClientException(Exception e) {
}

@Override
public Optional<T> getAssociatedResource(T primary) {
public Optional<T> getSecondaryResource(T primary) {
return get(ResourceID.fromResource(primary));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private void propagateEvent(R object) {
* @return the informed resource associated with the specified primary resource
*/
@Override
public Optional<R> getAssociatedResource(P resource) {
public Optional<R> getSecondaryResource(P resource) {
final var id = configuration.getAssociatedResourceIdentifier().associatedSecondaryID(resource);
return get(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Optional<R> get(ResourceID resourceID) {
}

@Override
public Optional<R> getAssociatedResource(P primary) {
public Optional<R> getSecondaryResource(P primary) {
return get(ResourceID.fromResource(primary));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void run() {
* @return the related resource for this event source
*/
@Override
public Optional<R> getAssociatedResource(P primary) {
public Optional<R> getSecondaryResource(P primary) {
return getValueFromCacheOrSupplier(ResourceID.fromResource(primary));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void stop() throws OperatorException {
* @return related resource
*/
@Override
public Optional<R> getAssociatedResource(P primary) {
public Optional<R> getSecondaryResource(P primary) {
return getCachedValue(ResourceID.fromResource(primary));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public ReconcileResult<Deployment> reconcile(TestCustomResource primary,
}

@Override
public Optional<Deployment> getAssociatedResource(TestCustomResource primaryResource) {
public Optional<Deployment> getSecondaryResource(TestCustomResource primaryResource) {
return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ void getsTheResourceFromSupplyIfReconciling() {
simpleDependentResource.reconcile(TestUtils.testCustomResource1(), null);

verify(supplierMock, times(1)).get();
assertThat(simpleDependentResource.getAssociatedResource(TestUtils.testCustomResource1()))
assertThat(simpleDependentResource.getSecondaryResource(TestUtils.testCustomResource1()))
.isPresent()
.isEqualTo(Optional.of(SampleExternalResource.testResource1()));
}

@Test
void getResourceReadsTheResourceFromCache() {
simpleDependentResource.getAssociatedResource(TestUtils.testCustomResource1());
simpleDependentResource.getSecondaryResource(TestUtils.testCustomResource1());

verify(supplierMock, times(0)).get();
verify(updatableCacheMock, times(1)).get(any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public UpdateControl<StandaloneDependentTestCustomResource> reconcile(
StandaloneDependentTestCustomResource primary,
Context<StandaloneDependentTestCustomResource> context) {
deploymentDependent.reconcile(primary, context);
Optional<Deployment> deployment = deploymentDependent.getAssociatedResource(primary);
Optional<Deployment> deployment = deploymentDependent.getSecondaryResource(primary);
if (deployment.isEmpty()) {
throw new IllegalStateException("Resource should not be empty after reconcile.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public UpdateControl<WebPage> reconcile(WebPage webPage, Context<WebPage> contex

webPage.setStatus(
createStatus(
configMapDR.getAssociatedResource(webPage).orElseThrow().getMetadata().getName()));
configMapDR.getSecondaryResource(webPage).orElseThrow().getMetadata().getName()));
return UpdateControl.updateStatus(webPage);
}

Expand Down