K8s: Rename origin.key to origin.hash (#89337)
This commit is contained in:
@@ -25,7 +25,7 @@ const AnnoKeySlug = "grafana.app/slug"
|
||||
|
||||
const AnnoKeyOriginName = "grafana.app/originName"
|
||||
const AnnoKeyOriginPath = "grafana.app/originPath"
|
||||
const AnnoKeyOriginKey = "grafana.app/originKey"
|
||||
const AnnoKeyOriginHash = "grafana.app/originHash"
|
||||
const AnnoKeyOriginTimestamp = "grafana.app/originTimestamp"
|
||||
|
||||
// ResourceOriginInfo is saved in annotations. This is used to identify where the resource came from
|
||||
@@ -37,8 +37,8 @@ type ResourceOriginInfo struct {
|
||||
// The path within the named origin above (external_id in the existing dashboard provisioing)
|
||||
Path string `json:"path,omitempty"`
|
||||
|
||||
// Verification/identification key (check_sum in existing dashboard provisioning)
|
||||
Key string `json:"key,omitempty"`
|
||||
// Verification/identification hash (check_sum in existing dashboard provisioning)
|
||||
Hash string `json:"hash,omitempty"`
|
||||
|
||||
// Origin modification timestamp when the resource was saved
|
||||
// This will be before the resource updated time
|
||||
@@ -77,7 +77,7 @@ type GrafanaMetaAccessor interface {
|
||||
SetOriginInfo(info *ResourceOriginInfo)
|
||||
GetOriginName() string
|
||||
GetOriginPath() string
|
||||
GetOriginKey() string
|
||||
GetOriginHash() string
|
||||
GetOriginTimestamp() (*time.Time, error)
|
||||
|
||||
// Find a title in the object
|
||||
@@ -219,15 +219,15 @@ func (m *grafanaMetaAccessor) SetOriginInfo(info *ResourceOriginInfo) {
|
||||
|
||||
delete(anno, AnnoKeyOriginName)
|
||||
delete(anno, AnnoKeyOriginPath)
|
||||
delete(anno, AnnoKeyOriginKey)
|
||||
delete(anno, AnnoKeyOriginHash)
|
||||
delete(anno, AnnoKeyOriginTimestamp)
|
||||
if info != nil && info.Name != "" {
|
||||
anno[AnnoKeyOriginName] = info.Name
|
||||
if info.Path != "" {
|
||||
anno[AnnoKeyOriginPath] = info.Path
|
||||
}
|
||||
if info.Key != "" {
|
||||
anno[AnnoKeyOriginKey] = info.Key
|
||||
if info.Hash != "" {
|
||||
anno[AnnoKeyOriginHash] = info.Hash
|
||||
}
|
||||
if info.Timestamp != nil {
|
||||
anno[AnnoKeyOriginTimestamp] = info.Timestamp.UTC().Format(time.RFC3339)
|
||||
@@ -245,7 +245,7 @@ func (m *grafanaMetaAccessor) GetOriginInfo() (*ResourceOriginInfo, error) {
|
||||
return &ResourceOriginInfo{
|
||||
Name: v,
|
||||
Path: m.GetOriginPath(),
|
||||
Key: m.GetOriginKey(),
|
||||
Hash: m.GetOriginHash(),
|
||||
Timestamp: t,
|
||||
}, err
|
||||
}
|
||||
@@ -258,8 +258,8 @@ func (m *grafanaMetaAccessor) GetOriginPath() string {
|
||||
return m.get(AnnoKeyOriginPath)
|
||||
}
|
||||
|
||||
func (m *grafanaMetaAccessor) GetOriginKey() string {
|
||||
return m.get(AnnoKeyOriginKey)
|
||||
func (m *grafanaMetaAccessor) GetOriginHash() string {
|
||||
return m.get(AnnoKeyOriginHash)
|
||||
}
|
||||
|
||||
func (m *grafanaMetaAccessor) GetOriginTimestamp() (*time.Time, error) {
|
||||
|
||||
@@ -126,7 +126,7 @@ func TestMetaAccessor(t *testing.T) {
|
||||
originInfo := &utils.ResourceOriginInfo{
|
||||
Name: "test",
|
||||
Path: "a/b/c",
|
||||
Key: "kkk",
|
||||
Hash: "kkk",
|
||||
}
|
||||
|
||||
t.Run("fails for non resource objects", func(t *testing.T) {
|
||||
@@ -158,7 +158,7 @@ func TestMetaAccessor(t *testing.T) {
|
||||
require.Equal(t, map[string]string{
|
||||
"grafana.app/originName": "test",
|
||||
"grafana.app/originPath": "a/b/c",
|
||||
"grafana.app/originKey": "kkk",
|
||||
"grafana.app/originHash": "kkk",
|
||||
"grafana.app/folder": "folderUID",
|
||||
}, res.GetAnnotations())
|
||||
|
||||
@@ -192,7 +192,7 @@ func TestMetaAccessor(t *testing.T) {
|
||||
require.Equal(t, map[string]string{
|
||||
"grafana.app/originName": "test",
|
||||
"grafana.app/originPath": "a/b/c",
|
||||
"grafana.app/originKey": "kkk",
|
||||
"grafana.app/originHash": "kkk",
|
||||
"grafana.app/folder": "folderUID",
|
||||
}, obj.GetAnnotations())
|
||||
|
||||
@@ -215,7 +215,7 @@ func TestMetaAccessor(t *testing.T) {
|
||||
require.Equal(t, map[string]string{
|
||||
"grafana.app/originName": "test",
|
||||
"grafana.app/originPath": "a/b/c",
|
||||
"grafana.app/originKey": "kkk",
|
||||
"grafana.app/originHash": "kkk",
|
||||
"grafana.app/folder": "folderUID",
|
||||
}, obj2.GetAnnotations())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user