Skip to content

Leader Election #1358

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 31 commits into from
Aug 24, 2022
Merged

Leader Election #1358

merged 31 commits into from
Aug 24, 2022

Conversation

csviri
Copy link
Collaborator

@csviri csviri commented Jul 21, 2022

No description provided.

@csviri csviri self-assigned this Jul 21, 2022
@csviri csviri linked an issue Jul 21, 2022 that may be closed by this pull request
@csviri csviri force-pushed the leader-election branch from 0dea3db to c77db84 Compare July 25, 2022 13:05
@csviri csviri force-pushed the next branch 2 times, most recently from f6aa23f to e3cd675 Compare July 26, 2022 07:33
@csviri csviri marked this pull request as ready for review August 3, 2022 14:11
@csviri csviri requested a review from metacosm August 3, 2022 14:11
@csviri
Copy link
Collaborator Author

csviri commented Aug 5, 2022

Note that the e2e test has to be this was because of the System.exit also since configuration service is a singleton (although that could be hacked), but anyways it is good to have a e2e test for this.

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.

Made some changes, also have some comments but looks good otherwise.


public LeaderElectionConfigurationBuilder() {}

public static LeaderElectionConfigurationBuilder aLeaderElectionConfiguration() {
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 really see the point of this builder as it is just creating the object using the publicly available constructors…

Copy link
Collaborator Author

@csviri csviri Aug 24, 2022

Choose a reason for hiding this comment

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

deleted. Added an additional constructor.

@@ -30,26 +30,26 @@
/**
* Handles calls and results of a Reconciler and finalizer related logic
*/
class ReconciliationDispatcher<R extends HasMetadata> {
class ReconciliationDispatcher<P 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.

It would be better to do these kind of changes in different PRs as this makes things more difficult to review

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, will try to do in the future.

this.identity = identity(config);
Lock lock = new LeaseLock(config.getLeaseNamespace(), config.getLeaseName(), identity);
// releaseOnCancel is not used in the underlying implementation
leaderElector = new LeaderElectorBuilder(client,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This API is quite awkward, imo… maybe we should improve it in the Fabric8 client project?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, yes, this could be better there.

ExecutorServiceManager.init();
controllers.start();
// first start the controller manager before leader election,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a bit smelly, imo. Would it make sense to put the election-related behavior in the ControllerManager to simplify the state management?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It has nothing to do with the controllers, it's more like a logic regarding the whole operator. Not saying that it is ideally describing the domain, but I don't think it should be in the controller. Controllers actually should not know if there is such thing as leader election in the background.

.inNamespace(namespace).withName(TEST_RESOURCE_NAME).get().getStatus();

assertThat(actualStatus).isNotNull();
assertThat(actualStatus.getReconciledBy()).hasSizeGreaterThan(actualListSize + 2);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why +2? Why not use a set on the status so that we can check that both instances have reconciled the 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.

Added a named constant

@@ -70,7 +72,18 @@ public Duration getRetryPeriod() {
return retryPeriod;
}

public Optional<String> getIdentity() {
return Optional.ofNullable(identity);
public String getIdentity() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TBH I don't think this is good, would like to keep the POJOs clear without any logic

@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 4 Code Smells

34.1% 34.1% Coverage
0.0% 0.0% Duplication

@metacosm metacosm merged commit e5c4928 into next Aug 24, 2022
@metacosm metacosm deleted the leader-election branch August 24, 2022 19:26
csviri added a commit that referenced this pull request Aug 25, 2022
@honnix
Copy link
Contributor

honnix commented Aug 26, 2022

Very much looking forward to this! Thanks for implementing it.

csviri added a commit that referenced this pull request Aug 30, 2022
csviri added a commit that referenced this pull request Sep 5, 2022
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.

Leader election
3 participants