UniStore Big Objects: Fix spec rebuilding (#100183)

* Fix big object spec rebuilding and associated test

---------

Co-authored-by: Jean-Philippe Quémémer <jeanphilippe.quemener@grafana.com>
This commit is contained in:
Arati R. 2025-02-07 09:29:25 +01:00 committed by GitHub
parent d16f2315a4
commit d62c490af5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 3 deletions

View File

@ -51,7 +51,16 @@ func NewDashboardLargeObjectSupport(scheme *runtime.Scheme) *apistore.BasicLarge
if err != nil {
return err
}
return json.Unmarshal(blob, &dash.Spec)
if err := json.Unmarshal(blob, &dash.Spec); err != nil {
return fmt.Errorf("failed to unmarshal blob into spec: %w", err)
}
if err := scheme.Convert(dash, obj, nil); err != nil {
return fmt.Errorf("failed to update original object: %w", err)
}
return nil
},
}
}

View File

@ -59,11 +59,17 @@ func TestLargeDashboardSupport(t *testing.T) {
}`, string(small))
// Now make it big again
err = largeObject.RebuildSpec(dash, f)
rehydratedDash := &dashboardv0alpha1.Dashboard{
ObjectMeta: v1.ObjectMeta{
Name: "test",
Namespace: "test",
},
}
err = largeObject.RebuildSpec(rehydratedDash, f)
require.NoError(t, err)
// check that all panels exist again
panels, found, err = unstructured.NestedSlice(dash.Spec.Object, "panels")
panels, found, err = unstructured.NestedSlice(rehydratedDash.Spec.Object, "panels")
require.NoError(t, err)
require.True(t, found)
require.Len(t, panels, expectedPanelCount)