Skip to content

Conversation

basit9958
Copy link

@basit9958 basit9958 commented Aug 6, 2023

What this PR does / why we need it:

Added Leader Election Mechanism

OnStartedLeading: This callback is executed when the current instance becomes the leader. It starts running the controller logic by calling the Run function.
OnStoppedLeading: This callback is executed when the current instance is no longer the leader. It logs a message and may exit gracefully if needed.
OnNewLeader: This callback is executed when a new leader is elected. It logs a message indicating the new leader's identity.

Which issue(s) this PR fixes:

Fixes #838

Does this PR introduce a user-facing change?


Additional Notes for your reviewer:

Review Checklist:
  • Follows the developer guidelines
  • Relevant tests are added or updated
  • Relevant docs in this repo added or updated
  • Relevant carvel.dev docs added or updated in a separate PR and there's
    a link to that PR
  • Code is at least as readable and maintainable as it was before this
    change

Additional documentation e.g., Proposal, usage docs, etc.:


client *clientset.Clientset
)

func getNewLock(lockname, podname, namespace string) *resourcelock.LeaseLock {

Choose a reason for hiding this comment

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

Early Feedback: Can we move all the leader election code to a different file / module? Main ought to be as simple as possible (just start the app)

Copy link
Author

Choose a reason for hiding this comment

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

okay will look into this

@neil-hickey
Copy link

Hi @basit9958 , thanks for this!

Is this PR intended to be for demonstration / Proof of Concept purposes - or the intended feature complete? If it's intended to be complete, looks like it doesn't compile right now.

+ go build -trimpath -mod=vendor -o controller ./cmd/controller/...
# github.com/vmware-tanzu/carvel-kapp-controller/cmd/controller
Error: cmd/controller/main.go:113:20: cannot use lock (variable of type *resourcelock.LeaseLock) as "context".Context value in argument to runLeaderElection: *resourcelock.LeaseLock does not implement "context".Context (missing method Deadline)
Error: cmd/controller/main.go:113:26: cannot use ctx (variable of type "context".Context) as *resourcelock.LeaseLock value in argument to runLeaderElection
Error: Process completed with exit code 1.

@basit9958
Copy link
Author

Hi @basit9958 , thanks for this!

Is this PR intended to be for demonstration / Proof of Concept purposes - or the intended feature complete? If it's intended to be complete, looks like it doesn't compile right now.

+ go build -trimpath -mod=vendor -o controller ./cmd/controller/...
# github.com/vmware-tanzu/carvel-kapp-controller/cmd/controller
Error: cmd/controller/main.go:113:20: cannot use lock (variable of type *resourcelock.LeaseLock) as "context".Context value in argument to runLeaderElection: *resourcelock.LeaseLock does not implement "context".Context (missing method Deadline)
Error: cmd/controller/main.go:113:26: cannot use ctx (variable of type "context".Context) as *resourcelock.LeaseLock value in argument to runLeaderElection
Error: Process completed with exit code 1.

It is meant to be complete, I will fix these errors

Signed-off-by: Basit Hasan <[email protected]>
Signed-off-by: Basit Hasan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

kapp-controller leader election should provide safety during update operations
2 participants