Skip to content

Commit

Permalink
chore: Refactor const usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Baarsgaard committed Jan 10, 2025
1 parent fbc0b9e commit e45f0eb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 27 deletions.
10 changes: 8 additions & 2 deletions controllers/controller_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -37,6 +40,9 @@ const (
// condition reasons
conditionApplySuccessful = "ApplySuccessful"
conditionApplyFailed = "ApplyFailed"

// Finalizer
grafanaFinalizer = "operator.grafana.com/finalizer"
)

//+kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,verbs=get;list;watch;create;update;patch;delete
Expand Down
9 changes: 1 addition & 8 deletions controllers/dashboard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ import (
)

const (
initialSyncDelay = "10s"
syncBatchSize = 100
conditionDashboardSynchronized = "DashboardSynchronized"
)

Expand Down Expand Up @@ -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")
Expand Down
7 changes: 1 addition & 6 deletions controllers/datasource_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 0 additions & 5 deletions controllers/grafana_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"os"
"reflect"
"strings"
"time"

"github.com/go-logr/logr"
"github.com/grafana/grafana-operator/v5/controllers/config"
Expand All @@ -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
Expand Down
7 changes: 1 addition & 6 deletions controllers/grafanafolder_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit e45f0eb

Please sign in to comment.