Skip to content

Commit 04c023c

Browse files
cspl-2532: fix for leader election lost issue (#1281)
* fix for leader election lost issue * runs nigtly once a week
1 parent 7208833 commit 04c023c

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

.github/workflows/nightly-int-test-workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Nightly Integration Test WorkFlow
22
on:
33
schedule:
4-
- cron: "0 06 * * *"
4+
- cron: "0 06 * * 0"
55
jobs:
66
build-operator-image:
77
runs-on: ubuntu-latest

main.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package main
1919
import (
2020
"flag"
2121
"os"
22+
"time"
2223

2324
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
2425
// to ensure that exec-entrypoint and run can make use of them.
@@ -66,14 +67,34 @@ func main() {
6667
var logEncoder string
6768
var logLevel int
6869

69-
flag.StringVar(&logEncoder, "logEncoder", "json", "log encoding ('json' or 'console')")
70+
var leaseDuration time.Duration
71+
var renewDeadline time.Duration
72+
var leaseDurationSecond int
73+
var renewDeadlineSecond int
74+
75+
flag.StringVar(&logEncoder, "log-encoder", "json", "log encoding ('json' or 'console')")
7076
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
7177
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
7278
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
7379
"Enable leader election for controller manager. "+
7480
"Enabling this will ensure there is only one active controller manager.")
7581
flag.BoolVar(&pprofActive, "pprof", true, "Enable pprof endpoint")
76-
flag.IntVar(&logLevel, "loglevel", int(zapcore.InfoLevel), "set log level")
82+
flag.IntVar(&logLevel, "log-level", int(zapcore.InfoLevel), "set log level")
83+
flag.IntVar(&leaseDurationSecond, "lease-duration", int(leaseDurationSecond), "manager lease duration in seconds")
84+
flag.IntVar(&renewDeadlineSecond, "renew-duration", int(renewDeadlineSecond), "manager renew duration in seconds")
85+
86+
// see https://github.com/operator-framework/operator-sdk/issues/1813
87+
if leaseDurationSecond < 30 {
88+
leaseDuration = 30 * time.Second
89+
} else {
90+
leaseDuration = time.Duration(leaseDurationSecond) * time.Second
91+
}
92+
93+
if renewDeadlineSecond < 20 {
94+
renewDeadline = 20 * time.Second
95+
} else {
96+
renewDeadline = time.Duration(renewDeadlineSecond) * time.Second
97+
}
7798

7899
opts := zap.Options{
79100
Development: true,
@@ -92,6 +113,8 @@ func main() {
92113
HealthProbeBindAddress: probeAddr,
93114
LeaderElection: enableLeaderElection,
94115
LeaderElectionID: "270bec8c.splunk.com",
116+
LeaseDuration: &leaseDuration,
117+
RenewDeadline: &renewDeadline,
95118
}
96119

97120
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), config.ManagerOptionsWithNamespaces(setupLog, options))

0 commit comments

Comments
 (0)