K8s: Fix error conversion for provisioned dashboards (#103074)

This commit is contained in:
Stephanie Hingtgen
2025-03-31 14:34:54 +01:00
committed by GitHub
parent 19a52ba35e
commit 4cb756c5d1
4 changed files with 28 additions and 2 deletions
+5
View File
@@ -46,5 +46,10 @@ func ToDashboardErrorResponse(ctx context.Context, pluginStore pluginstore.Store
return response.Error(http.StatusRequestEntityTooLarge, fmt.Sprintf("Dashboard is too large, max is %d MB", apiserver.MaxRequestBodyBytes/1024/1024), err)
}
var statusErr *apierrors.StatusError
if errors.As(err, &statusErr) {
return response.Error(int(statusErr.ErrStatus.Code), statusErr.ErrStatus.Message, err)
}
return response.Error(http.StatusInternalServerError, "Failed to save dashboard", err)
}
+7
View File
@@ -36,6 +36,7 @@ import (
"github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana/pkg/util"
"github.com/grafana/grafana/pkg/web"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
)
const (
@@ -504,6 +505,12 @@ func (hs *HTTPServer) deleteDashboard(c *contextmodel.ReqContext) response.Respo
return response.Error(dashboardErr.StatusCode, dashboardErr.Error(), err)
}
}
var statusErr *k8serrors.StatusError
if errors.As(err, &statusErr) {
return response.Error(int(statusErr.ErrStatus.Code), statusErr.ErrStatus.Message, err)
}
return response.Error(http.StatusInternalServerError, "Failed to delete dashboard", err)
}
+1 -1
View File
@@ -173,7 +173,7 @@ func (b *DashboardsAPIBuilder) Validate(ctx context.Context, a admission.Attribu
}
if provisioningData != nil {
return dashboards.ErrDashboardCannotDeleteProvisionedDashboard
return apierrors.NewBadRequest(dashboards.ErrDashboardCannotDeleteProvisionedDashboard.Reason)
}
}
}
@@ -152,9 +152,23 @@ func TestIntegrationUpdatingProvisionionedDashboards(t *testing.T) {
t.Skip("skipping integration test")
}
testUpdatingProvisionionedDashboards(t, []string{})
}
func TestIntegrationUpdatingProvisionionedDashboardsK8s(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
// will be the default in g12
testUpdatingProvisionionedDashboards(t, []string{featuremgmt.FlagKubernetesClientDashboardsFolders})
}
func testUpdatingProvisionionedDashboards(t *testing.T, featureToggles []string) {
// Setup Grafana and its Database
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
DisableAnonymous: true,
DisableAnonymous: true,
EnableFeatureToggles: featureToggles,
})
provDashboardsDir := filepath.Join(dir, "conf", "provisioning", "dashboards")