@@ -26,7 +26,6 @@ import (
26
26
27
27
"github.com/go-logr/logr"
28
28
genapi "github.com/grafana/grafana-openapi-client-go/client"
29
- "github.com/grafana/grafana-openapi-client-go/client/dashboards"
30
29
"github.com/grafana/grafana-openapi-client-go/client/folders"
31
30
"github.com/grafana/grafana-openapi-client-go/models"
32
31
client2 "github.com/grafana/grafana-operator/v5/controllers/client"
@@ -92,14 +91,14 @@ func (r *GrafanaFolderReconciler) syncFolders(ctx context.Context) (ctrl.Result,
92
91
}
93
92
}
94
93
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 {
97
96
grafanaClient , err := client2 .NewGeneratedGrafanaClient (ctx , r .Client , grafana )
98
97
if err != nil {
99
98
return ctrl.Result {Requeue : true }, err
100
99
}
101
100
102
- for _ , folder := range folders {
101
+ for _ , folder := range existingFolders {
103
102
// avoid bombarding the grafana instance with a large number of requests at once, limit
104
103
// the sync to a certain number of folders per cycle. This means that it will take longer to sync
105
104
// 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,
108
107
}
109
108
110
109
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
112
113
if err != nil {
113
- var notFound * dashboards. DeleteDashboardByUIDNotFound
114
+ var notFound * folders. DeleteFolderNotFound
114
115
if errors .As (err , & notFound ) {
115
116
syncLog .Info ("folder no longer exists" , "namespace" , namespace , "name" , name )
116
117
} else {
@@ -269,7 +270,7 @@ func (r *GrafanaFolderReconciler) onFolderDeleted(ctx context.Context, namespace
269
270
_ , err = grafanaClient .Folders .DeleteFolder (params ) //nolint
270
271
if err != nil {
271
272
var notFound * folders.DeleteFolderNotFound
272
- if errors .As (err , & notFound ) {
273
+ if ! errors .As (err , & notFound ) {
273
274
return err
274
275
}
275
276
}
@@ -281,6 +282,7 @@ func (r *GrafanaFolderReconciler) onFolderDeleted(ctx context.Context, namespace
281
282
}
282
283
}
283
284
}
285
+
284
286
return nil
285
287
}
286
288
0 commit comments