Skip to content

Commit

Permalink
refactor: move uid reassignment to existing conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
theSuess committed Jul 4, 2024
1 parent 9855012 commit 3695416
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions controllers/grafanafolder_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ func (r *GrafanaFolderReconciler) onFolderCreated(ctx context.Context, grafana *
}

if exists {
// make sure we use the correct UID
uid = remoteUID
// Add to status to cover cases:
// - operator have previously failed to update status
// - the folder was created outside of operator
Expand Down Expand Up @@ -389,12 +391,7 @@ func (r *GrafanaFolderReconciler) onFolderCreated(ctx context.Context, grafana *
return fmt.Errorf("failed to unmarshal spec.permissions: %w", err)
}

targetUID := uid
if exists {
targetUID = remoteUID
}

_, err = grafanaClient.FolderPermissions.UpdateFolderPermissions(targetUID, &permissions) //nolint
_, err = grafanaClient.FolderPermissions.UpdateFolderPermissions(uid, &permissions) //nolint
if err != nil {
return fmt.Errorf("failed to update folder permissions: %w", err)
}
Expand Down

0 comments on commit 3695416

Please sign in to comment.