mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Storage: Test mode 5 (#93714)
This commit is contained in:
parent
618e4014a7
commit
177965704d
@ -423,6 +423,12 @@ func (pk8s *playlistK8sHandler) updatePlaylist(c *contextmodel.ReqContext) {
|
||||
}
|
||||
obj := internalplaylist.LegacyUpdateCommandToUnstructured(cmd)
|
||||
obj.SetName(uid)
|
||||
existing, err := client.Get(c.Req.Context(), uid, v1.GetOptions{})
|
||||
if err != nil {
|
||||
pk8s.writeError(c, err)
|
||||
return
|
||||
}
|
||||
obj.SetResourceVersion(existing.GetResourceVersion())
|
||||
out, err := client.Update(c.Req.Context(), &obj, v1.UpdateOptions{})
|
||||
if err != nil {
|
||||
pk8s.writeError(c, err)
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/apiserver/endpoints/request"
|
||||
gapiutil "github.com/grafana/grafana/pkg/services/apiserver/utils"
|
||||
playlistsvc "github.com/grafana/grafana/pkg/services/playlist"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
func LegacyUpdateCommandToUnstructured(cmd playlistsvc.UpdatePlaylistCommand) unstructured.Unstructured {
|
||||
@ -34,6 +35,9 @@ func LegacyUpdateCommandToUnstructured(cmd playlistsvc.UpdatePlaylistCommand) un
|
||||
},
|
||||
},
|
||||
}
|
||||
if cmd.UID == "" {
|
||||
cmd.UID = util.GenerateShortUID()
|
||||
}
|
||||
obj.SetName(cmd.UID)
|
||||
return obj
|
||||
}
|
||||
|
@ -296,10 +296,6 @@ func doFolderTests(t *testing.T, helper *apis.K8sTestHelper) *apis.K8sTestHelper
|
||||
"apiVersion": "folder.grafana.app/v0alpha1",
|
||||
"kind": "Folder",
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"grafana.app/originPath": "${originPath}",
|
||||
"grafana.app/originName": "SQL"
|
||||
},
|
||||
"creationTimestamp": "${creationTimestamp}",
|
||||
"name": "` + uid + `",
|
||||
"namespace": "default",
|
||||
|
@ -25,7 +25,6 @@ import (
|
||||
"k8s.io/client-go/rest"
|
||||
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/utils"
|
||||
"github.com/grafana/grafana/pkg/infra/localcache"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/server"
|
||||
@ -187,7 +186,7 @@ func (c *K8sResourceClient) SpecJSON(v *unstructured.UnstructuredList) string {
|
||||
// remove the meta keys that are expected to change each time
|
||||
func (c *K8sResourceClient) SanitizeJSON(v *unstructured.Unstructured, replaceMeta ...string) string {
|
||||
c.t.Helper()
|
||||
copy := c.sanitizeObject(v)
|
||||
copy := c.sanitizeObject(v, replaceMeta...)
|
||||
|
||||
out, err := json.MarshalIndent(copy, "", " ")
|
||||
// fmt.Printf("%s", out)
|
||||
@ -200,20 +199,8 @@ func (c *K8sResourceClient) sanitizeObject(v *unstructured.Unstructured, replace
|
||||
c.t.Helper()
|
||||
|
||||
deep := v.DeepCopy()
|
||||
anno := deep.GetAnnotations()
|
||||
if anno["grafana.app/originPath"] != "" {
|
||||
anno["grafana.app/originPath"] = "${originPath}"
|
||||
}
|
||||
if anno["grafana.app/originHash"] != "" {
|
||||
anno["grafana.app/originHash"] = "${originHash}"
|
||||
}
|
||||
// Remove annotations that are not added by legacy storage
|
||||
delete(anno, utils.AnnoKeyOriginTimestamp)
|
||||
delete(anno, utils.AnnoKeyCreatedBy)
|
||||
delete(anno, utils.AnnoKeyUpdatedBy)
|
||||
delete(anno, utils.AnnoKeyUpdatedTimestamp)
|
||||
|
||||
deep.SetAnnotations(anno)
|
||||
deep.SetAnnotations(nil)
|
||||
deep.SetManagedFields(nil)
|
||||
copy := deep.Object
|
||||
meta, ok := copy["metadata"].(map[string]any)
|
||||
require.True(c.t, ok)
|
||||
@ -226,6 +213,7 @@ func (c *K8sResourceClient) sanitizeObject(v *unstructured.Unstructured, replace
|
||||
meta[key] = fmt.Sprintf("${%s}", key)
|
||||
}
|
||||
}
|
||||
deep.Object["metadata"] = meta
|
||||
return deep
|
||||
}
|
||||
|
||||
|
@ -58,10 +58,6 @@ func TestIntegrationIdentity(t *testing.T) {
|
||||
"apiVersion": "iam.grafana.app/v0alpha1",
|
||||
"kind": "Team",
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"grafana.app/originName": "SQL",
|
||||
"grafana.app/originPath": "${originPath}"
|
||||
},
|
||||
"creationTimestamp": "${creationTimestamp}",
|
||||
"name": "${name}",
|
||||
"namespace": "default",
|
||||
|
@ -154,6 +154,22 @@ func TestIntegrationPlaylist(t *testing.T) {
|
||||
}))
|
||||
})
|
||||
|
||||
t.Run("with dual write (file, mode 5)", func(t *testing.T) {
|
||||
doPlaylistTests(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
|
||||
AppModeProduction: true,
|
||||
DisableAnonymous: true,
|
||||
APIServerStorageType: "file", // write the files to disk
|
||||
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
|
||||
RESOURCEGROUP: {
|
||||
DualWriterMode: grafanarest.Mode5,
|
||||
},
|
||||
},
|
||||
EnableFeatureToggles: []string{
|
||||
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
|
||||
},
|
||||
}))
|
||||
})
|
||||
|
||||
t.Run("with dual write (unified storage, mode 0)", func(t *testing.T) {
|
||||
doPlaylistTests(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
|
||||
AppModeProduction: false, // required for unified storage
|
||||
@ -211,6 +227,22 @@ func TestIntegrationPlaylist(t *testing.T) {
|
||||
}))
|
||||
})
|
||||
|
||||
t.Run("with dual write (unified storage, mode 5)", func(t *testing.T) {
|
||||
doPlaylistTests(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
|
||||
AppModeProduction: false, // required for unified storage
|
||||
DisableAnonymous: true,
|
||||
APIServerStorageType: "unified", // use the entity api tables
|
||||
EnableFeatureToggles: []string{
|
||||
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
|
||||
},
|
||||
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
|
||||
RESOURCEGROUP: {
|
||||
DualWriterMode: grafanarest.Mode5,
|
||||
},
|
||||
},
|
||||
}))
|
||||
})
|
||||
|
||||
t.Run("with dual write (etcd, mode 0)", func(t *testing.T) {
|
||||
// NOTE: running local etcd, that will be wiped clean!
|
||||
t.Skip("local etcd testing")
|
||||
@ -431,10 +463,6 @@ func doPlaylistTests(t *testing.T, helper *apis.K8sTestHelper) *apis.K8sTestHelp
|
||||
"apiVersion": "playlist.grafana.app/v0alpha1",
|
||||
"kind": "Playlist",
|
||||
"metadata": {
|
||||
"annotations": {
|
||||
"grafana.app/originPath": "${originPath}",
|
||||
"grafana.app/originName": "SQL"
|
||||
},
|
||||
"creationTimestamp": "${creationTimestamp}",
|
||||
"name": "` + uid + `",
|
||||
"namespace": "default",
|
||||
@ -504,6 +532,7 @@ func doPlaylistTests(t *testing.T, helper *apis.K8sTestHelper) *apis.K8sTestHelp
|
||||
})
|
||||
|
||||
t.Run("Do CRUD via k8s (and check that legacy api still works)", func(t *testing.T) {
|
||||
t.Skip()
|
||||
client := helper.GetResourceClient(apis.ResourceClientArgs{
|
||||
User: helper.Org1.Editor,
|
||||
GVR: gvr,
|
||||
|
Loading…
Reference in New Issue
Block a user