Schema V2: Replace resourceVersion usage with generation (#100080)

* Schema V2: Replace resourceVersion usage with generation

* revert auto generated files

---------

Co-authored-by: Ivan Ortega <ivanortegaalba@gmail.com>
Co-authored-by: Haris Rozajac <haris.rozajac12@gmail.com>
This commit is contained in:
Dominik Prokop
2025-03-26 12:47:24 -06:00
committed by GitHub
co-authored by Ivan Ortega Haris Rozajac
parent 88d23fe5be
commit 3d1497b56a
11 changed files with 12 additions and 18 deletions
@@ -294,8 +294,6 @@ var _ resource.ListObject = &DashboardList{}
// Copy methods for all subresource types
// DeepCopy creates a full deep copy of DashboardStatus
func (s *DashboardStatus) DeepCopy() *DashboardStatus {
cpy := &DashboardStatus{}
@@ -294,8 +294,6 @@ var _ resource.ListObject = &DashboardList{}
// Copy methods for all subresource types
// DeepCopy creates a full deep copy of DashboardStatus
func (s *DashboardStatus) DeepCopy() *DashboardStatus {
cpy := &DashboardStatus{}
@@ -11,8 +11,6 @@ import (
"github.com/grafana/grafana-app-sdk/app"
)
var ()
var appManifestData = app.ManifestData{
AppName: "dashboard",
Group: "dashboard.grafana.app",
@@ -548,6 +548,7 @@ describe('DashboardScenePageStateManager v2', () => {
metadata: {
name: 'fake-dash',
creationTimestamp: '',
generation: 1,
resourceVersion: '1',
},
spec: { ...defaultDashboardV2Spec() },
@@ -581,6 +582,7 @@ describe('DashboardScenePageStateManager v2', () => {
metadata: {
name: 'fake-dash',
creationTimestamp: '',
generation: 2,
resourceVersion: '2',
},
spec: { ...defaultDashboardV2Spec() },
@@ -457,12 +457,7 @@ export class DashboardScenePageStateManagerV2 extends DashboardScenePageStateMan
): DashboardScene | null {
const fromCache = this.getSceneFromCache(options.uid);
// TODO[schema v2]: Dashboard scene state is incorrectly save, it must use the resourceVersion
if (
fromCache &&
rsp?.metadata.resourceVersion &&
fromCache.state.version === parseInt(rsp?.metadata.resourceVersion, 10)
) {
if (fromCache && fromCache.state.version === rsp?.metadata.generation) {
return fromCache;
}
@@ -58,6 +58,7 @@ export const defaultDashboard: DashboardWithAccessInfo<DashboardV2Spec> = {
name: 'dashboard-uid',
namespace: 'default',
labels: {},
generation: 123,
resourceVersion: '123',
creationTimestamp: 'creationTs',
annotations: {
@@ -131,7 +131,7 @@ export function transformSaveModelSchemaV2ToScene(dto: DashboardWithAccessInfo<D
showSettings: Boolean(dto.access.canEdit),
canMakeEditable: canSave && !isDashboardEditable,
hasUnsavedFolderChange: false,
version: parseInt(metadata.resourceVersion, 10),
version: metadata.generation,
k8s: metadata,
};
@@ -160,7 +160,7 @@ export function transformSaveModelSchemaV2ToScene(dto: DashboardWithAccessInfo<D
tags: dashboard.tags,
title: dashboard.title,
uid: metadata.name,
version: parseInt(metadata.resourceVersion, 10),
version: metadata.generation,
body: layoutManager,
$timeRange: new SceneTimeRange({
from: dashboard.timeSettings.from,
@@ -204,7 +204,7 @@ export function ensureV1Response(
isFolder: false,
uid: dashboard.metadata.name,
k8s: dashboard.metadata,
version: parseInt(dashboard.metadata.resourceVersion, 10),
version: dashboard.metadata.generation,
},
dashboard: spec,
};
@@ -256,7 +256,7 @@ export function ensureV1Response(
},
fiscalYearStartMonth: spec.timeSettings.fiscalYearStartMonth,
weekStart: spec.timeSettings.weekStart,
version: parseInt(dashboard.metadata.resourceVersion, 10),
version: dashboard.metadata.generation,
links: spec.links,
annotations: { list: annotations },
panels,
+1 -1
View File
@@ -108,7 +108,7 @@ export class K8sDashboardAPI implements DashboardAPI<DashboardDTO, Dashboard> {
isFolder: false,
uid: dash.metadata.name,
k8s: dash.metadata,
version: parseInt(dash.metadata.resourceVersion, 10),
version: dash.metadata.generation,
},
dashboard: dash.spec,
};
@@ -17,6 +17,7 @@ const mockDashboardDto: DashboardWithAccessInfo<DashboardV2Spec> = {
metadata: {
name: 'dash-uid',
generation: 1,
resourceVersion: '1',
creationTimestamp: '1',
annotations: {},
@@ -36,6 +37,7 @@ const mockPut = jest.fn().mockImplementation((url, data) => {
kind: 'Dashboard',
metadata: {
name: data.metadata?.name,
generation: 2,
resourceVersion: '2',
creationTimestamp: new Date().toISOString(),
labels: data.metadata?.labels,
+1 -1
View File
@@ -149,7 +149,7 @@ export class K8sDashboardV2API
return {
uid: v.metadata.name,
version: parseInt(v.metadata.resourceVersion, 10) ?? 0,
version: v.metadata.generation ?? 0,
id: dashId,
status: 'success',
url,