Skip to content

fix: ordered managed dependents #1120

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 9 commits into from
Apr 4, 2022
Merged

Conversation

csviri
Copy link
Collaborator

@csviri csviri commented Apr 1, 2022

No description provided.

@csviri csviri self-assigned this Apr 1, 2022
@csviri csviri requested a review from metacosm April 1, 2022 14:40
Copy link
Collaborator Author

@csviri csviri left a comment

Choose a reason for hiding this comment

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

Made some comments :)

@@ -22,7 +22,7 @@
private ResourceEventFilter<R> customResourcePredicate;
private final ControllerConfiguration<R> original;
private Duration reconciliationMaxInterval;
private final Map<String, DependentResourceSpec<?, ?>> dependentResourceSpecs;
private final LinkedHashMap<String, DependentResourceSpec<?, ?>> namedDependentResourceSpecs;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why use a map why not a list? as in ControllerConfiguration or DefaultControllerConfiguration: List<DependentResourceSpec<?, ?>>
DependentResourceSpec already contains the name. It's basically data duplication.

Would be also consistent with those 2 classes.

Copy link
Collaborator

@metacosm metacosm Apr 3, 2022

Choose a reason for hiding this comment

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

Makes it easier to check if the spec is already present, find it again, naturally ensures that there is no duplication, easier to replace as well. Basically, indexing the specs by their name.

final var dependent = createAndConfigureFrom(drs, kubernetesClient);
// check if dependent implements Deleter to record that fact
if (!hasDeleterHolder[0] && dependent instanceof Deleter) {
hasDeleterHolder[0] = true;
}
dependentsHolder.put(name, dependent);
dependentsHolder.put(drs.getName(), dependent);
});
dependents = Collections.unmodifiableMap(dependentsHolder);
Copy link
Collaborator Author

@csviri csviri Apr 3, 2022

Choose a reason for hiding this comment

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

If we don't want to use list but an ordered Map, thus LinkedHashMap, we should have it also on the defined variable on line 57, so it's explicit on the definition, maybe also comment this. (For some reason I cannot comment on that line)

Named for me personally is better readabel / more expressive. But no strong opinion, fine also with this if the root definition is also LinkedHashMap

Copy link
Collaborator

Choose a reason for hiding this comment

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

The problem if we do that is that we cannot use Collections.emptyMap or Collections.unmodifiableMap anymore… Then again, since the dependents are not exposed, it's probably OK and indeed conveys the intent more clearly.

@@ -25,13 +25,17 @@ void replaceNamedDependentResourceConfigShouldWork() {
var dependents = configuration.getDependentResources();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test needs to be breaked down to multiple separate test cases. It's very hard to read this way.

@csviri
Copy link
Collaborator Author

csviri commented Apr 3, 2022

Ahh and it's my PR, will update :)

@sonarqubecloud
Copy link

sonarqubecloud bot commented Apr 3, 2022

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 1 Code Smell

60.0% 60.0% Coverage
0.0% 0.0% Duplication

@csviri csviri merged commit 62daa4a into main Apr 4, 2022
@csviri csviri deleted the ordered-managed-dependent-resources branch April 4, 2022 06: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
Development

Successfully merging this pull request may close these issues.

2 participants