Allow defining unique election leader id

This commit is contained in:
Rolf Ahrenberg 2021-09-11 18:26:29 +03:00 committed by Yusuke Kuoka
parent e5b5ee6f1d
commit 5da808af96
3 changed files with 14 additions and 1 deletions

View File

@ -37,7 +37,12 @@ spec:
{{- $metricsHost := .Values.metrics.proxy.enabled | ternary "127.0.0.1" "0.0.0.0" }} {{- $metricsHost := .Values.metrics.proxy.enabled | ternary "127.0.0.1" "0.0.0.0" }}
{{- $metricsPort := .Values.metrics.proxy.enabled | ternary "8080" .Values.metrics.port }} {{- $metricsPort := .Values.metrics.proxy.enabled | ternary "8080" .Values.metrics.port }}
- "--metrics-addr={{ $metricsHost }}:{{ $metricsPort }}" - "--metrics-addr={{ $metricsHost }}:{{ $metricsPort }}"
{{- if .Values.controller.enableLeaderElection }}
- "--enable-leader-election" - "--enable-leader-election"
{{- end }}
{{- if .Values.controller.leaderElectionId }}
- "--leader-election-id={{ .Values.controller.leaderElectionId }}"
{{- end }}
- "--sync-period={{ .Values.syncPeriod }}" - "--sync-period={{ .Values.syncPeriod }}"
- "--docker-image={{ .Values.image.dindSidecarRepositoryAndTag }}" - "--docker-image={{ .Values.image.dindSidecarRepositoryAndTag }}"
- "--runner-image={{ .Values.image.actionsRunnerRepositoryAndTag }}" - "--runner-image={{ .Values.image.actionsRunnerRepositoryAndTag }}"

View File

@ -8,6 +8,12 @@ replicaCount: 1
syncPeriod: 10m syncPeriod: 10m
controller:
enableLeaderElection: true
# Specifies the controller id for leader election.
# Must be unique if more than one controller installed.
#leaderElectionId: "actions-runner-controller"
# The controller tries its best not to repeat the duplicate GitHub API call # The controller tries its best not to repeat the duplicate GitHub API call
# within this duration. # within this duration.
# Defaults to syncPeriod - 10s. # Defaults to syncPeriod - 10s.

View File

@ -65,6 +65,7 @@ func main() {
metricsAddr string metricsAddr string
enableLeaderElection bool enableLeaderElection bool
leaderElectionId string
syncPeriod time.Duration syncPeriod time.Duration
gitHubAPICacheDuration time.Duration gitHubAPICacheDuration time.Duration
@ -87,6 +88,7 @@ func main() {
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.") flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false, flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.") "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
flag.StringVar(&leaderElectionId, "leader-election-id", "actions-runner-controller", "Controller id for leader election.")
flag.StringVar(&runnerImage, "runner-image", defaultRunnerImage, "The image name of self-hosted runner container.") flag.StringVar(&runnerImage, "runner-image", defaultRunnerImage, "The image name of self-hosted runner container.")
flag.StringVar(&dockerImage, "docker-image", defaultDockerImage, "The image name of docker sidecar container.") flag.StringVar(&dockerImage, "docker-image", defaultDockerImage, "The image name of docker sidecar container.")
flag.StringVar(&dockerRegistryMirror, "docker-registry-mirror", "", "The default Docker Registry Mirror used by runners.") flag.StringVar(&dockerRegistryMirror, "docker-registry-mirror", "", "The default Docker Registry Mirror used by runners.")
@ -129,7 +131,7 @@ func main() {
Scheme: scheme, Scheme: scheme,
MetricsBindAddress: metricsAddr, MetricsBindAddress: metricsAddr,
LeaderElection: enableLeaderElection, LeaderElection: enableLeaderElection,
LeaderElectionID: "actions-runner-controller", LeaderElectionID: leaderElectionId,
Port: 9443, Port: 9443,
SyncPeriod: &syncPeriod, SyncPeriod: &syncPeriod,
Namespace: namespace, Namespace: namespace,