diff --git a/pkg/registry/apis/dashboard/legacy/sql_dashboards.go b/pkg/registry/apis/dashboard/legacy/sql_dashboards.go index ec751cbecf0..320dea78209 100644 --- a/pkg/registry/apis/dashboard/legacy/sql_dashboards.go +++ b/pkg/registry/apis/dashboard/legacy/sql_dashboards.go @@ -263,6 +263,7 @@ func (a *dashboardSqlAccess) scanRow(rows *sql.Rows) (*dashboardRow, error) { meta.SetCreatedBy(getUserID(createdBy, createdByID)) meta.SetUpdatedBy(getUserID(updatedBy, updatedByID)) meta.SetDeprecatedInternalID(dashboard_id) //nolint:staticcheck + meta.SetGeneration(version) if deleted.Valid { meta.SetDeletionTimestamp(ptr.To(metav1.NewTime(deleted.Time))) diff --git a/pkg/tests/apis/dashboard/dashboards_test.go b/pkg/tests/apis/dashboard/dashboards_test.go index 2d1a5855ce8..4232fd478ba 100644 --- a/pkg/tests/apis/dashboard/dashboards_test.go +++ b/pkg/tests/apis/dashboard/dashboards_test.go @@ -10,6 +10,7 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" + "github.com/grafana/grafana/pkg/apimachinery/utils" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/tests/apis" "github.com/grafana/grafana/pkg/tests/testinfra" @@ -60,6 +61,12 @@ func runDashboardTest(t *testing.T, helper *apis.K8sTestHelper) { obj, err = client.Resource.Get(ctx, created, metav1.GetOptions{}) require.NoError(t, err) require.Equal(t, created, obj.GetName()) + require.Equal(t, int64(1), obj.GetGeneration()) + + wrap, err := utils.MetaAccessor(obj) + require.NoError(t, err) + require.Empty(t, wrap.GetRepositoryName()) // no SQL repo stub + require.Equal(t, helper.Org1.Admin.Identity.GetUID(), wrap.GetCreatedBy()) // Commented out because the dynamic client does not like lists as sub-resource // // Check that it now appears in the history diff --git a/public/app/features/apiserver/types.ts b/public/app/features/apiserver/types.ts index c6d142f4019..1df68585beb 100644 --- a/public/app/features/apiserver/types.ts +++ b/public/app/features/apiserver/types.ts @@ -23,6 +23,8 @@ export interface ObjectMeta { namespace?: string; // Resource version will increase (not sequentially!) with any change to the saved value resourceVersion: string; + // Incremented by the server when the value of spec changes + generation?: number; // The first time this was saved creationTimestamp: string; // General resource annotations -- including the common grafana.app values