Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve LeaderElection #190

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions cmd/yawol-cloud-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,32 +121,34 @@ func main() {
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

targetMgr, err := ctrl.NewManager(getConfigFromKubeconfigOrDie(targetKubeconfig), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
LeaderElection: targetEnableLeaderElection,
LeaderElectionID: "4c878ae2.stackit.cloud",
LeaseDuration: &leasesDuration,
RenewDeadline: &leasesRenewDeadline,
RetryPeriod: &leasesRetryPeriod,
LeaderElectionResourceLock: leasesLeaderElectionResourceLock,
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
LeaderElection: targetEnableLeaderElection,
LeaderElectionReleaseOnCancel: true,
LeaderElectionID: "4c878ae2.stackit.cloud",
LeaseDuration: &leasesDuration,
RenewDeadline: &leasesRenewDeadline,
RetryPeriod: &leasesRetryPeriod,
LeaderElectionResourceLock: leasesLeaderElectionResourceLock,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
}

controlMgr, err := ctrl.NewManager(getConfigFromKubeconfigOrDie(controlKubeconfig), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: "0",
Port: 9443,
Namespace: *infrastructureDefaults.Namespace,
LeaderElection: controlEnableLeaderElection,
LeaderElectionID: "4c878ae2.stackit.cloud",
LeaseDuration: &leasesDuration,
RenewDeadline: &leasesRenewDeadline,
RetryPeriod: &leasesRetryPeriod,
LeaderElectionResourceLock: leasesLeaderElectionResourceLock,
Scheme: scheme,
MetricsBindAddress: "0",
Port: 9443,
Namespace: *infrastructureDefaults.Namespace,
LeaderElection: controlEnableLeaderElection,
LeaderElectionReleaseOnCancel: true,
LeaderElectionID: "4c878ae2.stackit.cloud",
LeaseDuration: &leasesDuration,
RenewDeadline: &leasesRenewDeadline,
RetryPeriod: &leasesRetryPeriod,
LeaderElectionResourceLock: leasesLeaderElectionResourceLock,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down
63 changes: 33 additions & 30 deletions cmd/yawol-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,17 @@ func main() {
// LoadBalancer Controller
if lbController {
loadBalancerMgr, err = ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddrLb,
Port: 9443,
LeaderElection: enableLeaderElection,
LeaderElectionID: "3a7ac996.stackit.cloud",
LeaseDuration: &leasesDuration,
RenewDeadline: &leasesRenewDeadline,
RetryPeriod: &leasesRetryPeriod,
LeaderElectionResourceLock: leasesLeaderElectionResourceLock,
Namespace: clusterNamespace,
Scheme: scheme,
MetricsBindAddress: metricsAddrLb,
Port: 9443,
LeaderElection: enableLeaderElection,
LeaderElectionReleaseOnCancel: true,
LeaderElectionID: "3a7ac996.stackit.cloud",
LeaseDuration: &leasesDuration,
RenewDeadline: &leasesRenewDeadline,
RetryPeriod: &leasesRetryPeriod,
LeaderElectionResourceLock: leasesLeaderElectionResourceLock,
Namespace: clusterNamespace,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down Expand Up @@ -196,16 +197,17 @@ func main() {
// LoadBalancerSet Controller
if lbSetController {
loadBalancerSetMgr, err = ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddrLbs,
Port: 9444,
LeaderElection: enableLeaderElection,
LeaderElectionID: "rgp5vg43.stackit.cloud",
LeaseDuration: &leasesDuration,
RenewDeadline: &leasesRenewDeadline,
RetryPeriod: &leasesRetryPeriod,
LeaderElectionResourceLock: leasesLeaderElectionResourceLock,
Namespace: clusterNamespace,
Scheme: scheme,
MetricsBindAddress: metricsAddrLbs,
Port: 9444,
LeaderElection: enableLeaderElection,
LeaderElectionReleaseOnCancel: true,
LeaderElectionID: "rgp5vg43.stackit.cloud",
LeaseDuration: &leasesDuration,
RenewDeadline: &leasesRenewDeadline,
RetryPeriod: &leasesRetryPeriod,
LeaderElectionResourceLock: leasesLeaderElectionResourceLock,
Namespace: clusterNamespace,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down Expand Up @@ -246,16 +248,17 @@ func main() {
discoveryClient := discovery.NewDiscoveryClientForConfigOrDie(cfg)

loadBalancerMachineMgr, err = ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddrLbm,
Port: 9445,
LeaderElection: enableLeaderElection,
LeaderElectionID: "tanf7ges.stackit.cloud",
LeaseDuration: &leasesDuration,
RenewDeadline: &leasesRenewDeadline,
RetryPeriod: &leasesRetryPeriod,
LeaderElectionResourceLock: leasesLeaderElectionResourceLock,
Namespace: clusterNamespace,
Scheme: scheme,
MetricsBindAddress: metricsAddrLbm,
Port: 9445,
LeaderElection: enableLeaderElection,
LeaderElectionReleaseOnCancel: true,
LeaderElectionID: "tanf7ges.stackit.cloud",
LeaseDuration: &leasesDuration,
RenewDeadline: &leasesRenewDeadline,
RetryPeriod: &leasesRetryPeriod,
LeaderElectionResourceLock: leasesLeaderElectionResourceLock,
Namespace: clusterNamespace,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down
7 changes: 1 addition & 6 deletions cmd/yawollet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func init() {
func main() {
var metricsAddr string
var probeAddr string
var enableLeaderElection bool
var namespace string
var loadbalancerName string
var loadbalancerMachineName string
Expand All @@ -68,9 +67,6 @@ func main() {

flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metric endpoint binds to. Default is disabled.")
flag.StringVar(&probeAddr, "health-probe-bind-address", "0", "The address the probe endpoint binds to. Default is disabled.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")

flag.StringVar(&namespace, "namespace", "", "The namespace from lb und lbm object.")
flag.StringVar(&loadbalancerName, "loadbalancer-name", "", "Name of lb object.")
Expand Down Expand Up @@ -192,8 +188,7 @@ func main() {
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
LeaderElection: enableLeaderElection,
LeaderElectionID: "9df1d9a0.stackit.cloud",
LeaderElection: false,
Namespace: namespace,

NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) {
Expand Down