@@ -235,39 +235,39 @@ func (r *GrafanaLibraryPanelReconciler) reconcileWithInstance(ctx context.Contex
235
235
return instance .AddNamespacedResource (ctx , r .Client , cr , cr .NamespacedResource (uid ))
236
236
}
237
237
238
- func (r * GrafanaLibraryPanelReconciler ) finalize (ctx context.Context , libraryPanel * v1beta1.GrafanaLibraryPanel ) error {
238
+ func (r * GrafanaLibraryPanelReconciler ) finalize (ctx context.Context , cr * v1beta1.GrafanaLibraryPanel ) error {
239
239
log := logf .FromContext (ctx )
240
240
log .Info ("Finalizing GrafanaLibraryPanel" )
241
241
242
- uid := content .CustomUIDOrUID (libraryPanel , libraryPanel .Status .UID )
242
+ uid := content .CustomUIDOrUID (cr , cr .Status .UID )
243
243
244
- instances , err := GetScopedMatchingInstances (ctx , r .Client , libraryPanel )
244
+ instances , err := GetScopedMatchingInstances (ctx , r .Client , cr )
245
245
if err != nil {
246
246
return fmt .Errorf ("fetching instances: %w" , err )
247
247
}
248
248
249
- for _ , instance := range instances {
250
- grafanaClient , err := client2 .NewGeneratedGrafanaClient (ctx , r .Client , & instance )
249
+ for _ , grafana := range instances {
250
+ grafanaClient , err := client2 .NewGeneratedGrafanaClient (ctx , r .Client , & grafana )
251
251
if err != nil {
252
252
return err
253
253
}
254
254
255
255
isCleanupInGrafanaRequired := true
256
256
257
- resp , err := grafanaClient .LibraryElements .GetLibraryElementConnections (uid )
257
+ resp , err := grafanaClient .LibraryElements .GetLibraryElementByUID (uid )
258
258
if err != nil {
259
- var notFound * library_elements.GetLibraryElementConnectionsNotFound
259
+ var notFound * library_elements.GetLibraryElementByUIDNotFound
260
260
if ! errors .As (err , & notFound ) {
261
- return fmt .Errorf ("fetching library panel from instance %s/%s: %w" , instance .Namespace , instance .Name , err )
261
+ return fmt .Errorf ("fetching library panel from instance %s/%s: %w" , grafana .Namespace , grafana .Name , err )
262
262
}
263
263
264
264
isCleanupInGrafanaRequired = false
265
265
}
266
266
267
267
// Skip cleanup in instances
268
268
if isCleanupInGrafanaRequired {
269
- if len ( resp .Payload .Result ) > 0 {
270
- return fmt .Errorf ("library panel %s/%s/%s on instance %s/%s has existing connections" , libraryPanel .Namespace , libraryPanel .Name , uid , instance .Namespace , instance .Name ) //nolint
269
+ if resp .Payload .Result . Meta . ConnectedDashboards > 0 {
270
+ return fmt .Errorf ("library panel %s/%s/%s on instance %s/%s has existing connections" , cr .Namespace , cr .Name , uid , grafana .Namespace , grafana .Name ) //nolint
271
271
}
272
272
273
273
_ , err = grafanaClient .LibraryElements .DeleteLibraryElementByUID (uid ) //nolint:errcheck
@@ -279,8 +279,15 @@ func (r *GrafanaLibraryPanelReconciler) finalize(ctx context.Context, libraryPan
279
279
}
280
280
}
281
281
282
+ if grafana .IsInternal () {
283
+ err = ReconcilePlugins (ctx , r .Client , r .Scheme , & grafana , nil , cr .GetPluginConfigMapKey (), cr .GetPluginConfigMapDeprecatedKey ())
284
+ if err != nil {
285
+ return fmt .Errorf ("reconciling plugins: %w" , err )
286
+ }
287
+ }
288
+
282
289
// Update grafana instance Status
283
- err = instance .RemoveNamespacedResource (ctx , r .Client , libraryPanel )
290
+ err = grafana .RemoveNamespacedResource (ctx , r .Client , cr )
284
291
if err != nil {
285
292
return fmt .Errorf ("removing Folder from Grafana cr: %w" , err )
286
293
}
0 commit comments