mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Unistore: Ensure deprecated Folder ID gets stored on all modes (#99043)
* Unistore: Ensure deprecated Folder ID gets stored on all modes Signed-off-by: Maicon Costa <maiconscosta@gmail.com> --------- Signed-off-by: Maicon Costa <maiconscosta@gmail.com>
This commit is contained in:
parent
8e59f618c1
commit
b4ec11e150
@ -3,7 +3,6 @@ package folders
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@ -80,10 +79,7 @@ func UnstructuredToLegacyFolder(item unstructured.Unstructured, orgID int64) (*f
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
id, err := getLegacyID(meta)
|
||||
if err != nil {
|
||||
return nil, ""
|
||||
}
|
||||
id := meta.GetDeprecatedInternalID() // nolint:staticcheck
|
||||
|
||||
created, err := getCreated(meta)
|
||||
if err != nil {
|
||||
@ -161,6 +157,8 @@ 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
|
||||
@ -201,23 +199,6 @@ func setParentUID(u *unstructured.Unstructured, parentUid string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getLegacyID(meta utils.GrafanaMetaAccessor) (int64, error) {
|
||||
var i int64
|
||||
|
||||
repo, err := meta.GetRepositoryInfo()
|
||||
if err != nil {
|
||||
return i, err
|
||||
}
|
||||
|
||||
if repo != nil && repo.Name == "SQL" {
|
||||
i, err = strconv.ParseInt(repo.Path, 10, 64)
|
||||
if err != nil {
|
||||
return i, err
|
||||
}
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func getURL(meta utils.GrafanaMetaAccessor, title string) string {
|
||||
slug := slugify.Slugify(title)
|
||||
uid := meta.GetName()
|
||||
|
@ -18,13 +18,11 @@ import (
|
||||
common "k8s.io/kube-openapi/pkg/common"
|
||||
"k8s.io/kube-openapi/pkg/spec3"
|
||||
|
||||
grafanarest "github.com/grafana/grafana/pkg/apiserver/rest"
|
||||
"github.com/grafana/grafana/pkg/storage/unified/resource"
|
||||
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/utils"
|
||||
"github.com/grafana/grafana/pkg/apis/folder/v0alpha1"
|
||||
grafanaregistry "github.com/grafana/grafana/pkg/apiserver/registry/generic"
|
||||
grafanarest "github.com/grafana/grafana/pkg/apiserver/rest"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/apiserver/builder"
|
||||
"github.com/grafana/grafana/pkg/services/apiserver/endpoints/request"
|
||||
@ -32,6 +30,8 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/folder"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/storage/unified/apistore"
|
||||
"github.com/grafana/grafana/pkg/storage/unified/resource"
|
||||
)
|
||||
|
||||
var _ builder.APIGroupBuilder = (*FolderAPIBuilder)(nil)
|
||||
@ -134,6 +134,9 @@ func (b *FolderAPIBuilder) UpdateAPIGroupInfo(apiGroupInfo *genericapiserver.API
|
||||
cfg: b.cfg,
|
||||
}
|
||||
|
||||
opts.StorageOptions(resourceInfo.GroupResource(), apistore.StorageOptions{
|
||||
RequireDeprecatedInternalID: true})
|
||||
|
||||
storage := map[string]rest.Storage{}
|
||||
storage[resourceInfo.StoragePath()] = legacyStore
|
||||
if optsGetter != nil && dualWriteBuilder != nil {
|
||||
|
@ -398,6 +398,7 @@ func doFolderTests(t *testing.T, helper *apis.K8sTestHelper) *apis.K8sTestHelper
|
||||
"kind": "Folder",
|
||||
"metadata": {
|
||||
"creationTimestamp": "${creationTimestamp}",
|
||||
"labels": {"grafana.app/deprecatedInternalID":"1"},
|
||||
"name": "` + uid + `",
|
||||
"namespace": "default",
|
||||
"resourceVersion": "${resourceVersion}",
|
||||
|
Loading…
Reference in New Issue
Block a user