From c7fe20db725c3c8a18d51d3849cf4c422544750b Mon Sep 17 00:00:00 2001 From: "David J. M. Karlsen" Date: Tue, 20 Sep 2022 11:41:25 +0200 Subject: [PATCH] Migrate away from configmaps as leader-eletion mechanism (#488) --- config/rbac/role.yaml | 6 ++++++ controllers/githubactionrunner_controller.go | 1 + main.go | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index f5b4c359..2ef3eced 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -24,6 +24,12 @@ rules: - secrets verbs: - '*' +- apiGroups: + - coordination.k8s.io + resources: + - leases + verbs: + - '*' - apiGroups: - garo.tietoevry.com resources: diff --git a/controllers/githubactionrunner_controller.go b/controllers/githubactionrunner_controller.go index 48cca993..c00cb025 100644 --- a/controllers/githubactionrunner_controller.go +++ b/controllers/githubactionrunner_controller.go @@ -73,6 +73,7 @@ func (r *GithubActionRunnerReconciler) IsValid(obj metav1.Object) (bool, error) // +kubebuilder:rbac:groups="",resources=pods,verbs="*" // +kubebuilder:rbac:groups="",resources=secrets,verbs="*" // +kubebuilder:rbac:groups="",resources=events,verbs=create;patch +// +kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,verbs="*" // Reconcile is the main loop implementing the controller action func (r *GithubActionRunnerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { diff --git a/main.go b/main.go index 56828afd..fd72354f 100644 --- a/main.go +++ b/main.go @@ -72,7 +72,7 @@ func main() { Namespace: namespace, LeaderElection: enableLeaderElection, LeaderElectionID: "4ef9cd91.tietoevry.com", - LeaderElectionResourceLock: "configmaps", + LeaderElectionResourceLock: "configmapsleases", } if strings.Contains(namespace, ",") { options.Namespace = ""