Skip to content

Commit 3e81660

Browse files
authored
Merge pull request #1516 from grafana/fix/folder-sync
fix(GrafanaFolder): proper status updates for removed CRs, don't fail on missing folder in onFolderDeleted events
2 parents 27aafa8 + 858f4f5 commit 3e81660

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

controllers/grafanafolder_controller.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626

2727
"github.com/go-logr/logr"
2828
genapi "github.com/grafana/grafana-openapi-client-go/client"
29-
"github.com/grafana/grafana-openapi-client-go/client/dashboards"
3029
"github.com/grafana/grafana-openapi-client-go/client/folders"
3130
"github.com/grafana/grafana-openapi-client-go/models"
3231
client2 "github.com/grafana/grafana-operator/v5/controllers/client"
@@ -92,14 +91,14 @@ func (r *GrafanaFolderReconciler) syncFolders(ctx context.Context) (ctrl.Result,
9291
}
9392
}
9493

95-
// delete all dashboards that no longer have a cr
96-
for grafana, folders := range foldersToDelete {
94+
// delete all folders that no longer have a cr
95+
for grafana, existingFolders := range foldersToDelete {
9796
grafanaClient, err := client2.NewGeneratedGrafanaClient(ctx, r.Client, grafana)
9897
if err != nil {
9998
return ctrl.Result{Requeue: true}, err
10099
}
101100

102-
for _, folder := range folders {
101+
for _, folder := range existingFolders {
103102
// avoid bombarding the grafana instance with a large number of requests at once, limit
104103
// the sync to a certain number of folders per cycle. This means that it will take longer to sync
105104
// a large number of deleted dashboard crs, but that should be an edge case.
@@ -108,9 +107,11 @@ func (r *GrafanaFolderReconciler) syncFolders(ctx context.Context) (ctrl.Result,
108107
}
109108

110109
namespace, name, uid := folder.Split()
111-
_, err = grafanaClient.Dashboards.DeleteDashboardByUID(uid) //nolint
110+
111+
params := folders.NewDeleteFolderParams().WithFolderUID(uid)
112+
_, err = grafanaClient.Folders.DeleteFolder(params) //nolint
112113
if err != nil {
113-
var notFound *dashboards.DeleteDashboardByUIDNotFound
114+
var notFound *folders.DeleteFolderNotFound
114115
if errors.As(err, &notFound) {
115116
syncLog.Info("folder no longer exists", "namespace", namespace, "name", name)
116117
} else {
@@ -269,7 +270,7 @@ func (r *GrafanaFolderReconciler) onFolderDeleted(ctx context.Context, namespace
269270
_, err = grafanaClient.Folders.DeleteFolder(params) //nolint
270271
if err != nil {
271272
var notFound *folders.DeleteFolderNotFound
272-
if errors.As(err, &notFound) {
273+
if !errors.As(err, &notFound) {
273274
return err
274275
}
275276
}
@@ -281,6 +282,7 @@ func (r *GrafanaFolderReconciler) onFolderDeleted(ctx context.Context, namespace
281282
}
282283
}
283284
}
285+
284286
return nil
285287
}
286288

0 commit comments

Comments
 (0)