K8s/Dashboard: Promote from alpha1 to beta1 (#104009)
This commit is contained in:
@@ -15,8 +15,8 @@ import (
|
||||
|
||||
claims "github.com/grafana/authlib/types"
|
||||
dashboardOG "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard"
|
||||
dashboardv0 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v0alpha1"
|
||||
dashboard "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v1alpha1"
|
||||
dashboardV0 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v0alpha1"
|
||||
dashboardV1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v1beta1"
|
||||
"github.com/grafana/grafana/apps/dashboard/pkg/migration/schemaversion"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
@@ -43,7 +43,7 @@ type dashboardRow struct {
|
||||
RV int64
|
||||
|
||||
// Dashboard resource
|
||||
Dash *dashboard.Dashboard
|
||||
Dash *dashboardV1.Dashboard
|
||||
|
||||
// The folder UID (needed for access control checks)
|
||||
FolderUID string
|
||||
@@ -222,8 +222,8 @@ func (r *rowsWrapper) Value() []byte {
|
||||
}
|
||||
|
||||
func (a *dashboardSqlAccess) scanRow(rows *sql.Rows, history bool) (*dashboardRow, error) {
|
||||
dash := &dashboard.Dashboard{
|
||||
TypeMeta: dashboard.DashboardResourceInfo.TypeMeta(),
|
||||
dash := &dashboardV1.Dashboard{
|
||||
TypeMeta: dashboardV1.DashboardResourceInfo.TypeMeta(),
|
||||
ObjectMeta: metav1.ObjectMeta{Annotations: make(map[string]string)},
|
||||
}
|
||||
row := &dashboardRow{Dash: dash}
|
||||
@@ -257,8 +257,11 @@ func (a *dashboardSqlAccess) scanRow(rows *sql.Rows, history bool) (*dashboardRo
|
||||
&updated, &updatedBy, &updatedByID,
|
||||
&version, &message, &data, &apiVersion,
|
||||
)
|
||||
if apiVersion.String == "" {
|
||||
apiVersion.String = "v0alpha1" // default value
|
||||
switch apiVersion.String {
|
||||
case "":
|
||||
apiVersion.String = dashboardV0.VERSION // default value
|
||||
case "v1alpha1":
|
||||
apiVersion.String = dashboardV0.VERSION // downgrade to v0 (it may not have run migrations)
|
||||
}
|
||||
|
||||
row.token = &continueToken{orgId: orgId, id: dashboard_id}
|
||||
@@ -270,7 +273,7 @@ func (a *dashboardSqlAccess) scanRow(rows *sql.Rows, history bool) (*dashboardRo
|
||||
row.RV = version
|
||||
dash.ResourceVersion = fmt.Sprintf("%d", row.RV)
|
||||
dash.Namespace = a.namespacer(orgId)
|
||||
dash.APIVersion = fmt.Sprintf("%s/%s", dashboard.GROUP, apiVersion.String)
|
||||
dash.APIVersion = fmt.Sprintf("%s/%s", dashboardV1.GROUP, apiVersion.String)
|
||||
dash.UID = gapiutil.CalculateClusterWideUID(dash)
|
||||
dash.SetCreationTimestamp(metav1.NewTime(created))
|
||||
meta, err := utils.MetaAccessor(dash)
|
||||
@@ -345,7 +348,7 @@ func getUserID(v sql.NullString, id sql.NullInt64) string {
|
||||
}
|
||||
|
||||
// DeleteDashboard implements DashboardAccess.
|
||||
func (a *dashboardSqlAccess) DeleteDashboard(ctx context.Context, orgId int64, uid string) (*dashboard.Dashboard, bool, error) {
|
||||
func (a *dashboardSqlAccess) DeleteDashboard(ctx context.Context, orgId int64, uid string) (*dashboardV1.Dashboard, bool, error) {
|
||||
dash, _, err := a.GetDashboard(ctx, orgId, uid, 0)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
@@ -361,7 +364,7 @@ func (a *dashboardSqlAccess) DeleteDashboard(ctx context.Context, orgId int64, u
|
||||
return dash, true, nil
|
||||
}
|
||||
|
||||
func (a *dashboardSqlAccess) buildSaveDashboardCommand(ctx context.Context, orgId int64, dash *dashboard.Dashboard) (*dashboards.SaveDashboardCommand, bool, error) {
|
||||
func (a *dashboardSqlAccess) buildSaveDashboardCommand(ctx context.Context, orgId int64, dash *dashboardV1.Dashboard) (*dashboards.SaveDashboardCommand, bool, error) {
|
||||
created := false
|
||||
user, ok := claims.AuthInfoFrom(ctx)
|
||||
if !ok || user == nil {
|
||||
@@ -397,21 +400,21 @@ func (a *dashboardSqlAccess) buildSaveDashboardCommand(ctx context.Context, orgI
|
||||
}
|
||||
}
|
||||
|
||||
// v1 should be saved as schema version 41. v0 allows for older versions
|
||||
if strings.HasSuffix(dash.APIVersion, "v1alpha1") {
|
||||
schemaVersion := schemaversion.GetSchemaVersion(dash.Spec.Object)
|
||||
if schemaVersion < int(schemaversion.LATEST_VERSION) {
|
||||
dash.APIVersion = dashboardv0.VERSION
|
||||
a.log.Info("Downgrading v1alpha1 dashboard to v0alpha1 due to schema version mismatch", "dashboard", dash.Name, "schema_version", schemaVersion)
|
||||
}
|
||||
}
|
||||
|
||||
apiVersion := strings.TrimPrefix(dash.APIVersion, dashboard.GROUP+"/")
|
||||
apiVersion := strings.TrimPrefix(dash.APIVersion, dashboardV1.GROUP+"/")
|
||||
meta, err := utils.MetaAccessor(dash)
|
||||
if err != nil {
|
||||
return nil, created, err
|
||||
}
|
||||
|
||||
// v1 should be saved as schema version 41. v0 allows for older versions
|
||||
if strings.HasPrefix(apiVersion, "v1") {
|
||||
schemaVersion := schemaversion.GetSchemaVersion(dash.Spec.Object)
|
||||
if schemaVersion < int(schemaversion.LATEST_VERSION) {
|
||||
apiVersion = dashboardV0.VERSION
|
||||
a.log.Info("Downgrading v1alpha1 dashboard to v0alpha1 due to schema version mismatch", "dashboard", dash.Name, "schema_version", schemaVersion)
|
||||
}
|
||||
}
|
||||
|
||||
return &dashboards.SaveDashboardCommand{
|
||||
OrgID: orgId,
|
||||
Message: meta.GetMessage(),
|
||||
@@ -424,7 +427,7 @@ func (a *dashboardSqlAccess) buildSaveDashboardCommand(ctx context.Context, orgI
|
||||
}, created, nil
|
||||
}
|
||||
|
||||
func (a *dashboardSqlAccess) SaveDashboard(ctx context.Context, orgId int64, dash *dashboard.Dashboard, failOnExisting bool) (*dashboard.Dashboard, bool, error) {
|
||||
func (a *dashboardSqlAccess) SaveDashboard(ctx context.Context, orgId int64, dash *dashboardV1.Dashboard, failOnExisting bool) (*dashboardV1.Dashboard, bool, error) {
|
||||
user, ok := claims.AuthInfoFrom(ctx)
|
||||
if !ok || user == nil {
|
||||
return nil, false, fmt.Errorf("no user found in context")
|
||||
@@ -464,7 +467,7 @@ func (a *dashboardSqlAccess) SaveDashboard(ctx context.Context, orgId int64, das
|
||||
return dash, created, err
|
||||
}
|
||||
|
||||
func (a *dashboardSqlAccess) GetLibraryPanels(ctx context.Context, query LibraryPanelQuery) (*dashboard.LibraryPanelList, error) {
|
||||
func (a *dashboardSqlAccess) GetLibraryPanels(ctx context.Context, query LibraryPanelQuery) (*dashboardV0.LibraryPanelList, error) {
|
||||
limit := int(query.Limit)
|
||||
query.Limit += 1 // for continue
|
||||
if query.OrgID == 0 {
|
||||
@@ -483,7 +486,7 @@ func (a *dashboardSqlAccess) GetLibraryPanels(ctx context.Context, query Library
|
||||
}
|
||||
q := rawQuery
|
||||
|
||||
res := &dashboard.LibraryPanelList{}
|
||||
res := &dashboardV0.LibraryPanelList{}
|
||||
rows, err := sqlx.DB.GetSqlxSession().Query(ctx, q, req.GetArgs()...)
|
||||
defer func() {
|
||||
if rows != nil {
|
||||
@@ -524,9 +527,9 @@ func (a *dashboardSqlAccess) GetLibraryPanels(ctx context.Context, query Library
|
||||
}
|
||||
lastID = p.ID
|
||||
|
||||
item := dashboard.LibraryPanel{
|
||||
item := dashboardV0.LibraryPanel{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
APIVersion: fmt.Sprintf("%s/%s", dashboard.GROUP, "v0alpha1"),
|
||||
APIVersion: dashboardV0.APIVERSION,
|
||||
Kind: "LibraryPanel",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
@@ -534,10 +537,10 @@ func (a *dashboardSqlAccess) GetLibraryPanels(ctx context.Context, query Library
|
||||
CreationTimestamp: metav1.NewTime(p.Created),
|
||||
ResourceVersion: strconv.FormatInt(p.Updated.UnixMicro(), 10),
|
||||
},
|
||||
Spec: dashboard.LibraryPanelSpec{},
|
||||
Spec: dashboardV0.LibraryPanelSpec{},
|
||||
}
|
||||
|
||||
status := &dashboard.LibraryPanelStatus{
|
||||
status := &dashboardV0.LibraryPanelStatus{
|
||||
Missing: v0alpha1.Unstructured{},
|
||||
}
|
||||
err = json.Unmarshal(p.Model, &item.Spec)
|
||||
|
||||
Reference in New Issue
Block a user