fix: use folder UID instead of name for tree keying

- Change AddUnstructured to use item.GetUID() instead of item.GetName()
- This fixes the mismatch where GetFolder() returns UID but tree was keyed by name
- Folders in Grafana are identified by UID, so tree should be keyed by UID
This commit is contained in:
Roberto Jimenez Sanchez
2025-12-03 08:19:58 +01:00
parent 7d6f718a34
commit 5dacd2edff
2 changed files with 10 additions and 2 deletions
@@ -356,7 +356,12 @@ func computeExportPath(basePath string, meta utils.GrafanaMetaAccessor, tree res
if resourceFolder != "" {
// Get the folder path from the unmanaged tree (rootFolder is empty string for unmanaged tree)
fid, ok := tree.DirPath(resourceFolder, "")
if ok && fid.Path != "" {
if !ok {
// Folder not found in tree - this shouldn't happen for unmanaged folders
// but if it does, we'll just use the base path
return exportPath
}
if fid.Path != "" {
if exportPath != "" {
exportPath = safepath.Join(exportPath, fid.Path)
} else {
@@ -145,9 +145,12 @@ func (t *folderTree) AddUnstructured(item *unstructured.Unstructured) error {
return fmt.Errorf("extract meta accessor: %w", err)
}
// Use UID as the identifier since GetFolder() returns UID
// In Grafana's folder API, folders are identified by UID
folderUID := string(item.GetUID())
folder := Folder{
Title: meta.FindTitle(item.GetName()),
ID: item.GetName(),
ID: folderUID,
}
t.mu.Lock()
defer t.mu.Unlock()