diff --git a/controllers/controller_shared.go b/controllers/controller_shared.go index 1300e18f0..2e461fc33 100644 --- a/controllers/controller_shared.go +++ b/controllers/controller_shared.go @@ -26,9 +26,12 @@ import ( "sigs.k8s.io/controller-runtime/pkg/predicate" ) -const grafanaFinalizer = "operator.grafana.com/finalizer" - const ( + // Synchronization size and timeout values + syncBatchSize = 100 + initialSyncDelay = 10 * time.Second + RequeueDelay = 10 * time.Second + // condition types conditionNoMatchingInstance = "NoMatchingInstance" conditionNoMatchingFolder = "NoMatchingFolder" @@ -37,6 +40,7 @@ const ( // condition reasons conditionApplySuccessful = "ApplySuccessful" conditionApplyFailed = "ApplyFailed" + grafanaFinalizer = "operator.grafana.com/finalizer" ) //+kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,verbs=get;list;watch;create;update;patch;delete diff --git a/controllers/dashboard_controller.go b/controllers/dashboard_controller.go index fb85ef0d6..87f9b560f 100644 --- a/controllers/dashboard_controller.go +++ b/controllers/dashboard_controller.go @@ -57,8 +57,6 @@ import ( ) const ( - initialSyncDelay = "10s" - syncBatchSize = 100 conditionDashboardSynchronized = "DashboardSynchronized" ) @@ -756,17 +754,12 @@ func (r *GrafanaDashboardReconciler) SetupWithManager(mgr ctrl.Manager, ctx cont Complete(r) if err == nil { - d, err := time.ParseDuration(initialSyncDelay) - if err != nil { - return err - } - go func() { for { select { case <-ctx.Done(): return - case <-time.After(d): + case <-time.After(initialSyncDelay): result, err := r.Reconcile(ctx, ctrl.Request{}) if err != nil { r.Log.Error(err, "error synchronizing dashboards") diff --git a/controllers/datasource_controller.go b/controllers/datasource_controller.go index 951d27e5b..33b7ddfa4 100644 --- a/controllers/datasource_controller.go +++ b/controllers/datasource_controller.go @@ -390,17 +390,12 @@ func (r *GrafanaDatasourceReconciler) SetupWithManager(mgr ctrl.Manager, ctx con Complete(r) if err == nil { - d, err := time.ParseDuration(initialSyncDelay) - if err != nil { - return err - } - go func() { for { select { case <-ctx.Done(): return - case <-time.After(d): + case <-time.After(initialSyncDelay): result, err := r.Reconcile(ctx, ctrl.Request{}) if err != nil { r.Log.Error(err, "error synchronizing datasources") diff --git a/controllers/grafana_controller.go b/controllers/grafana_controller.go index 6c5ff25b3..f0f8e61cf 100644 --- a/controllers/grafana_controller.go +++ b/controllers/grafana_controller.go @@ -24,7 +24,6 @@ import ( "os" "reflect" "strings" - "time" "github.com/go-logr/logr" "github.com/grafana/grafana-operator/v5/controllers/config" @@ -45,10 +44,6 @@ import ( client2 "github.com/grafana/grafana-operator/v5/controllers/client" ) -const ( - RequeueDelay = 10 * time.Second -) - // GrafanaReconciler reconciles a Grafana object type GrafanaReconciler struct { client.Client diff --git a/controllers/grafanafolder_controller.go b/controllers/grafanafolder_controller.go index 643b23e4b..74255de9a 100644 --- a/controllers/grafanafolder_controller.go +++ b/controllers/grafanafolder_controller.go @@ -256,17 +256,12 @@ func (r *GrafanaFolderReconciler) SetupWithManager(mgr ctrl.Manager, ctx context Complete(r) if err == nil { - d, err := time.ParseDuration(initialSyncDelay) - if err != nil { - return err - } - go func() { for { select { case <-ctx.Done(): return - case <-time.After(d): + case <-time.After(initialSyncDelay): result, err := r.Reconcile(ctx, ctrl.Request{}) if err != nil { r.Log.Error(err, "error synchronizing folders")