exit with exit code 0 on cancel & release leader-election on cancel
Signed-off-by: Inteon <42113979+inteon@users.noreply.github.com>
This commit is contained in:
parent
632459c6d9
commit
48e9c2bd16
@ -117,15 +117,16 @@ servers and webhook servers.`,
|
||||
|
||||
func (o InjectorControllerOptions) RunInjectorController(ctx context.Context) error {
|
||||
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
|
||||
Scheme: api.Scheme,
|
||||
Namespace: o.Namespace,
|
||||
LeaderElection: o.LeaderElect,
|
||||
LeaderElectionNamespace: o.LeaderElectionNamespace,
|
||||
LeaderElectionID: "cert-manager-cainjector-leader-election",
|
||||
LeaseDuration: &o.LeaseDuration,
|
||||
RenewDeadline: &o.RenewDeadline,
|
||||
RetryPeriod: &o.RetryPeriod,
|
||||
MetricsBindAddress: "0",
|
||||
Scheme: api.Scheme,
|
||||
Namespace: o.Namespace,
|
||||
LeaderElection: o.LeaderElect,
|
||||
LeaderElectionNamespace: o.LeaderElectionNamespace,
|
||||
LeaderElectionID: "cert-manager-cainjector-leader-election",
|
||||
LeaderElectionReleaseOnCancel: true,
|
||||
LeaseDuration: &o.LeaseDuration,
|
||||
RenewDeadline: &o.RenewDeadline,
|
||||
RetryPeriod: &o.RetryPeriod,
|
||||
MetricsBindAddress: "0",
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating manager: %v", err)
|
||||
|
||||
@ -337,15 +337,22 @@ func startLeaderElection(ctx context.Context, opts *options.ControllerOptions, l
|
||||
|
||||
// Try and become the leader and start controller manager loops
|
||||
leaderelection.RunOrDie(ctx, leaderelection.LeaderElectionConfig{
|
||||
Lock: ml,
|
||||
LeaseDuration: opts.LeaderElectionLeaseDuration,
|
||||
RenewDeadline: opts.LeaderElectionRenewDeadline,
|
||||
RetryPeriod: opts.LeaderElectionRetryPeriod,
|
||||
Lock: ml,
|
||||
LeaseDuration: opts.LeaderElectionLeaseDuration,
|
||||
RenewDeadline: opts.LeaderElectionRenewDeadline,
|
||||
RetryPeriod: opts.LeaderElectionRetryPeriod,
|
||||
ReleaseOnCancel: true,
|
||||
Callbacks: leaderelection.LeaderCallbacks{
|
||||
OnStartedLeading: run,
|
||||
OnStoppedLeading: func() {
|
||||
log.V(logf.ErrorLevel).Info("leader election lost")
|
||||
os.Exit(1)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
// context was canceled, just return
|
||||
return
|
||||
default:
|
||||
log.V(logf.ErrorLevel).Info("leader election lost")
|
||||
os.Exit(1)
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user