mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
K8s: use deprecatedInternalID label rather than SQL annotation (#99263)
This commit is contained in:
parent
9ce9ad1777
commit
d8b6ded101
@ -532,10 +532,7 @@ func (a *dashboardSqlAccess) GetLibraryPanels(ctx context.Context, query Library
|
||||
meta.SetCreatedBy(p.CreatedBy)
|
||||
meta.SetUpdatedBy(p.UpdatedBy)
|
||||
meta.SetUpdatedTimestamp(&p.Updated)
|
||||
meta.SetRepositoryInfo(&utils.ResourceRepositoryInfo{
|
||||
Name: "SQL",
|
||||
Path: strconv.FormatInt(p.ID, 10),
|
||||
})
|
||||
meta.SetDeprecatedInternalID(p.ID) // nolint:staticcheck
|
||||
|
||||
res.Items = append(res.Items, item)
|
||||
if len(res.Items) > limit {
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
@ -120,16 +119,14 @@ func (r *DTOConnector) Connect(ctx context.Context, name string, opts runtime.Ob
|
||||
dto := &dashboards.Dashboard{
|
||||
UID: name,
|
||||
OrgID: info.OrgID,
|
||||
ID: obj.GetDeprecatedInternalID(), // nolint:staticcheck
|
||||
}
|
||||
repo, err := obj.GetRepositoryInfo()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if repo != nil && repo.Name == "SQL" {
|
||||
dto.ID, err = strconv.ParseInt(repo.Path, 10, 64)
|
||||
if err == nil {
|
||||
return nil, err
|
||||
}
|
||||
if repo != nil && repo.Name == "plugin" {
|
||||
dto.PluginID = repo.Path
|
||||
}
|
||||
|
||||
guardian, err := guardian.NewByDashboard(ctx, dto, info.OrgID, user)
|
||||
|
@ -158,12 +158,6 @@ func convertToK8sResource(v *folder.Folder, namespacer request.NamespaceMapper)
|
||||
meta.SetUpdatedTimestamp(&v.Updated)
|
||||
if v.ID > 0 { // nolint:staticcheck
|
||||
meta.SetDeprecatedInternalID(v.ID) // nolint:staticcheck
|
||||
|
||||
meta.SetRepositoryInfo(&utils.ResourceRepositoryInfo{
|
||||
Name: "SQL",
|
||||
Path: fmt.Sprintf("%d", v.ID), // nolint:staticcheck
|
||||
Timestamp: &v.Created,
|
||||
})
|
||||
}
|
||||
// #TODO: turns out these get overwritten by Unified Storage (see pkg/storage/unified/apistore/prepare.go)
|
||||
// We're going to have to align with that. For now we do need the user ID because the folder type stores it
|
||||
|
@ -3,7 +3,6 @@ package serviceaccount
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@ -109,10 +108,7 @@ func toSAItem(sa legacy.ServiceAccount, ns string) iamv0.ServiceAccount {
|
||||
}
|
||||
obj, _ := utils.MetaAccessor(&item)
|
||||
obj.SetUpdatedTimestamp(&sa.Updated)
|
||||
obj.SetRepositoryInfo(&utils.ResourceRepositoryInfo{
|
||||
Name: "SQL",
|
||||
Path: strconv.FormatInt(sa.ID, 10),
|
||||
})
|
||||
obj.SetDeprecatedInternalID(sa.ID) // nolint:staticcheck
|
||||
return item
|
||||
}
|
||||
|
||||
|
@ -135,10 +135,7 @@ func toTeamObject(t team.Team, ns claims.NamespaceInfo) iamv0.Team {
|
||||
}
|
||||
meta, _ := utils.MetaAccessor(&obj)
|
||||
meta.SetUpdatedTimestamp(&t.Updated)
|
||||
meta.SetRepositoryInfo(&utils.ResourceRepositoryInfo{
|
||||
Name: "SQL",
|
||||
Path: strconv.FormatInt(t.ID, 10),
|
||||
})
|
||||
meta.SetDeprecatedInternalID(t.ID) // nolint:staticcheck
|
||||
|
||||
return obj
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package user
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@ -136,9 +135,6 @@ func toUserItem(u *user.User, ns string) iamv0.User {
|
||||
}
|
||||
obj, _ := utils.MetaAccessor(item)
|
||||
obj.SetUpdatedTimestamp(&u.Updated)
|
||||
obj.SetRepositoryInfo(&utils.ResourceRepositoryInfo{
|
||||
Name: "SQL",
|
||||
Path: strconv.FormatInt(u.ID, 10),
|
||||
})
|
||||
obj.SetDeprecatedInternalID(u.ID) // nolint:staticcheck
|
||||
return *item
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package playlist
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@ -96,12 +95,7 @@ func convertToK8sResource(v *playlistsvc.PlaylistDTO, namespacer request.Namespa
|
||||
if err == nil {
|
||||
meta.SetUpdatedTimestampMillis(v.UpdatedAt)
|
||||
if v.Id > 0 {
|
||||
createdAt := time.UnixMilli(v.CreatedAt)
|
||||
meta.SetRepositoryInfo(&utils.ResourceRepositoryInfo{
|
||||
Name: "SQL",
|
||||
Path: fmt.Sprintf("%d", v.Id),
|
||||
Timestamp: &createdAt,
|
||||
})
|
||||
meta.SetDeprecatedInternalID(v.Id) // nolint:staticcheck
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,12 +129,5 @@ func getLegacyID(item *unstructured.Unstructured) int64 {
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
info, _ := meta.GetRepositoryInfo()
|
||||
if info != nil && info.Name == "SQL" {
|
||||
i, err := strconv.ParseInt(info.Path, 10, 64)
|
||||
if err == nil {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return 0
|
||||
return meta.GetDeprecatedInternalID() // nolint:staticcheck
|
||||
}
|
||||
|
@ -36,36 +36,36 @@ func TestPlaylistConversion(t *testing.T) {
|
||||
// fmt.Printf("%s", string(out))
|
||||
require.JSONEq(t, `{
|
||||
"metadata": {
|
||||
"name": "abc",
|
||||
"namespace": "org-3",
|
||||
"uid": "f0zxjm7ApxOafsn6DLQZ4Ezp78WRUsZqSc4taOSHq1gX",
|
||||
"resourceVersion": "54321",
|
||||
"creationTimestamp": "1970-01-01T00:00:12Z",
|
||||
"annotations": {
|
||||
"grafana.app/repoPath": "123",
|
||||
"grafana.app/repoName": "SQL",
|
||||
"grafana.app/repoTimestamp":"1970-01-01T00:00:12Z",
|
||||
"grafana.app/updatedTimestamp": "1970-01-01T00:00:54Z"
|
||||
}
|
||||
"name": "abc",
|
||||
"namespace": "org-3",
|
||||
"uid": "f0zxjm7ApxOafsn6DLQZ4Ezp78WRUsZqSc4taOSHq1gX",
|
||||
"resourceVersion": "54321",
|
||||
"creationTimestamp": "1970-01-01T00:00:12Z",
|
||||
"labels": {
|
||||
"grafana.app/deprecatedInternalID": "123"
|
||||
},
|
||||
"annotations": {
|
||||
"grafana.app/updatedTimestamp": "1970-01-01T00:00:54Z"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"title": "MyPlaylists",
|
||||
"interval": "10s",
|
||||
"items": [
|
||||
{
|
||||
"type": "dashboard_by_uid",
|
||||
"value": "UID0"
|
||||
},
|
||||
{
|
||||
"type": "dashboard_by_tag",
|
||||
"value": "tagA"
|
||||
},
|
||||
{
|
||||
"type": "dashboard_by_id",
|
||||
"value": "123"
|
||||
}
|
||||
]
|
||||
"title": "MyPlaylists",
|
||||
"interval": "10s",
|
||||
"items": [
|
||||
{
|
||||
"type": "dashboard_by_uid",
|
||||
"value": "UID0"
|
||||
},
|
||||
{
|
||||
"type": "dashboard_by_tag",
|
||||
"value": "tagA"
|
||||
},
|
||||
{
|
||||
"type": "dashboard_by_id",
|
||||
"value": "123"
|
||||
}
|
||||
]
|
||||
},
|
||||
"status": {}
|
||||
}`, string(out))
|
||||
}`, string(out))
|
||||
}
|
||||
|
@ -41,8 +41,8 @@ func TestStandardDocumentBuilder(t *testing.T) {
|
||||
"updatedBy": "user:XYZ",
|
||||
"name": "test1",
|
||||
"repo": {
|
||||
"name": "SQL",
|
||||
"path": "15",
|
||||
"name": "something",
|
||||
"path": "path/in/system.json",
|
||||
"hash": "xyz"
|
||||
}
|
||||
}`, string(jj))
|
||||
|
@ -9,8 +9,8 @@
|
||||
"annotations": {
|
||||
"grafana.app/createdBy": "user:ABC",
|
||||
"grafana.app/updatedBy": "user:XYZ",
|
||||
"grafana.app/repoName": "SQL",
|
||||
"grafana.app/repoPath": "15",
|
||||
"grafana.app/repoName": "something",
|
||||
"grafana.app/repoPath": "path/in/system.json",
|
||||
"grafana.app/repoHash": "xyz",
|
||||
"grafana.app/updatedTimestamp": "2024-07-01T10:11:12Z"
|
||||
}
|
||||
|
@ -9,9 +9,9 @@
|
||||
"rv": 1234,
|
||||
"title": "Test AAA",
|
||||
"title_sort": "test aaa",
|
||||
"labels": {
|
||||
"grafana.app/deprecatedInternalID": "123"
|
||||
},
|
||||
"created": 1706690655000,
|
||||
"createdBy": "user:abc",
|
||||
"repo": {
|
||||
"name": "SQL"
|
||||
}
|
||||
"createdBy": "user:abc"
|
||||
}
|
@ -8,8 +8,10 @@
|
||||
"resourceVersion": "1706690655000",
|
||||
"creationTimestamp": "2024-01-31T08:44:15Z",
|
||||
"annotations": {
|
||||
"grafana.app/createdBy": "user:abc",
|
||||
"grafana.app/originName": "SQL"
|
||||
"grafana.app/createdBy": "user:abc"
|
||||
},
|
||||
"labels": {
|
||||
"grafana.app/deprecatedInternalID": "123"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
|
@ -223,6 +223,11 @@ func (c *K8sResourceClient) sanitizeObject(v *unstructured.Unstructured, replace
|
||||
|
||||
replaceMeta = append(replaceMeta, "creationTimestamp", "resourceVersion", "uid")
|
||||
for _, key := range replaceMeta {
|
||||
if key == "labels" {
|
||||
delete(meta, key)
|
||||
continue
|
||||
}
|
||||
|
||||
old, ok := meta[key]
|
||||
if ok {
|
||||
require.NotEmpty(c.t, old)
|
||||
|
@ -4,13 +4,14 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/tests/apis"
|
||||
"github.com/grafana/grafana/pkg/tests/testinfra"
|
||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||
"github.com/stretchr/testify/require"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
var gvrTeams = schema.GroupVersionResource{
|
||||
@ -51,7 +52,7 @@ func TestIntegrationIdentity(t *testing.T) {
|
||||
})
|
||||
rsp, err := teamClient.Resource.List(ctx, metav1.ListOptions{})
|
||||
require.NoError(t, err)
|
||||
found := teamClient.SanitizeJSONList(rsp, "name")
|
||||
found := teamClient.SanitizeJSONList(rsp, "name", "labels")
|
||||
require.JSONEq(t, `{
|
||||
"items": [
|
||||
{
|
||||
|
@ -523,17 +523,17 @@ func doPlaylistTests(t *testing.T, helper *apis.K8sTestHelper) *apis.K8sTestHelp
|
||||
k8sList, err := client.Resource.List(context.Background(), metav1.ListOptions{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(k8sList.Items))
|
||||
require.JSONEq(t, expectedResult, client.SanitizeJSON(&k8sList.Items[0]))
|
||||
require.JSONEq(t, expectedResult, client.SanitizeJSON(&k8sList.Items[0], "labels"))
|
||||
|
||||
// Get should return the same result
|
||||
found, err := client.Resource.Get(context.Background(), uid, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
require.JSONEq(t, expectedResult, client.SanitizeJSON(found))
|
||||
require.JSONEq(t, expectedResult, client.SanitizeJSON(found, "labels"))
|
||||
|
||||
// Now modify the interval
|
||||
updatedInterval := `"interval": "10m"`
|
||||
legacyPayload = strings.Replace(legacyPayload, `"interval": "20s"`, updatedInterval, 1)
|
||||
require.JSONEq(t, expectedResult, client.SanitizeJSON(&k8sList.Items[0]))
|
||||
require.JSONEq(t, expectedResult, client.SanitizeJSON(&k8sList.Items[0], "labels"))
|
||||
dtoResponse := apis.DoRequest(helper, apis.RequestParams{
|
||||
User: client.Args.User,
|
||||
Method: http.MethodPut,
|
||||
|
Loading…
Reference in New Issue
Block a user