Skip to content

Commit

Permalink
chore: Update returned results on errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Baarsgaard committed Dec 30, 2024
1 parent 995140f commit e9efc98
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions controllers/grafanafolder_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,19 @@ func (r *GrafanaFolderReconciler) syncFolders(ctx context.Context) (ctrl.Result,
var opts []client.ListOption
err := r.Client.List(ctx, grafanas, opts...)
if err != nil {
return ctrl.Result{
Requeue: true,
}, err
return ctrl.Result{}, err
}

// no instances, no need to sync
if len(grafanas.Items) == 0 {
return ctrl.Result{Requeue: false}, nil
return ctrl.Result{}, nil
}

// get all folders
allFolders := &grafanav1beta1.GrafanaFolderList{}
err = r.Client.List(ctx, allFolders, opts...)
if err != nil {
return ctrl.Result{
Requeue: true,
}, err
return ctrl.Result{}, err
}

// sync folders, delete folders from grafana that do no longer have a cr
Expand All @@ -100,15 +96,15 @@ func (r *GrafanaFolderReconciler) syncFolders(ctx context.Context) (ctrl.Result,
for grafana, existingFolders := range foldersToDelete {
grafanaClient, err := client2.NewGeneratedGrafanaClient(ctx, r.Client, grafana)
if err != nil {
return ctrl.Result{Requeue: true}, err
return ctrl.Result{}, err
}

for _, folder := range existingFolders {
// avoid bombarding the grafana instance with a large number of requests at once, limit
// the sync to a certain number of folders per cycle. This means that it will take longer to sync
// a large number of deleted dashboard crs, but that should be an edge case.
if foldersSynced >= syncBatchSize {
return ctrl.Result{Requeue: true}, nil
return ctrl.Result{}, nil
}

namespace, name, uid := folder.Split()
Expand All @@ -121,7 +117,7 @@ func (r *GrafanaFolderReconciler) syncFolders(ctx context.Context) (ctrl.Result,
if errors.As(err, &notFound) {
r.Log.Info("folder no longer exists", "namespace", namespace, "name", name)
} else {
return ctrl.Result{Requeue: false}, err
return ctrl.Result{}, err
}
}

Expand Down Expand Up @@ -171,7 +167,7 @@ func (r *GrafanaFolderReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}, folder)
if err != nil {
if kuberr.IsNotFound(err) {
return ctrl.Result{Requeue: false}, nil
return ctrl.Result{}, nil
}
return ctrl.Result{}, fmt.Errorf("error getting grafana folder cr: %w", err)
}
Expand Down

0 comments on commit e9efc98

Please sign in to comment.