Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore(internal): Refactor const usage and unready info message #1810

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 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 Expand Up @@ -114,7 +120,7 @@ func GetScopedMatchingInstances(log logr.Logger, ctx context.Context, k8sClient
selectedList = append(selectedList, instance)
}
if len(unready_instances) > 0 {
log.Info("Grafana instances not ready", "instances", unready_instances)
log.Info("Grafana instances not ready, excluded from matching", "instances", unready_instances)
}

return selectedList, nil
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
Loading