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:
co-authored by
Ryan McKinley
parent
da894994d4
commit
d76defe517
@@ -4,9 +4,6 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/grafana/grafana/pkg/kinds/team"
|
||||
"github.com/grafana/grafana/pkg/services/auth/identity"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess"
|
||||
"github.com/grafana/grafana/pkg/services/search/model"
|
||||
@@ -36,18 +33,6 @@ type Team struct {
|
||||
Updated time.Time `json:"updated"`
|
||||
}
|
||||
|
||||
func (t *Team) ToResource() team.K8sResource {
|
||||
r := team.NewK8sResource(t.UID, &team.Spec{
|
||||
Name: t.Name,
|
||||
})
|
||||
r.Metadata.CreationTimestamp = v1.NewTime(t.Created)
|
||||
r.Metadata.SetUpdatedTimestamp(&t.Updated)
|
||||
if t.Email != "" {
|
||||
r.Spec.Email = &t.Email
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// ---------------------
|
||||
// COMMANDS
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package team
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestTeamConversion(t *testing.T) {
|
||||
src := Team{
|
||||
ID: 123,
|
||||
UID: "abc",
|
||||
Name: "TeamA",
|
||||
Email: "team@a.org",
|
||||
OrgID: 11,
|
||||
Created: time.UnixMilli(946713600000).UTC(), // 2000-01-01
|
||||
Updated: time.UnixMilli(1262332800000).UTC(), // 2010-01-01
|
||||
}
|
||||
|
||||
dst := src.ToResource()
|
||||
|
||||
require.Equal(t, src.Name, dst.Spec.Name)
|
||||
|
||||
out, err := json.MarshalIndent(dst, "", " ")
|
||||
require.NoError(t, err)
|
||||
fmt.Printf("%s", string(out))
|
||||
require.JSONEq(t, `{
|
||||
"apiVersion": "v0-0-alpha",
|
||||
"kind": "Team",
|
||||
"metadata": {
|
||||
"name": "abc",
|
||||
"creationTimestamp": "2000-01-01T08:00:00Z",
|
||||
"annotations": {
|
||||
"grafana.app/updatedTimestamp": "2010-01-01T08:00:00Z"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"email": "team@a.org",
|
||||
"name": "TeamA"
|
||||
}
|
||||
}`, string(out))
|
||||
}
|
||||
Reference in New Issue
Block a user