Skip to content

Commit a2e72f1

Browse files
authored
Merge pull request #369 from rabbitmq/sync-period
Support setting manager sync period using operator envVar
2 parents 9f8bcac + 641b361 commit a2e72f1

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

controllers/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const (
3939
KubernetesInternalDomainEnvVar = "MESSAGING_DOMAIN_NAME"
4040
OperatorNamespaceEnvVar = "OPERATOR_NAMESPACE"
4141
EnableWebhooksEnvVar = "ENABLE_WEBHOOKS"
42+
ControllerSyncPeriodEnvVar = "SYNC_PERIOD"
4243
)
4344

4445
type TopologyController interface {

main.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"os"
1717
"regexp"
1818
"strings"
19+
"time"
1920

2021
"k8s.io/apimachinery/pkg/runtime"
2122
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
@@ -87,13 +88,25 @@ func main() {
8788

8889
clusterDomain := sanitizeClusterDomainInput(os.Getenv(controllers.KubernetesInternalDomainEnvVar))
8990

90-
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
91+
managerOpts := ctrl.Options{
9192
Scheme: scheme,
9293
MetricsBindAddress: metricsAddr,
9394
LeaderElection: true,
9495
LeaderElectionNamespace: operatorNamespace,
9596
LeaderElectionID: "messaging-topology-operator-leader-election",
96-
})
97+
}
98+
99+
if syncPeriod := os.Getenv(controllers.ControllerSyncPeriodEnvVar); syncPeriod != "" {
100+
syncPeriodDuration, err := time.ParseDuration(syncPeriod)
101+
if err != nil {
102+
log.Error(err, "unable to parse provided sync period", "sync period", syncPeriod)
103+
os.Exit(1)
104+
}
105+
managerOpts.SyncPeriod = &syncPeriodDuration
106+
log.Info(fmt.Sprintf("sync period set; all resources will be reconciled every: %s", syncPeriodDuration))
107+
}
108+
109+
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), managerOpts)
97110
if err != nil {
98111
log.Error(err, "unable to start manager")
99112
os.Exit(1)

0 commit comments

Comments
 (0)