Skip to content

Commit

Permalink
[wildfly#301] Replace leader-for-life leader election with leader-for…
Browse files Browse the repository at this point in the history
…-lease

Fixes wildfly#301
  • Loading branch information
yersan committed Apr 24, 2024
1 parent 9796e91 commit 3ab631c
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ limitations under the License.
package main

import (
"context"
"flag"
"fmt"
"github.com/RHsyseng/operator-utils/pkg/utils/openshift"
"go.uber.org/zap/zapcore"
"os"
goruntime "runtime"
"time"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"

route "github.com/openshift/api/route/v1"
"github.com/operator-framework/operator-lib/leader"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
wildflyv1alpha1 "github.com/wildfly/wildfly-operator/api/v1alpha1"
"github.com/wildfly/wildfly-operator/controllers"
Expand Down Expand Up @@ -90,13 +90,8 @@ func main() {
}
setupLog.Info("Watching namespace", "namespace", namespace)

if enableLeaderElection {
err = leader.Become(context.TODO(), "t3dv81741s.wildfly-operator-lock")
if err != nil {
setupLog.Error(err, "Failed to retry for leader lock")
os.Exit(1)
}
}
leaseDuration := 30 * time.Second
renewDeadline := 20 * time.Second

setupLog.Info("Starting the Manager")
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Expand All @@ -105,7 +100,10 @@ func main() {
Port: 9443,
Namespace: namespace,
HealthProbeBindAddress: probeAddr,
LeaderElection: false,
LeaderElection: enableLeaderElection,
LeaderElectionID: "8kr4rta7hq.wildfly-operator-lock",
LeaseDuration: &leaseDuration,
RenewDeadline: &renewDeadline,
Logger: ctrl.Log.WithName("manager"),
})
if err != nil {
Expand Down

0 comments on commit 3ab631c

Please sign in to comment.