Skip to content

feat: remove primary to secondary mapper (handled automatically) #1161

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 19 commits into from
Apr 20, 2022

Conversation

csviri
Copy link
Collaborator

@csviri csviri commented Apr 15, 2022

No description provided.

@csviri csviri marked this pull request as ready for review April 17, 2022 18:18
@csviri csviri marked this pull request as draft April 17, 2022 18:18
@csviri csviri marked this pull request as ready for review April 17, 2022 20:13
@csviri csviri requested a review from metacosm April 17, 2022 20:14
@csviri
Copy link
Collaborator Author

csviri commented Apr 17, 2022

@metacosm I would actually put this into 3.0 since (if does not make trouble with quarkus extension), although its quite last minute, but simplifies usage a lot. PrimaryToSecondaryMapper was not easy to understand for someone who started with dependent resources and it basically was needed in all cases when the names of the primary and secondary did not match.

@@ -28,9 +32,28 @@ public Optional<RetryInfo> getRetryInfo() {
return Optional.ofNullable(retryInfo);
}

@Override
@SuppressWarnings("unchecked")
public <T> List<T> getSecondaryResources(Class<T> expectedType) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a Set instead of List, actually? Don't we want to return unique resources? Also, there's no ordering there so a List is not required.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with that will change.

import io.javaoperatorsdk.operator.processing.event.ResourceID;
import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper;

public class PrimaryToSecondaryIndex<R extends HasMetadata> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class should probably be package-private, no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is also used by the user in case to define custom mapping. (We have default by owner reference, but that does not work for example outside of namespace. See also support in KubernetesDependentResource.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what you mean. This class is only used by InformerEventSource internally and since it's the class implementing the automated indexing of secondary resources, it shouldn't be exposed anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I though this is the mapper. Yes this can be package private, will change it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

if (log.isDebugEnabled()) {
log.debug("On delete event received for resource id: {}", ResourceID.fromResource(resource));
}
primaryToSecondaryIndex.onAddOrUpdate(resource);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that be onDelete instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhh, yes, fixed thx.

}
super.onDelete(resource, b);
propagateEvent(resource);
private boolean temporalCacheHasResourceWithVersionAs(R resource) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private boolean temporalCacheHasResourceWithVersionAs(R resource) {
private boolean temporaryCacheHasResourceWithSameVersionAs(R resource) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed this separatelly in a commit, because here might break the build.

@csviri csviri requested a review from metacosm April 19, 2022 14:44
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

42.6% 42.6% Coverage
0.0% 0.0% Duplication

Copy link
Collaborator

@metacosm metacosm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@csviri csviri merged commit e971c4d into main Apr 20, 2022
@csviri csviri deleted the index-secondary-to-primary branch April 20, 2022 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants