Skip to content

Commit

Permalink
Add an option to stat multiproject controller without leader election
Browse files Browse the repository at this point in the history
  • Loading branch information
panslava committed Jan 17, 2025
1 parent 717f4c9 commit 12a0122
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
46 changes: 31 additions & 15 deletions cmd/glbc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,21 +243,37 @@ func main() {
rootLogger.Info("Multi-project mode is enabled, starting project-syncer")

runWithWg(func() {
err := multiprojectstart.StartWithLeaderElection(
context.Background(),
leaderElectKubeClient,
hostname,
kubeConfig,
rootLogger,
kubeClient,
svcNegClient,
kubeSystemUID,
eventRecorderKubeClient,
namer,
stopCh,
)
if err != nil {
rootLogger.Error(err, "Failed to start multi-project syncer")
if flags.F.LeaderElection.LeaderElect {
err := multiprojectstart.StartWithLeaderElection(
context.Background(),
leaderElectKubeClient,
hostname,
kubeConfig,
rootLogger,
kubeClient,
svcNegClient,
kubeSystemUID,
eventRecorderKubeClient,
namer,
stopCh,
)
if err != nil {
rootLogger.Error(err, "Failed to start multi-project syncer with leader election")
}
} else {
multiprojectstart.Start(
kubeConfig,
rootLogger,
kubeClient,
svcNegClient,
kubeSystemUID,
eventRecorderKubeClient,
namer,
stopCh,
)
if err != nil {
rootLogger.Error(err, "Failed to start multi-project syncer")
}
}
}, rOption.wg)

Expand Down
4 changes: 2 additions & 2 deletions pkg/multiproject/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func makeLeaderElectionConfig(
RetryPeriod: flags.F.LeaderElection.RetryPeriod.Duration,
Callbacks: leaderelection.LeaderCallbacks{
OnStartedLeading: func(context.Context) {
start(kubeConfig, logger, kubeClient, svcNegClient, kubeSystemUID, eventRecorderKubeClient, rootNamer, stopCh)
Start(kubeConfig, logger, kubeClient, svcNegClient, kubeSystemUID, eventRecorderKubeClient, rootNamer, stopCh)
},
OnStoppedLeading: func() {
logger.Info("Stop running multi-project leader election")
Expand All @@ -102,7 +102,7 @@ func makeLeaderElectionConfig(
}, nil
}

func start(
func Start(
kubeConfig *rest.Config,
logger klog.Logger,
kubeClient kubernetes.Interface,
Expand Down

0 comments on commit 12a0122

Please sign in to comment.