Skip to content

Commit 331c77b

Browse files
committedFeb 21, 2025
fix: use specified name for dashboard env var using valueFrom
fixes #1857
1 parent dafc0e9 commit 331c77b

File tree

5 files changed

+85
-20
lines changed

5 files changed

+85
-20
lines changed
 

‎controllers/content/resolver.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ func (h *ContentResolver) getDashboardEnvs(ctx context.Context) (map[string]stri
171171
if ref.Value != "" {
172172
envs[ref.Name] = ref.Value
173173
} else {
174-
val, key, err := h.getReferencedValue(ctx, h.resource, ref.ValueFrom)
174+
_, val, err := h.getReferencedValue(ctx, h.resource, ref.ValueFrom)
175175
if err != nil {
176176
return nil, fmt.Errorf("something went wrong processing referenced env %s, error: %w", ref.Name, err)
177177
}
178-
envs[key] = val
178+
envs[ref.Name] = val
179179
}
180180
}
181181
}

‎tests/e2e/example-test/07-assert.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
---
12
apiVersion: grafana.integreatly.org/v1beta1
23
kind: GrafanaDashboard
34
metadata:
45
name: grafana-dashboard-jsonnet-project
6+
---
7+
apiVersion: grafana.integreatly.org/v1beta1
8+
kind: GrafanaDashboard
9+
metadata:
10+
name: jsonnet-env-vars
11+
status:
12+
conditions:
13+
- type: DashboardSynchronized
14+
status: "True"

‎tests/e2e/example-test/07-jsonnet-project.yaml

-17
This file was deleted.
+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
apiVersion: grafana.integreatly.org/v1beta1
3+
kind: GrafanaDashboard
4+
metadata:
5+
name: "grafana-dashboard-jsonnet-project"
6+
spec:
7+
instanceSelector:
8+
matchLabels:
9+
dashboards: "grafana"
10+
envs:
11+
- name: "ENV"
12+
value: "test"
13+
jsonnetLib:
14+
jPath:
15+
- "vendor"
16+
fileName: "test.jsonnet"
17+
gzipJsonnetProject: |-
18+
H4sIADxf5mQAA+2R3QqCMBiGPfYqPrwA3damZES3UEd1amtWYi50OiK690ZJYPR3UES05+B7Ybx8P3uzShaFUONSZoKrwPkECKGIMThpeFZE6FlbAFMaYcqiHsOAMGM4coB9ZJsr6kolpVlF5iITy1O56TO2NH3Qp73joj9C1s1fNqJs1kL77ftbZpj/CCm9nz8mpJs/MT7iAHrL9Cf8ef655EkObdowBNi7YPDqMvdi8FZKbas4CLTW/k7Wqp4Ln8tNoBPFV6NmuJhoqvvT5YxPPPcwcN394dsXWSwWi+UVjj9zQO4ACgAA
19+
---
20+
apiVersion: v1
21+
kind: ConfigMap
22+
metadata:
23+
name: jsonnet-env-vars
24+
data:
25+
value: from-conf-map
26+
---
27+
apiVersion: grafana.integreatly.org/v1beta1
28+
kind: GrafanaDashboard
29+
metadata:
30+
name: jsonnet-env-vars
31+
spec:
32+
instanceSelector:
33+
matchLabels:
34+
dashboards: "grafana"
35+
envs:
36+
- name: LITERAL
37+
value: literal
38+
- name: CONF_MAP
39+
valueFrom:
40+
configMapKeyRef:
41+
name: jsonnet-env-vars
42+
key: value
43+
jsonnet: >
44+
{
45+
"id": null,
46+
"title": "jsonnet env vars",
47+
"tags": [std.extVar("LITERAL"),std.extVar("CONF_MAP")],
48+
"style": "dark",
49+
"timezone": "browser",
50+
"editable": true,
51+
"hideControls": false,
52+
"graphTooltip": 1,
53+
"panels": [],
54+
"time": {
55+
"from": "now-6h",
56+
"to": "now"
57+
},
58+
"timepicker": {
59+
"time_options": [],
60+
"refresh_intervals": []
61+
},
62+
"templating": {
63+
"list": []
64+
},
65+
"annotations": {
66+
"list": []
67+
},
68+
"refresh": "5s",
69+
"schemaVersion": 17,
70+
"version": 0,
71+
"links": []
72+
}

‎tests/e2e/example-test/chainsaw-test.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ spec:
5353
- name: step-07
5454
try:
5555
- apply:
56-
file: 07-jsonnet-project.yaml
56+
file: 07-jsonnet.yaml
5757
- assert:
5858
file: 07-assert.yaml
5959
- name: step-08

0 commit comments

Comments
 (0)