Default LeaderElectionResourceLock to leases
Controller runtime sets by default leader-election-resource-lock to ConfigMapsLeasesResourceLock so consumers can do smooth transitions.
This PR defaults our contorller to leases.
This mitigates overwhelming the apiserver in a large management cluster and avoid additional rbac.
@@ -28,18 +28,12 @@ import (
"time"
"github.com/spf13/pflag"
-
"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
+ "k8s.io/client-go/tools/leaderelection/resourcelock"
cgrecord "k8s.io/client-go/tools/record"
"k8s.io/klog/v2"
"k8s.io/klog/v2/klogr"
- ctrl "sigs.k8s.io/controller-runtime"
- "sigs.k8s.io/controller-runtime/pkg/controller"
-
- clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
- clusterv1exp "sigs.k8s.io/cluster-api/exp/api/v1alpha4"
-
infrav1alpha3 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha3"
infrav1alpha4 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha4"
bootstrapv1alpha3 "sigs.k8s.io/cluster-api-provider-aws/bootstrap/eks/api/v1alpha3"
@@ -59,6 +53,10 @@ import (
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/scope"
"sigs.k8s.io/cluster-api-provider-aws/pkg/record"
"sigs.k8s.io/cluster-api-provider-aws/version"
+ clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
+ clusterv1exp "sigs.k8s.io/cluster-api/exp/api/v1alpha4"
+ ctrl "sigs.k8s.io/controller-runtime"
+ "sigs.k8s.io/controller-runtime/pkg/controller"
// +kubebuilder:scaffold:imports
)
@@ -136,6 +134,7 @@ func main() {
Scheme: scheme,
MetricsBindAddress: metricsBindAddr,
LeaderElection: enableLeaderElection,
+ LeaderElectionResourceLock: resourcelock.LeasesResourceLock,
LeaderElectionID: "controller-leader-elect-capa",
LeaderElectionNamespace: leaderElectionNamespace,
SyncPeriod: &syncPeriod,
