From a95de85062be4b8c16bae952d66aaa3dd5d32d6f Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Mon, 8 Dec 2025 11:07:16 +0300 Subject: [PATCH] merge main --- pkg/storage/unified/resource/document.go | 9 +++++++++ pkg/storage/unified/resource/document_test.go | 4 ++++ .../unified/resource/testdata/playlist-resource.json | 11 ++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/pkg/storage/unified/resource/document.go b/pkg/storage/unified/resource/document.go index 4e528b96df0..adc7d14a718 100644 --- a/pkg/storage/unified/resource/document.go +++ b/pkg/storage/unified/resource/document.go @@ -101,6 +101,11 @@ type IndexableDocument struct { // metadata, annotations, or external data linked at index time Fields map[string]any `json:"fields,omitempty"` + // The list of owner references, + // each value is of the form {group}/{kind}/{name} + // ex: iam.grafana.app/Team/abc-engineering + OwnerReferences []string `json:"ownerReferences,omitempty"` + // Maintain a list of resource references. // Someday this will likely be part of https://github.com/grafana/gamma References ResourceReferences `json:"references,omitempty"` @@ -217,6 +222,10 @@ func NewIndexableDocument(key *resourcepb.ResourceKey, rv int64, obj utils.Grafa if err != nil && tt != nil { doc.Updated = tt.UnixMilli() } + for _, owner := range obj.GetOwnerReferences() { + gv, _ := schema.ParseGroupVersion(owner.APIVersion) + doc.OwnerReferences = append(doc.OwnerReferences, fmt.Sprintf("%s/%s/%s", gv.Group, owner.Kind, owner.Name)) + } return doc.UpdateCopyFields() } diff --git a/pkg/storage/unified/resource/document_test.go b/pkg/storage/unified/resource/document_test.go index f6bf17531d8..39a71af1cb7 100644 --- a/pkg/storage/unified/resource/document_test.go +++ b/pkg/storage/unified/resource/document_test.go @@ -48,6 +48,10 @@ func TestStandardDocumentBuilder(t *testing.T) { "id": "something" }, "managedBy": "repo:something", + "ownerReferences": [ + "iam.grafana.app/Team/engineering", + "iam.grafana.app/User/test" + ], "source": { "path": "path/in/system.json", "checksum": "xyz" diff --git a/pkg/storage/unified/resource/testdata/playlist-resource.json b/pkg/storage/unified/resource/testdata/playlist-resource.json index c1d4081d9c3..dc25b31ed63 100644 --- a/pkg/storage/unified/resource/testdata/playlist-resource.json +++ b/pkg/storage/unified/resource/testdata/playlist-resource.json @@ -13,7 +13,16 @@ "grafana.app/repoPath": "path/in/system.json", "grafana.app/repoHash": "xyz", "grafana.app/updatedTimestamp": "2024-07-01T10:11:12Z" - } + }, + "ownerReferences": [{ + "apiVersion": "iam.grafana.app/v1alpha1", + "kind": "Team", + "name": "engineering" + }, { + "apiVersion": "iam.grafana.app/v1alpha1", + "kind": "User", + "name": "test" + }] }, "spec": { "title": "Test Playlist from Unified Storage",