Merge pull request #318 from fluxcd/le-config

Set leader election deadline to 30s
This commit is contained in:
Stefan Prodan 2021-03-25 16:19:07 +02:00 committed by GitHub
commit eaec1642cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 27 deletions

2
go.mod
View File

@ -13,7 +13,7 @@ require (
github.com/fluxcd/pkg/gitutil v0.0.1 github.com/fluxcd/pkg/gitutil v0.0.1
github.com/fluxcd/pkg/helmtestserver v0.1.0 github.com/fluxcd/pkg/helmtestserver v0.1.0
github.com/fluxcd/pkg/lockedfile v0.0.5 github.com/fluxcd/pkg/lockedfile v0.0.5
github.com/fluxcd/pkg/runtime v0.8.5 github.com/fluxcd/pkg/runtime v0.10.1
github.com/fluxcd/pkg/ssh v0.0.5 github.com/fluxcd/pkg/ssh v0.0.5
github.com/fluxcd/pkg/untar v0.0.5 github.com/fluxcd/pkg/untar v0.0.5
github.com/fluxcd/pkg/version v0.0.1 github.com/fluxcd/pkg/version v0.0.1

4
go.sum
View File

@ -262,8 +262,8 @@ github.com/fluxcd/pkg/helmtestserver v0.1.0 h1:RiVVxIHD6PJdKinW46feFIYf1LUj6xXSp
github.com/fluxcd/pkg/helmtestserver v0.1.0/go.mod h1:3L+tbPn74PsHwHsyhbfk/kZAosrwMFTTA92XEFiwVAE= github.com/fluxcd/pkg/helmtestserver v0.1.0/go.mod h1:3L+tbPn74PsHwHsyhbfk/kZAosrwMFTTA92XEFiwVAE=
github.com/fluxcd/pkg/lockedfile v0.0.5 h1:C3T8wfdff1UY1bvplmCkGOLrdMWJHO8Q8+tdlEXJYzQ= github.com/fluxcd/pkg/lockedfile v0.0.5 h1:C3T8wfdff1UY1bvplmCkGOLrdMWJHO8Q8+tdlEXJYzQ=
github.com/fluxcd/pkg/lockedfile v0.0.5/go.mod h1:uAtPUBId6a2RqO84MTH5HKGX0SbM1kNW3Wr/FhYyDVA= github.com/fluxcd/pkg/lockedfile v0.0.5/go.mod h1:uAtPUBId6a2RqO84MTH5HKGX0SbM1kNW3Wr/FhYyDVA=
github.com/fluxcd/pkg/runtime v0.8.5 h1:ynh8fszbLQ3QSisQBNOABEUTnvt+/QfCdaL6gOJQcoQ= github.com/fluxcd/pkg/runtime v0.10.1 h1:NV0pe6lFzodKBIz0dT3xkoR0wJnTCicXwM/v/d5T0+Y=
github.com/fluxcd/pkg/runtime v0.8.5/go.mod h1:JD0eZIn5xkTeHHQUWXSqJPIh/ecO0d0qrUKbSVHnpnw= github.com/fluxcd/pkg/runtime v0.10.1/go.mod h1:JD0eZIn5xkTeHHQUWXSqJPIh/ecO0d0qrUKbSVHnpnw=
github.com/fluxcd/pkg/ssh v0.0.5 h1:rnbFZ7voy2JBlUfMbfyqArX2FYaLNpDhccGFC3qW83A= github.com/fluxcd/pkg/ssh v0.0.5 h1:rnbFZ7voy2JBlUfMbfyqArX2FYaLNpDhccGFC3qW83A=
github.com/fluxcd/pkg/ssh v0.0.5/go.mod h1:7jXPdXZpc0ttMNz2kD9QuMi3RNn/e0DOFbj0Tij/+Hs= github.com/fluxcd/pkg/ssh v0.0.5/go.mod h1:7jXPdXZpc0ttMNz2kD9QuMi3RNn/e0DOFbj0Tij/+Hs=
github.com/fluxcd/pkg/testserver v0.0.2 h1:SoaMtO9cE5p/wl2zkGudzflnEHd9mk68CGjZOo7w0Uk= github.com/fluxcd/pkg/testserver v0.0.2 h1:SoaMtO9cE5p/wl2zkGudzflnEHd9mk68CGjZOo7w0Uk=

49
main.go
View File

@ -36,6 +36,7 @@ import (
"github.com/fluxcd/pkg/runtime/client" "github.com/fluxcd/pkg/runtime/client"
"github.com/fluxcd/pkg/runtime/events" "github.com/fluxcd/pkg/runtime/events"
"github.com/fluxcd/pkg/runtime/leaderelection"
"github.com/fluxcd/pkg/runtime/logger" "github.com/fluxcd/pkg/runtime/logger"
"github.com/fluxcd/pkg/runtime/metrics" "github.com/fluxcd/pkg/runtime/metrics"
"github.com/fluxcd/pkg/runtime/pprof" "github.com/fluxcd/pkg/runtime/pprof"
@ -66,17 +67,17 @@ func init() {
func main() { func main() {
var ( var (
metricsAddr string metricsAddr string
eventsAddr string eventsAddr string
healthAddr string healthAddr string
enableLeaderElection bool storagePath string
storagePath string storageAddr string
storageAddr string storageAdvAddr string
storageAdvAddr string concurrent int
concurrent int watchAllNamespaces bool
watchAllNamespaces bool clientOptions client.Options
clientOptions client.Options logOptions logger.Options
logOptions logger.Options leaderElectionOptions leaderelection.Options
) )
flag.StringVar(&metricsAddr, "metrics-addr", envOrDefault("METRICS_ADDR", ":8080"), flag.StringVar(&metricsAddr, "metrics-addr", envOrDefault("METRICS_ADDR", ":8080"),
@ -84,9 +85,6 @@ func main() {
flag.StringVar(&eventsAddr, "events-addr", envOrDefault("EVENTS_ADDR", ""), flag.StringVar(&eventsAddr, "events-addr", envOrDefault("EVENTS_ADDR", ""),
"The address of the events receiver.") "The address of the events receiver.")
flag.StringVar(&healthAddr, "health-addr", ":9440", "The address the health endpoint binds to.") flag.StringVar(&healthAddr, "health-addr", ":9440", "The address the health 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(&storagePath, "storage-path", envOrDefault("STORAGE_PATH", ""), flag.StringVar(&storagePath, "storage-path", envOrDefault("STORAGE_PATH", ""),
"The local storage path.") "The local storage path.")
flag.StringVar(&storageAddr, "storage-addr", envOrDefault("STORAGE_ADDR", ":9090"), flag.StringVar(&storageAddr, "storage-addr", envOrDefault("STORAGE_ADDR", ":9090"),
@ -96,10 +94,9 @@ func main() {
flag.IntVar(&concurrent, "concurrent", 2, "The number of concurrent reconciles per controller.") flag.IntVar(&concurrent, "concurrent", 2, "The number of concurrent reconciles per controller.")
flag.BoolVar(&watchAllNamespaces, "watch-all-namespaces", true, flag.BoolVar(&watchAllNamespaces, "watch-all-namespaces", true,
"Watch for custom resources in all namespaces, if set to false it will only watch the runtime namespace.") "Watch for custom resources in all namespaces, if set to false it will only watch the runtime namespace.")
flag.Bool("log-json", false, "Set logging to JSON format.")
flag.CommandLine.MarkDeprecated("log-json", "Please use --log-encoding=json instead.")
clientOptions.BindFlags(flag.CommandLine) clientOptions.BindFlags(flag.CommandLine)
logOptions.BindFlags(flag.CommandLine) logOptions.BindFlags(flag.CommandLine)
leaderElectionOptions.BindFlags(flag.CommandLine)
flag.Parse() flag.Parse()
ctrl.SetLogger(logger.NewLogger(logOptions)) ctrl.SetLogger(logger.NewLogger(logOptions))
@ -124,14 +121,18 @@ func main() {
restConfig := client.GetConfigOrDie(clientOptions) restConfig := client.GetConfigOrDie(clientOptions)
mgr, err := ctrl.NewManager(restConfig, ctrl.Options{ mgr, err := ctrl.NewManager(restConfig, ctrl.Options{
Scheme: scheme, Scheme: scheme,
MetricsBindAddress: metricsAddr, MetricsBindAddress: metricsAddr,
HealthProbeBindAddress: healthAddr, HealthProbeBindAddress: healthAddr,
Port: 9443, Port: 9443,
LeaderElection: enableLeaderElection, LeaderElection: leaderElectionOptions.Enable,
LeaderElectionID: "305740c0.fluxcd.io", LeaderElectionReleaseOnCancel: leaderElectionOptions.ReleaseOnCancel,
Namespace: watchNamespace, LeaseDuration: &leaderElectionOptions.LeaseDuration,
Logger: ctrl.Log, RenewDeadline: &leaderElectionOptions.RenewDeadline,
RetryPeriod: &leaderElectionOptions.RetryPeriod,
LeaderElectionID: "305740c0.fluxcd.io",
Namespace: watchNamespace,
Logger: ctrl.Log,
}) })
if err != nil { if err != nil {
setupLog.Error(err, "unable to start manager") setupLog.Error(err, "unable to start manager")