@@ -473,6 +473,9 @@ func (r *GrafanaDashboardReconciler) fetchDashboardJson(ctx context.Context, das
473
473
474
474
func (r * GrafanaDashboardReconciler ) getDashboardEnvs (ctx context.Context , dashboard * v1beta1.GrafanaDashboard ) (map [string ]string , error ) {
475
475
envs := make (map [string ]string )
476
+ if dashboard .Spec .EnvsFrom == nil && dashboard .Spec .Envs == nil {
477
+ return nil , fmt .Errorf ("dashboard.Spec.Envs or dashboard.Spec.EnvFrom nil, can't get envs for dashboard: %s" , dashboard .Name )
478
+ }
476
479
if dashboard .Spec .EnvsFrom != nil {
477
480
for _ , ref := range dashboard .Spec .EnvsFrom {
478
481
key , val , err := r .getReferencedValue (ctx , dashboard , ref )
@@ -508,20 +511,22 @@ func (r *GrafanaDashboardReconciler) getReferencedValue(ctx context.Context, cr
508
511
if val , ok := s .Data [source .SecretKeyRef .Key ]; ok {
509
512
return source .SecretKeyRef .Key , string (val ), nil
510
513
} else {
511
- return "" , "" , fmt .Errorf ("missing key %s in secret %s" , source .SecretKeyRef .Key , source .ConfigMapKeyRef .Name )
514
+ return "" , "" , fmt .Errorf ("missing key %s in secret %s" , source .SecretKeyRef .Key , source .SecretKeyRef .Name )
512
515
}
513
- } else {
516
+ }
517
+ if source .ConfigMapKeyRef != nil {
514
518
s := & v1.ConfigMap {}
515
- err := r .Client .Get (ctx , client.ObjectKey {Namespace : cr .Namespace , Name : source .SecretKeyRef .Name }, s )
519
+ err := r .Client .Get (ctx , client.ObjectKey {Namespace : cr .Namespace , Name : source .ConfigMapKeyRef .Name }, s )
516
520
if err != nil {
517
521
return "" , "" , err
518
522
}
519
- if val , ok := s .Data [source .SecretKeyRef .Key ]; ok {
520
- return source .SecretKeyRef .Key , val , nil
523
+ if val , ok := s .Data [source .ConfigMapKeyRef .Key ]; ok {
524
+ return source .ConfigMapKeyRef .Key , val , nil
521
525
} else {
522
- return "" , "" , fmt .Errorf ("missing key %s in configmap %s" , source .SecretKeyRef .Key , source .ConfigMapKeyRef .Name )
526
+ return "" , "" , fmt .Errorf ("missing key %s in configmap %s" , source .ConfigMapKeyRef .Key , source .ConfigMapKeyRef .Name )
523
527
}
524
528
}
529
+ return "" , "" , fmt .Errorf ("source couldn't be parsed source: %s" , source )
525
530
}
526
531
527
532
// getDashboardModel resolves datasources, updates uid (if needed) and converts raw json to type grafana client accepts
0 commit comments