jlevesy / prometheus-elector

Leader election for prometheus
25 stars 2 forks source link

Introduce a start/stoppable elector #36

Closed jlevesy closed 1 year ago

jlevesy commented 1 year ago

What Does This PR do?

For #35 we're going to need to pull of from the election if the local Prometheus instance isn't healthy. Sadlly the k8s leader election API doesn't allow to easily start and stop.

As a consequence this PR introduces our own Elector abstraction, that can be started and stopped.

It is also a tad cleaner than the existing setup.

Relates to: #35

How to Test This PR?

As for now I tried it by patching main.go and introducing this logic after the elector has initially started. It behaves as expected.

for {
                         time.Sleep(30 * time.Second)
                         klog.Info("HAHAHA LEAVING ELECTION BECAUSE WHY NOT")

                         klog.Info(elector.Stop(grpCtx))

                         time.Sleep(30 * time.Second)
                         klog.Info("OKAY I'M BACK IN THE RACE")

                        klog.Info(elector.Start(grpCtx))
 }

I'll also introduce a unit test suite for the election package.

Good PR Checklist

Additional Notes