put back devenv

This commit is contained in:
Ryan McKinley committed 2024-11-19 06:18:32 +03:00
1 parent 9ca2d61620
commit d50afe3020
4 files changed
+49 -4

No files matched your search

+8 -3
View File
@@ -16,6 +16,9 @@ import (
type LocalFolderResolver struct {
// Local path to data directory
ProvisioningPath string
// Path to development environment
DevenvPath string
}
func (r *LocalFolderResolver) LocalPath(path string) string {
@@ -24,7 +27,7 @@ func (r *LocalFolderResolver) LocalPath(path string) string {
return ""
}
parts := strings.SplitN(path, "/", 1)
parts := strings.SplitN(path, "/", 2)
if len(parts) != 2 {
return ""
}
@@ -35,9 +38,11 @@ func (r *LocalFolderResolver) LocalPath(path string) string {
}
return filepath.Join(r.ProvisioningPath, parts[1])
// Can we support pointing to files in devenv
case "devenv":
return ""
if r.DevenvPath == "" {
return "" // not allowed
}
return filepath.Join(r.DevenvPath, parts[1])
}
return ""
}
+3 -1
View File
@@ -3,6 +3,7 @@ package provisioning
import (
"context"
"fmt"
"path/filepath"
"slices"
"github.com/prometheus/client_golang/prometheus"
@@ -54,6 +55,7 @@ func RegisterAPIService(
}
builder := NewProvisioningAPIBuilder(&LocalFolderResolver{
ProvisioningPath: cfg.ProvisioningPath,
DevenvPath: filepath.Join(cfg.HomePath, "devenv"),
})
apiregistration.RegisterAPI(builder)
return builder
@@ -155,7 +157,7 @@ func (b *ProvisioningAPIBuilder) Validate(ctx context.Context, a admission.Attri
return nil // This is normal for sub-resource
}
repo, err := b.asRepository(a.GetObject())
repo, err := b.asRepository(obj)
if err != nil {
return err
}
@@ -119,6 +119,18 @@ func TestIntegrationProvisioning(t *testing.T) {
// Load the samples
_, err := client.Resource.Create(ctx,
helper.LoadYAMLOrJSONFile("testdata/local-conf-provisioning-sample.yaml"),
createOptions,
)
require.NoError(t, err)
_, err = client.Resource.Create(ctx,
helper.LoadYAMLOrJSONFile("testdata/local-devenv.yaml"),
createOptions,
)
require.NoError(t, err)
_, err = client.Resource.Create(ctx,
helper.LoadYAMLOrJSONFile("testdata/github-example.yaml"),
createOptions,
)
@@ -153,6 +165,22 @@ func TestIntegrationProvisioning(t *testing.T) {
"title": "Github Example",
"type": "github"
},
"local-conf-provisioning-sample": {
"description": "load resources from https://github.com/grafana/grafana/tree/main/conf/provisioning/sample",
"local": {
"path": "provisioning/sample"
},
"title": "Config provisioning files",
"type": "local"
},
"local-devenv": {
"description": "load https://github.com/grafana/grafana/tree/main/devenv/dev-dashboards",
"local": {
"path": "devenv/dev-dashboards"
},
"title": "Load devenv dashboards",
"type": "local"
},
"s3-example": {
"description": "load resources from an S3 bucket",
"s3": {
+10
View File
@@ -0,0 +1,10 @@
apiVersion: provisioning.grafana.app/v0alpha1
kind: Repository
metadata:
name: local-devenv
spec:
title: Load devenv dashboards
description: load https://github.com/grafana/grafana/tree/main/devenv/dev-dashboards
type: local
local:
path: devenv/dev-dashboards