K8s/Dashboards: Generate Dashboards k8s APIs using Grafana App SDK (#99966)
* Generate Dashboard kinds with `grafana-app-sdk` Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com> * Hack together a fix for invalid TS codegen for v0 & v1 Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com> * Address Go linter issues Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com> * Address TS linter issues Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com> * Add new app to CODEOWNERS Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com> * Fix a couple of issues detected by tests Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com> * Update OpenAPI definitions and test files Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com> * Remove title from Dashboard v1alpha1 spec Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com> * Remove unused CUE schemas Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com> * remove unrelated files * allow any in the generated betterer * Add a comment explaining why we don't use deepcopy-gen Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com> * Default to v2alpha1 if dashboards v2 FF is enabled Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com> --------- Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com> Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
co-authored by
Ryan McKinley
parent
3fffb2872e
commit
ea89a68028
@@ -1,6 +1,7 @@
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
@@ -35,7 +36,11 @@ func NewDashboardLargeObjectSupport(scheme *runtime.Scheme) *apistore.BasicLarge
|
||||
case *dashboardV1.Dashboard:
|
||||
reduceUnstructredSpec(&dash.Spec)
|
||||
case *dashboardV2.Dashboard:
|
||||
reduceUnstructredSpec(&dash.Spec)
|
||||
dash.Spec = dashboardV2.DashboardSpec{
|
||||
Title: dash.Spec.Title,
|
||||
Description: dash.Spec.Description,
|
||||
Tags: dash.Spec.Tags,
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("unsupported dashboard type %T", obj)
|
||||
}
|
||||
@@ -45,23 +50,16 @@ func NewDashboardLargeObjectSupport(scheme *runtime.Scheme) *apistore.BasicLarge
|
||||
},
|
||||
|
||||
RebuildSpec: func(obj runtime.Object, blob []byte) error {
|
||||
body := commonV0.Unstructured{}
|
||||
err := body.UnmarshalJSON(blob)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch dash := obj.(type) {
|
||||
case *dashboardV0.Dashboard:
|
||||
dash.Spec = body
|
||||
return dash.Spec.UnmarshalJSON(blob)
|
||||
case *dashboardV1.Dashboard:
|
||||
dash.Spec = body
|
||||
return dash.Spec.UnmarshalJSON(blob)
|
||||
case *dashboardV2.Dashboard:
|
||||
dash.Spec = body
|
||||
return json.Unmarshal(blob, &dash.Spec)
|
||||
default:
|
||||
return fmt.Errorf("unsupported dashboard type %T", obj)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user