Skip to content

Commit 8bc7d1c

Browse files
fix(controller): add leader-election (#743)
Signed-off-by: Oliver Bähler <[email protected]>
1 parent bab3fba commit 8bc7d1c

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

main.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
ctrl "sigs.k8s.io/controller-runtime"
2525
"sigs.k8s.io/controller-runtime/pkg/client"
2626
"sigs.k8s.io/controller-runtime/pkg/log/zap"
27+
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
2728
ctrlwebhook "sigs.k8s.io/controller-runtime/pkg/webhook"
2829
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2930

@@ -58,17 +59,17 @@ func main() {
5859
utilruntime.Must(apiextensionsv1.AddToScheme(scheme))
5960

6061
var (
61-
err error
62-
mgr ctrl.Manager
63-
certPath, keyPath, usernameClaimField, capsuleConfigurationName, impersonationGroupsRegexp string
64-
capsuleUserGroups, ignoredUserGroups, ignoreImpersonationGroups []string
65-
listeningPort uint
66-
bindSsl, disableCaching, enablePprof bool
67-
rolebindingsResyncPeriod time.Duration
68-
clientConnectionQPS float32
69-
clientConnectionBurst int32
70-
webhookPort int
71-
hooks []WebhookType
62+
err error
63+
mgr ctrl.Manager
64+
certPath, keyPath, usernameClaimField, capsuleConfigurationName, impersonationGroupsRegexp, metricsAddr string
65+
capsuleUserGroups, ignoredUserGroups, ignoreImpersonationGroups []string
66+
listeningPort uint
67+
bindSsl, disableCaching, enablePprof, enableLeaderElection bool
68+
rolebindingsResyncPeriod time.Duration
69+
clientConnectionQPS float32
70+
clientConnectionBurst int32
71+
webhookPort int
72+
hooks []WebhookType
7273
)
7374

7475
gates := featuregate.NewFeatureGate()
@@ -107,6 +108,10 @@ func main() {
107108
}
108109

109110
flag.IntVar(&webhookPort, "webhook-port", 9443, "The port the webhook server binds to.")
111+
flag.BoolVar(&enableLeaderElection, "enable-leader-election", true,
112+
"Enable leader election for controller manager. "+
113+
"Enabling this will ensure there is only one active controller manager.")
114+
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
110115
flag.StringVar(&capsuleConfigurationName, "capsule-configuration-name", "default", "Name of the CapsuleConfiguration used to retrieve the Capsule user groups names")
111116
flag.StringSliceVar(&capsuleUserGroups, "capsule-user-group", []string{}, "Names of the groups for capsule users (deprecated: use capsule-configuration-name)")
112117
flag.StringSliceVar(&ignoredUserGroups, "ignored-user-group", []string{}, "Names of the groups which requests must be ignored and proxy-passed to the upstream server")
@@ -198,8 +203,13 @@ First match is used and can be specified multiple times as comma separated value
198203

199204
// Base Config
200205
ctrlConfig := ctrl.Options{
201-
Scheme: scheme,
206+
Scheme: scheme,
207+
Metrics: metricsserver.Options{
208+
BindAddress: metricsAddr,
209+
},
202210
HealthProbeBindAddress: ":8081",
211+
LeaderElection: enableLeaderElection,
212+
LeaderElectionID: "42dadw1.proxy.projectcapsule.dev",
203213
}
204214

205215
if len(hooks) > 0 {

0 commit comments

Comments
 (0)