Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions bundle/deploy/metadata/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions bundle/deploy/metadata/compute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
},
}
Expand All @@ -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,
Expand Down Expand Up @@ -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",
},
},
},
},
}
Expand Down
15 changes: 13 additions & 2 deletions bundle/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down