mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
K8s: Dashboards: Set message as annotation (#99230)
This commit is contained in:
parent
b309c5daed
commit
1a2a284972
@ -2020,15 +2020,19 @@ func LegacySaveCommandToUnstructured(cmd *dashboards.SaveDashboardCommand, names
|
|||||||
finalObj.SetNamespace(namespace)
|
finalObj.SetNamespace(namespace)
|
||||||
finalObj.SetGroupVersionKind(v0alpha1.DashboardResourceInfo.GroupVersionKind())
|
finalObj.SetGroupVersionKind(v0alpha1.DashboardResourceInfo.GroupVersionKind())
|
||||||
|
|
||||||
if cmd.FolderUID != "" {
|
meta, err := utils.MetaAccessor(&finalObj)
|
||||||
meta, err := utils.MetaAccessor(&finalObj)
|
if err != nil {
|
||||||
if err != nil {
|
return finalObj, err
|
||||||
return finalObj, err
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
if cmd.FolderUID != "" {
|
||||||
meta.SetFolder(cmd.FolderUID)
|
meta.SetFolder(cmd.FolderUID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cmd.Message != "" {
|
||||||
|
meta.SetMessage(cmd.Message)
|
||||||
|
}
|
||||||
|
|
||||||
return finalObj, nil
|
return finalObj, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1761,6 +1761,7 @@ func TestLegacySaveCommandToUnstructured(t *testing.T) {
|
|||||||
t.Run("successfully converts save command to unstructured", func(t *testing.T) {
|
t.Run("successfully converts save command to unstructured", func(t *testing.T) {
|
||||||
cmd := &dashboards.SaveDashboardCommand{
|
cmd := &dashboards.SaveDashboardCommand{
|
||||||
FolderUID: "folder-uid",
|
FolderUID: "folder-uid",
|
||||||
|
Message: "saving this dashboard",
|
||||||
Dashboard: simplejson.NewFromAny(map[string]any{"test": "test", "title": "testing slugify", "uid": "test-uid"}),
|
Dashboard: simplejson.NewFromAny(map[string]any{"test": "test", "title": "testing slugify", "uid": "test-uid"}),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1771,7 +1772,7 @@ func TestLegacySaveCommandToUnstructured(t *testing.T) {
|
|||||||
assert.Equal(t, "test-namespace", result.GetNamespace())
|
assert.Equal(t, "test-namespace", result.GetNamespace())
|
||||||
spec := result.Object["spec"].(map[string]any)
|
spec := result.Object["spec"].(map[string]any)
|
||||||
assert.Equal(t, spec["version"], 1)
|
assert.Equal(t, spec["version"], 1)
|
||||||
assert.Equal(t, result.GetAnnotations(), map[string]string{utils.AnnoKeyFolder: "folder-uid"})
|
assert.Equal(t, result.GetAnnotations(), map[string]string{utils.AnnoKeyFolder: "folder-uid", utils.AnnoKeyMessage: "saving this dashboard"})
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should increase version when called", func(t *testing.T) {
|
t.Run("should increase version when called", func(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user