diff --git a/charts/actions-runner-controller/templates/deployment.yaml b/charts/actions-runner-controller/templates/deployment.yaml index 51e58462..e0384b75 100644 --- a/charts/actions-runner-controller/templates/deployment.yaml +++ b/charts/actions-runner-controller/templates/deployment.yaml @@ -37,7 +37,12 @@ spec: {{- $metricsHost := .Values.metrics.proxy.enabled | ternary "127.0.0.1" "0.0.0.0" }} {{- $metricsPort := .Values.metrics.proxy.enabled | ternary "8080" .Values.metrics.port }} - "--metrics-addr={{ $metricsHost }}:{{ $metricsPort }}" + {{- if .Values.controller.enableLeaderElection }} - "--enable-leader-election" + {{- end }} + {{- if .Values.controller.leaderElectionId }} + - "--leader-election-id={{ .Values.controller.leaderElectionId }}" + {{- end }} - "--sync-period={{ .Values.syncPeriod }}" - "--docker-image={{ .Values.image.dindSidecarRepositoryAndTag }}" - "--runner-image={{ .Values.image.actionsRunnerRepositoryAndTag }}" diff --git a/charts/actions-runner-controller/values.yaml b/charts/actions-runner-controller/values.yaml index 9e8633b0..3dbe4309 100644 --- a/charts/actions-runner-controller/values.yaml +++ b/charts/actions-runner-controller/values.yaml @@ -8,6 +8,12 @@ replicaCount: 1 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 # within this duration. # Defaults to syncPeriod - 10s. diff --git a/main.go b/main.go index d8d3bc58..ef02c2b4 100644 --- a/main.go +++ b/main.go @@ -65,6 +65,7 @@ func main() { metricsAddr string enableLeaderElection bool + leaderElectionId string syncPeriod 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.BoolVar(&enableLeaderElection, "enable-leader-election", false, "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(&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.") @@ -129,7 +131,7 @@ func main() { Scheme: scheme, MetricsBindAddress: metricsAddr, LeaderElection: enableLeaderElection, - LeaderElectionID: "actions-runner-controller", + LeaderElectionID: leaderElectionId, Port: 9443, SyncPeriod: &syncPeriod, Namespace: namespace,