K8s: Move GrafanaMetaAccessor into grafana-apiserver and remove usage of kinds metadata (#79602)

* move GrafanaMetaAccessor into pkg/apis, add support for Spec.Title & Spec.Name

* K8s: Move GrafanaMetaAccessor (PR into another) (#79728)

* access titles

* remove title

* remove title

* remove kinds metadata accessor

* remove kinds metadata accessor

* fixes

* error handling

* fix tests

---------

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
Dan Cech
2024-01-12 16:18:14 -05:00
committed by GitHub
co-authored by Ryan McKinley
parent da894994d4
commit d76defe517
25 changed files with 621 additions and 645 deletions
@@ -3,13 +3,9 @@ package model
import (
"encoding/json"
"errors"
"fmt"
"time"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/kinds"
"github.com/grafana/grafana/pkg/kinds/librarypanel"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type LibraryConnectionKind int
@@ -85,32 +81,6 @@ type LibraryElementDTO struct {
SchemaVersion int64 `json:"schemaVersion,omitempty"`
}
func (dto *LibraryElementDTO) ToResource() kinds.GrafanaResource[simplejson.Json, simplejson.Json] {
body := &simplejson.Json{}
_ = body.FromDB(dto.Model)
parent := librarypanel.NewK8sResource(dto.UID, nil)
res := kinds.GrafanaResource[simplejson.Json, simplejson.Json]{
Kind: parent.Kind,
APIVersion: parent.APIVersion,
Metadata: kinds.GrafanaResourceMetadata{
Name: dto.UID,
Annotations: make(map[string]string),
Labels: make(map[string]string),
ResourceVersion: fmt.Sprintf("%d", dto.Version),
CreationTimestamp: v1.NewTime(dto.Meta.Created),
},
Spec: body,
}
if dto.FolderUID != "" {
res.Metadata.SetFolder(dto.FolderUID)
}
res.Metadata.SetCreatedBy(fmt.Sprintf("user:%d", dto.Meta.CreatedBy.Id))
res.Metadata.SetUpdatedBy(fmt.Sprintf("user:%d", dto.Meta.UpdatedBy.Id))
res.Metadata.SetUpdatedTimestamp(&dto.Meta.Updated)
return res
}
// LibraryElementSearchResult is the search result for entities.
type LibraryElementSearchResult struct {
TotalCount int64 `json:"totalCount"`