|
|
@ -1,27 +1,34 @@ |
|
|
|
package v2alpha1 |
|
|
|
package v2alpha1 |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"errors" |
|
|
|
|
|
|
|
|
|
|
|
conversion "k8s.io/apimachinery/pkg/conversion" |
|
|
|
conversion "k8s.io/apimachinery/pkg/conversion" |
|
|
|
klog "k8s.io/klog/v2" |
|
|
|
klog "k8s.io/klog/v2" |
|
|
|
|
|
|
|
|
|
|
|
common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1" |
|
|
|
common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1" |
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/apis/dashboard/migration" |
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/apis/dashboard/migration/schemaversion" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func Convert_v0alpha1_Unstructured_To_v2alpha1_DashboardSpec(in *common.Unstructured, out *DashboardSpec, s conversion.Scope) error { |
|
|
|
func Convert_v0alpha1_Unstructured_To_v2alpha1_DashboardSpec(in *common.Unstructured, out *DashboardSpec, s conversion.Scope) error { |
|
|
|
out.Unstructured = *in |
|
|
|
out.Unstructured = *in |
|
|
|
|
|
|
|
err := migration.Migrate(out.Unstructured.Object, schemaversion.LATEST_VERSION) |
|
|
|
t, ok := in.Object["title"] |
|
|
|
if err != nil { |
|
|
|
if !ok { |
|
|
|
minErr := &schemaversion.MinimumVersionError{} |
|
|
|
return nil // skip setting the title if it's not in the unstructured object
|
|
|
|
if errors.As(err, &minErr) { |
|
|
|
|
|
|
|
out.Unstructured.Object["__migrationError"] = err.Error() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
title, ok := t.(string) |
|
|
|
t, ok := out.Unstructured.Object["title"].(string) |
|
|
|
if !ok { |
|
|
|
if !ok { |
|
|
|
klog.V(5).Infof("unstructured dashboard title field is not a string %v", t) |
|
|
|
klog.V(5).Infof("unstructured dashboard title field is not a string %v", t) |
|
|
|
return nil // skip setting the title if it's not a string in the unstructured object
|
|
|
|
return nil // skip setting the title if it's not a string in the unstructured object
|
|
|
|
} |
|
|
|
} |
|
|
|
out.Title = title |
|
|
|
out.Title = t |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|