Skip to content

Commit 616fa78

Browse files
mprahlopenshift-merge-robot
authored andcommitted
Add an option to disable the spec-sync controller
When running on the Hub, spec-sync controller should be disabled since the replicated policies are already present on the Hub from the Policy Propagator. Relates: stolostron/backlog#25999 stolostron/backlog#25949 Signed-off-by: mprahl <[email protected]>
1 parent 5711c68 commit 616fa78

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

main.go

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,23 @@ func main() {
233233
os.Exit(1)
234234
}
235235

236+
healthAddresses := []string{mgrHealthAddr}
237+
236238
mgr := getManager(mgrOptionsBase, mgrHealthAddr, hubCfg, managedCfg)
237239

238-
hubMgrHealthAddr, err := getFreeLocalAddr()
239-
if err != nil {
240-
log.Error(err, "Failed to get a free port for the health endpoint")
241-
os.Exit(1)
242-
}
240+
var hubMgr manager.Manager
243241

244-
hubMgr := getHubManager(mgrOptionsBase, hubMgrHealthAddr, hubCfg, managedCfg)
242+
if !tool.Options.DisableSpecSync {
243+
hubMgrHealthAddr, err := getFreeLocalAddr()
244+
if err != nil {
245+
log.Error(err, "Failed to get a free port for the health endpoint")
246+
os.Exit(1)
247+
}
248+
249+
healthAddresses = append(healthAddresses, hubMgrHealthAddr)
250+
251+
hubMgr = getHubManager(mgrOptionsBase, hubMgrHealthAddr, hubCfg, managedCfg)
252+
}
245253

246254
log.Info("Starting the controller managers")
247255

@@ -253,7 +261,7 @@ func main() {
253261
wg.Add(1)
254262

255263
go func() {
256-
err := startHealthProxy(mgrCtx, &wg, mgrHealthAddr, hubMgrHealthAddr)
264+
err := startHealthProxy(mgrCtx, &wg, healthAddresses...)
257265
if err != nil {
258266
log.Error(err, "failed to start the health endpoint proxy")
259267

@@ -279,20 +287,22 @@ func main() {
279287
wg.Done()
280288
}()
281289

282-
wg.Add(1)
290+
if !tool.Options.DisableSpecSync {
291+
wg.Add(1)
283292

284-
go func() {
285-
if err := hubMgr.Start(mgrCtx); err != nil {
286-
log.Error(err, "problem running hub manager")
293+
go func() {
294+
if err := hubMgr.Start(mgrCtx); err != nil {
295+
log.Error(err, "problem running hub manager")
287296

288-
// On errors, the parent context (mainCtx) may not have closed, so cancel the child context.
289-
mgrCtxCancel()
297+
// On errors, the parent context (mainCtx) may not have closed, so cancel the child context.
298+
mgrCtxCancel()
290299

291-
errorExit = true
292-
}
300+
errorExit = true
301+
}
293302

294-
wg.Done()
295-
}()
303+
wg.Done()
304+
}()
305+
}
296306

297307
wg.Wait()
298308

tool/options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type SyncerOptions struct {
1515
ClusterNamespaceOnHub string
1616
HubConfigFilePathName string
1717
ManagedConfigFilePathName string
18+
DisableSpecSync bool
1819
EnableLease bool
1920
EnableLeaderElection bool
2021
LegacyLeaderElection bool
@@ -66,6 +67,13 @@ func ProcessFlags() {
6667
"If enabled, the controller will start the lease controller to report its status",
6768
)
6869

70+
flag.BoolVar(
71+
&Options.DisableSpecSync,
72+
"disable-spec-sync",
73+
false,
74+
"If enabled, the spec-sync controller will not be started. This is used when running on the Hub.",
75+
)
76+
6977
flag.BoolVar(
7078
&Options.EnableLeaderElection,
7179
"leader-elect",

0 commit comments

Comments
 (0)