From 4d8a85d7de32fc107ae93e05689d31a0df427182 Mon Sep 17 00:00:00 2001 From: Russell Clarey Date: Thu, 22 Jan 2026 11:54:18 +0100 Subject: [PATCH] add dashboard deploy metadata --- bundle/deploy/metadata/compute.go | 19 +++++++++++++++++++ bundle/deploy/metadata/compute_test.go | 26 ++++++++++++++++++++++++++ bundle/metadata/metadata.go | 15 +++++++++++++-- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/bundle/deploy/metadata/compute.go b/bundle/deploy/metadata/compute.go index 9226f08d25..cb7be9811c 100644 --- a/bundle/deploy/metadata/compute.go +++ b/bundle/deploy/metadata/compute.go @@ -84,6 +84,25 @@ func (m *compute) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics } b.Metadata.Config.Resources.Pipelines = pipelinesMetadata + // Set dashboard config and file paths in metadata + dashboardsMetadata := make(map[string]*metadata.DashboardResource) + for name, dashboard := range b.Config.Resources.Dashboards { + // Compute config file path the dashboard is defined in, relative to the bundle + // root + l := b.Config.GetLocation("resources.dashboards." + name) + relativePath, err := filepath.Rel(b.BundleRootPath, l.File) + if err != nil { + return diag.Errorf("failed to compute relative path for dashboard %s: %v", name, err) + } + // Metadata for the dashboard + dashboardsMetadata[name] = &metadata.DashboardResource{ + ID: dashboard.ID, + RelativePath: filepath.ToSlash(relativePath), + FilePath: dashboard.FilePath, + } + } + b.Metadata.Config.Resources.Dashboards = dashboardsMetadata + // Set file upload destination of the bundle in metadata b.Metadata.Config.Workspace.FilePath = b.Config.Workspace.FilePath // In source-linked deployment files are not copied and resources use source files, therefore we use sync path as file path in metadata diff --git a/bundle/deploy/metadata/compute_test.go b/bundle/deploy/metadata/compute_test.go index ee77904f83..afddecf30e 100644 --- a/bundle/deploy/metadata/compute_test.go +++ b/bundle/deploy/metadata/compute_test.go @@ -66,6 +66,18 @@ func TestComputeMetadataMutator(t *testing.T) { }, }, }, + Dashboards: map[string]*resources.Dashboard{ + "my-dashboard-1": { + BaseResource: resources.BaseResource{ID: "5555"}, + DashboardConfig: resources.DashboardConfig{}, + FilePath: "i/h/g", + }, + "my-dashboard-2": { + BaseResource: resources.BaseResource{ID: "6666"}, + DashboardConfig: resources.DashboardConfig{}, + FilePath: "l/k/j", + }, + }, }, }, } @@ -74,6 +86,8 @@ func TestComputeMetadataMutator(t *testing.T) { bundletest.SetLocation(b, "resources.jobs.my-job-2", []dyn.Location{{File: "d/e/f"}}) bundletest.SetLocation(b, "resources.pipelines.my-pipeline-1", []dyn.Location{{File: "x/y/z"}}) bundletest.SetLocation(b, "resources.pipelines.my-pipeline-2", []dyn.Location{{File: "u/v/w"}}) + bundletest.SetLocation(b, "resources.dashboards.my-dashboard-1", []dyn.Location{{File: "g/h/i"}}) + bundletest.SetLocation(b, "resources.dashboards.my-dashboard-2", []dyn.Location{{File: "j/k/l"}}) expectedMetadata := metadata.Metadata{ Version: metadata.Version, @@ -113,6 +127,18 @@ func TestComputeMetadataMutator(t *testing.T) { ID: "4444", }, }, + Dashboards: map[string]*metadata.DashboardResource{ + "my-dashboard-1": { + RelativePath: "g/h/i", + ID: "5555", + FilePath: "i/h/g", + }, + "my-dashboard-2": { + RelativePath: "j/k/l", + ID: "6666", + FilePath: "l/k/j", + }, + }, }, }, } diff --git a/bundle/metadata/metadata.go b/bundle/metadata/metadata.go index 328b9d1a11..1c61cb093f 100644 --- a/bundle/metadata/metadata.go +++ b/bundle/metadata/metadata.go @@ -25,9 +25,20 @@ type Resource struct { RelativePath string `json:"relative_path"` } +type DashboardResource struct { + ID string `json:"id,omitempty"` + // Relative path from the bundle root to the configuration file that holds + // the dashboard definition + RelativePath string `json:"relative_path"` + // Relative path from the bundle root to the `.lvdash.json` file containing + // the dashboard source + FilePath string `json:"file_path"` +} + type Resources struct { - Jobs map[string]*Resource `json:"jobs,omitempty"` - Pipelines map[string]*Resource `json:"pipelines,omitempty"` + Jobs map[string]*Resource `json:"jobs,omitempty"` + Pipelines map[string]*Resource `json:"pipelines,omitempty"` + Dashboards map[string]*DashboardResource `json:"dashboards,omitempty"` } type Presets struct {