Skip to content

Commit 019a52f

Browse files
authored
Merge pull request #3273 from alvaroaleman/certwatcher-le
🌱 Certwatcher: Don't require leaderelection
2 parents 6707052 + 4dfefb0 commit 019a52f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pkg/certwatcher/certwatcher.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,9 @@ func (cw *CertWatcher) handleEvent(event fsnotify.Event) {
240240
log.Error(err, "error re-reading certificate")
241241
}
242242
}
243+
244+
// NeedLeaderElection indicates that the cert-manager
245+
// does not need leader election.
246+
func (cw *CertWatcher) NeedLeaderElection() bool {
247+
return false
248+
}

pkg/certwatcher/certwatcher_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737

3838
"sigs.k8s.io/controller-runtime/pkg/certwatcher"
3939
"sigs.k8s.io/controller-runtime/pkg/certwatcher/metrics"
40+
"sigs.k8s.io/controller-runtime/pkg/manager"
4041
)
4142

4243
var _ = Describe("CertWatcher", func() {
@@ -92,6 +93,12 @@ var _ = Describe("CertWatcher", func() {
9293
}
9394
})
9495

96+
It("should not require LeaderElection", func() {
97+
leaderElectionRunnable, isLeaderElectionRunnable := any(watcher).(manager.LeaderElectionRunnable)
98+
Expect(isLeaderElectionRunnable).To(BeTrue())
99+
Expect(leaderElectionRunnable.NeedLeaderElection()).To(BeFalse())
100+
})
101+
95102
It("should read the initial cert/key", func() {
96103
// This test verifies the initial read succeeded. So interval doesn't matter.
97104
doneCh := startWatcher(10 * time.Second)

0 commit comments

Comments
 (0)