K8s/Dashboard: Set generation from version (#99142)

This commit is contained in:
Ryan McKinley 2025-01-17 14:52:01 +03:00 committed by GitHub
parent a0d1a197e3
commit 7c04247d6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 0 deletions

View File

@ -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)))

View File

@ -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

View File

@ -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