mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboards: Remove schemaVersion < min_version validation (#100555)
This commit is contained in:
@@ -9,10 +9,6 @@ func Migrate(dash map[string]interface{}, targetVersion int) error {
|
||||
inputVersion := schemaversion.GetSchemaVersion(dash)
|
||||
dash["schemaVersion"] = inputVersion
|
||||
|
||||
if inputVersion < schemaversion.MINIUM_VERSION {
|
||||
return schemaversion.NewMinimumVersionError(inputVersion)
|
||||
}
|
||||
|
||||
for nextVersion := inputVersion + 1; nextVersion <= targetVersion; nextVersion++ {
|
||||
if migration, ok := schemaversion.Migrations[nextVersion]; ok {
|
||||
if err := migration(dash); err != nil {
|
||||
|
||||
@@ -22,15 +22,6 @@ func TestMigrate(t *testing.T) {
|
||||
files, err := os.ReadDir(INPUT_DIR)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("minimum version check", func(t *testing.T) {
|
||||
err := migration.Migrate(map[string]interface{}{
|
||||
"schemaVersion": schemaversion.MINIUM_VERSION - 1,
|
||||
}, schemaversion.MINIUM_VERSION)
|
||||
|
||||
var minVersionErr = schemaversion.NewMinimumVersionError(schemaversion.MINIUM_VERSION - 1)
|
||||
require.ErrorAs(t, err, &minVersionErr)
|
||||
})
|
||||
|
||||
for _, f := range files {
|
||||
if f.IsDir() {
|
||||
continue
|
||||
|
||||
@@ -2,23 +2,8 @@ package schemaversion
|
||||
|
||||
import "fmt"
|
||||
|
||||
var _ error = &MinimumVersionError{}
|
||||
var _ error = &MigrationError{}
|
||||
|
||||
// MinimumVersionError is an error that is returned when the schema version is below the minimum version.
|
||||
func NewMinimumVersionError(inputVersion int) *MinimumVersionError {
|
||||
return &MinimumVersionError{inputVersion: inputVersion}
|
||||
}
|
||||
|
||||
// MinimumVersionError is an error type for minimum version errors.
|
||||
type MinimumVersionError struct {
|
||||
inputVersion int
|
||||
}
|
||||
|
||||
func (e *MinimumVersionError) Error() string {
|
||||
return fmt.Errorf("input schema version is below minimum version. input: %d minimum: %d", e.inputVersion, MINIUM_VERSION).Error()
|
||||
}
|
||||
|
||||
// ErrMigrationFailed is an error that is returned when a migration fails.
|
||||
func NewMigrationError(msg string, currentVersion, targetVersion int) *MigrationError {
|
||||
return &MigrationError{
|
||||
|
||||
@@ -4,10 +4,7 @@ import "strconv"
|
||||
|
||||
type SchemaVersionMigrationFunc func(map[string]interface{}) error
|
||||
|
||||
const (
|
||||
MINIUM_VERSION = 36
|
||||
LATEST_VERSION = 41
|
||||
)
|
||||
const LATEST_VERSION = 41
|
||||
|
||||
var Migrations = map[int]SchemaVersionMigrationFunc{
|
||||
37: V37,
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
conversion "k8s.io/apimachinery/pkg/conversion"
|
||||
klog "k8s.io/klog/v2"
|
||||
|
||||
@@ -15,12 +13,7 @@ func Convert_v0alpha1_Unstructured_To_v1alpha1_DashboardSpec(in *common.Unstruct
|
||||
out.Unstructured = *in
|
||||
err := migration.Migrate(out.Unstructured.Object, schemaversion.LATEST_VERSION)
|
||||
if err != nil {
|
||||
minErr := &schemaversion.MinimumVersionError{}
|
||||
if errors.As(err, &minErr) {
|
||||
out.Unstructured.Object["__migrationError"] = err.Error()
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
t, ok := out.Unstructured.Object["title"].(string)
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package v2alpha1
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
conversion "k8s.io/apimachinery/pkg/conversion"
|
||||
klog "k8s.io/klog/v2"
|
||||
|
||||
@@ -15,12 +13,7 @@ func Convert_v0alpha1_Unstructured_To_v2alpha1_DashboardSpec(in *common.Unstruct
|
||||
out.Unstructured = *in
|
||||
err := migration.Migrate(out.Unstructured.Object, schemaversion.LATEST_VERSION)
|
||||
if err != nil {
|
||||
minErr := &schemaversion.MinimumVersionError{}
|
||||
if errors.As(err, &minErr) {
|
||||
out.Unstructured.Object["__migrationError"] = err.Error()
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
t, ok := out.Unstructured.Object["title"].(string)
|
||||
|
||||
Reference in New Issue
Block a user