Set leader election deadline to 30s

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
Stefan Prodan 2021-03-25 14:30:55 +02:00
parent 5d6ec2166e
commit a530be537e
No known key found for this signature in database
GPG Key ID: 3299AEB0E4085BAF
3 changed files with 33 additions and 28 deletions

2
go.mod
View File

@ -7,7 +7,7 @@ replace github.com/fluxcd/notification-controller/api => ./api
require ( require (
github.com/fluxcd/notification-controller/api v0.10.0 github.com/fluxcd/notification-controller/api v0.10.0
github.com/fluxcd/pkg/apis/meta v0.8.0 github.com/fluxcd/pkg/apis/meta v0.8.0
github.com/fluxcd/pkg/runtime v0.9.0 github.com/fluxcd/pkg/runtime v0.10.1
github.com/go-logr/logr v0.3.0 github.com/go-logr/logr v0.3.0
github.com/google/go-github/v32 v32.1.0 github.com/google/go-github/v32 v32.1.0
github.com/hashicorp/go-retryablehttp v0.6.8 github.com/hashicorp/go-retryablehttp v0.6.8

4
go.sum
View File

@ -96,8 +96,8 @@ github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLi
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fluxcd/pkg/apis/meta v0.8.0 h1:wqWpUsxhKHB1ZztcvOz+vnyhdKW9cWmjFp8Vci/XOdk= github.com/fluxcd/pkg/apis/meta v0.8.0 h1:wqWpUsxhKHB1ZztcvOz+vnyhdKW9cWmjFp8Vci/XOdk=
github.com/fluxcd/pkg/apis/meta v0.8.0/go.mod h1:yHuY8kyGHYz22I0jQzqMMGCcHViuzC/WPdo9Gisk8Po= github.com/fluxcd/pkg/apis/meta v0.8.0/go.mod h1:yHuY8kyGHYz22I0jQzqMMGCcHViuzC/WPdo9Gisk8Po=
github.com/fluxcd/pkg/runtime v0.9.0 h1:4ZnkyWg+MTEh6ne7E4DwS77nGsih7b5YscwVRIu+XfI= github.com/fluxcd/pkg/runtime v0.10.1 h1:NV0pe6lFzodKBIz0dT3xkoR0wJnTCicXwM/v/d5T0+Y=
github.com/fluxcd/pkg/runtime v0.9.0/go.mod h1:JD0eZIn5xkTeHHQUWXSqJPIh/ecO0d0qrUKbSVHnpnw= github.com/fluxcd/pkg/runtime v0.10.1/go.mod h1:JD0eZIn5xkTeHHQUWXSqJPIh/ecO0d0qrUKbSVHnpnw=
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=

55
main.go
View File

@ -17,6 +17,7 @@ limitations under the License.
package main package main
import ( import (
"fmt"
"os" "os"
flag "github.com/spf13/pflag" flag "github.com/spf13/pflag"
@ -26,17 +27,21 @@ import (
ctrl "sigs.k8s.io/controller-runtime" ctrl "sigs.k8s.io/controller-runtime"
crtlmetrics "sigs.k8s.io/controller-runtime/pkg/metrics" crtlmetrics "sigs.k8s.io/controller-runtime/pkg/metrics"
"github.com/fluxcd/notification-controller/api/v1beta1"
"github.com/fluxcd/notification-controller/controllers"
"github.com/fluxcd/notification-controller/internal/server"
"github.com/fluxcd/pkg/runtime/client" "github.com/fluxcd/pkg/runtime/client"
"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"
"github.com/fluxcd/pkg/runtime/probes" "github.com/fluxcd/pkg/runtime/probes"
"github.com/fluxcd/notification-controller/api/v1beta1"
"github.com/fluxcd/notification-controller/controllers"
"github.com/fluxcd/notification-controller/internal/server"
// +kubebuilder:scaffold:imports // +kubebuilder:scaffold:imports
) )
const controllerName = "notification-controller"
var ( var (
scheme = runtime.NewScheme() scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup") setupLog = ctrl.Log.WithName("setup")
@ -51,31 +56,27 @@ func init() {
func main() { func main() {
var ( var (
eventsAddr string eventsAddr string
receiverAddr string receiverAddr string
healthAddr string healthAddr string
metricsAddr string metricsAddr string
enableLeaderElection bool 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", ":8080", "The address the metric endpoint binds to.") flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&eventsAddr, "events-addr", ":9090", "The address the event endpoint binds to.") flag.StringVar(&eventsAddr, "events-addr", ":9090", "The address the event endpoint binds to.")
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.StringVar(&receiverAddr, "receiverAddr", ":9292", "The address the webhook receiver endpoint binds to.") flag.StringVar(&receiverAddr, "receiverAddr", ":9292", "The address the webhook receiver 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.IntVar(&concurrent, "concurrent", 4, "The number of concurrent notification reconciles.") flag.IntVar(&concurrent, "concurrent", 4, "The number of concurrent notification reconciles.")
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()
log := logger.NewLogger(logOptions) log := logger.NewLogger(logOptions)
@ -91,14 +92,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: "4ae6d3b3.fluxcd.io", LeaderElectionReleaseOnCancel: leaderElectionOptions.ReleaseOnCancel,
Namespace: watchNamespace, LeaseDuration: &leaderElectionOptions.LeaseDuration,
Logger: ctrl.Log, RenewDeadline: &leaderElectionOptions.RenewDeadline,
RetryPeriod: &leaderElectionOptions.RetryPeriod,
LeaderElectionID: fmt.Sprintf("%s-leader-election", controllerName),
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")