Skip to content
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

feat: use client-go leader election #1128

Merged
merged 7 commits into from
Oct 16, 2024
Merged

feat: use client-go leader election #1128

merged 7 commits into from
Oct 16, 2024

Conversation

adityathebe
Copy link
Member

No description provided.

@adityathebe adityathebe force-pushed the feat/leader-election branch 2 times, most recently from 6ffe025 to 0942f93 Compare October 15, 2024 04:39
AcquireTime: &now,
RenewTime: &now,
OnStoppedLeading: func() {
updateLeaderLabel(ctx, false)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we can rely on this to add a label - if the pod is killed or partitions it will never run - The leader should first add its own label, and then remove the label from other others

Copy link
Member

Choose a reason for hiding this comment

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

I think we should also stop and start all schedules here

leader/election.go Outdated Show resolved Hide resolved
leader/election.go Outdated Show resolved Hide resolved
leader/election.go Outdated Show resolved Hide resolved
Comment on lines 71 to 73
app string,
namespace string,
service string,
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need both app and service ?

Copy link
Member Author

Choose a reason for hiding this comment

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

app would always be "config-db" which is hardcoded in flanksource/config-db whereas service was meant to be the actual kubernetes service name.

Although, the we could just use the app name as the lease name.

leader/election.go Outdated Show resolved Hide resolved
AcquireTime: &now,
RenewTime: &now,
OnStoppedLeading: func() {
for _, k := range echo.Crons.Items() {
Copy link
Member

Choose a reason for hiding this comment

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

don't we also need to start the crons again when we become leader ?

Copy link
Member Author

Choose a reason for hiding this comment

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

starting the jobs had a few pre-processing before the cron was started.
So the operator in config-db would start those jobs in the onLead callback.

Although upon closer inspection, I see that's a one time thing.

@moshloop moshloop merged commit 01710f9 into main Oct 16, 2024
5 checks passed
@moshloop moshloop deleted the feat/leader-election branch October 16, 2024 06:50
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