Skip to content

Commit 53420b0

Browse files
committed
chore: Use identifier returned from Find
1 parent 761c95d commit 53420b0

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

controllers/alertrulegroup_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,9 @@ func (r *GrafanaAlertRuleGroupReconciler) finalize(ctx context.Context, group *g
309309
}
310310

311311
for _, instance := range instances {
312-
found, _ := instance.Status.AlertRuleGroups.Find(group.Namespace, group.Name)
312+
found, groupName := instance.Status.AlertRuleGroups.Find(group.Namespace, group.Name)
313313
if !found {
314-
log.Info("alertrulegroup not found on instance - skipping finalize", "grafana", instance.Name, "name", group.GroupName())
314+
log.Info("alertrulegroup not found on instance - skipping finalize", "grafana", instance.Name, "name", groupName)
315315
continue
316316
}
317317

@@ -322,7 +322,7 @@ func (r *GrafanaAlertRuleGroupReconciler) finalize(ctx context.Context, group *g
322322
return fmt.Errorf("building grafana client: %w", err)
323323
}
324324

325-
_, err = cl.Provisioning.DeleteAlertRuleGroup(group.GroupName(), folderUID) //nolint:errcheck
325+
_, err = cl.Provisioning.DeleteAlertRuleGroup(*groupName, folderUID) //nolint:errcheck
326326
if err != nil {
327327
var notFound *provisioning.DeleteAlertRuleGroupNotFound
328328
if !errors.As(err, &notFound) {

controllers/librarypanel_controller.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,13 @@ func (r *GrafanaLibraryPanelReconciler) finalize(ctx context.Context, libraryPan
239239
log := logf.FromContext(ctx)
240240
log.Info("Finalizing GrafanaLibraryPanel")
241241

242-
uid := content.CustomUIDOrUID(libraryPanel, libraryPanel.Status.UID)
243-
244242
instances, err := GetScopedMatchingInstances(ctx, r.Client, libraryPanel)
245243
if err != nil {
246244
return fmt.Errorf("fetching instances: %w", err)
247245
}
248246

249247
for _, instance := range instances {
250-
found, _ := instance.Status.LibraryPanels.Find(libraryPanel.Namespace, libraryPanel.Name)
248+
found, uid := instance.Status.LibraryPanels.Find(libraryPanel.Namespace, libraryPanel.Name)
251249
if !found {
252250
log.Info("librarypanel not found on instance - skipping finalize", "grafana", instance.Name, "uid", uid)
253251
continue
@@ -260,7 +258,7 @@ func (r *GrafanaLibraryPanelReconciler) finalize(ctx context.Context, libraryPan
260258

261259
isCleanupInGrafanaRequired := true
262260

263-
resp, err := grafanaClient.LibraryElements.GetLibraryElementConnections(uid)
261+
resp, err := grafanaClient.LibraryElements.GetLibraryElementConnections(*uid)
264262
if err != nil {
265263
var notFound *library_elements.GetLibraryElementConnectionsNotFound
266264
if !errors.As(err, &notFound) {
@@ -273,10 +271,10 @@ func (r *GrafanaLibraryPanelReconciler) finalize(ctx context.Context, libraryPan
273271
// Skip cleanup in instances
274272
if isCleanupInGrafanaRequired {
275273
if len(resp.Payload.Result) > 0 {
276-
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
274+
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
277275
}
278276

279-
_, err = grafanaClient.LibraryElements.DeleteLibraryElementByUID(uid) //nolint:errcheck
277+
_, err = grafanaClient.LibraryElements.DeleteLibraryElementByUID(*uid) //nolint:errcheck
280278
if err != nil {
281279
var notFound *library_elements.DeleteLibraryElementByUIDNotFound
282280
if !errors.As(err, &notFound) {

0 commit comments

Comments
 (0)