[release-12.0.0] Dashboard and Folders: fix version mismatch (#104713)

Folders: Fix version mismatch errors
This commit is contained in:
Stephanie Hingtgen
2025-04-29 22:07:14 +03:00
committed by GitHub
parent bc68bfbfe4
commit 4dbdac31dc
5 changed files with 11 additions and 10 deletions
-10
View File
@@ -352,16 +352,6 @@ func (b *DashboardsAPIBuilder) validateUpdate(ctx context.Context, a admission.A
return apierrors.NewBadRequest(err.Error())
}
allowOverwrite := false // TODO: Add support for overwrite flag
// check for is someone else has written in between
if newAccessor.GetGeneration() != oldAccessor.GetGeneration() {
if allowOverwrite {
newAccessor.SetGeneration(oldAccessor.GetGeneration())
} else {
return apierrors.NewBadRequest(dashboards.ErrDashboardVersionMismatch.Error())
}
}
return nil
}
+2
View File
@@ -22,6 +22,7 @@ func LegacyCreateCommandToUnstructured(cmd *folder.CreateFolderCommand) (*unstru
"spec": map[string]any{
"title": cmd.Title,
"description": cmd.Description,
"version": 1,
},
},
}
@@ -52,6 +53,7 @@ func convertToK8sResource(v *folder.Folder, namespacer request.NamespaceMapper)
ResourceVersion: fmt.Sprintf("%d", v.Updated.UnixMilli()),
CreationTimestamp: metav1.NewTime(v.Created),
Namespace: namespacer(v.OrgID),
Generation: int64(v.Version),
},
Spec: folders.FolderSpec{
Title: v.Title,
@@ -88,6 +88,7 @@ func (ss *FolderUnifiedStoreImpl) UnstructuredToLegacyFolder(ctx context.Context
updaterId = creatorId
}
folder.Version = int(item.GetGeneration())
folder.CreatedBy = creatorId
folder.UpdatedBy = updaterId
@@ -124,6 +125,7 @@ func (ss *FolderUnifiedStoreImpl) UnstructuredToLegacyFolderList(ctx context.Con
updaterId = creatorId
}
folder.Version = int(item.GetGeneration())
folder.CreatedBy = creatorId
folder.UpdatedBy = updaterId
folders = append(folders, folder)
@@ -591,6 +591,8 @@ func (s *Service) updateOnApiServer(ctx context.Context, cmd *folder.UpdateFolde
NewTitle: cmd.NewTitle,
NewDescription: cmd.NewDescription,
SignedInUser: user,
Overwrite: cmd.Overwrite,
Version: cmd.Version,
})
if err != nil {
@@ -104,6 +104,11 @@ func (ss *FolderUnifiedStoreImpl) Update(ctx context.Context, cmd folder.UpdateF
return nil, err
}
meta.SetFolder(*cmd.NewParentUID)
} else {
// only compare versions if not moving the folder
if !cmd.Overwrite && (cmd.Version != int(obj.GetGeneration())) {
return nil, dashboards.ErrDashboardVersionMismatch
}
}
out, err := ss.k8sclient.Update(ctx, updated, cmd.OrgID, v1.UpdateOptions{