Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix nil pointer exception in jsonnet logic #1435

Merged
merged 1 commit into from
Feb 21, 2024
Merged
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
2 changes: 1 addition & 1 deletion .chainsaw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
spec:
timeouts:
assert: 2m0s
cleanup: 2m0s
cleanup: 3m0s
delete: 2m0s
error: 2m0s
exec: 2m0s
17 changes: 11 additions & 6 deletions controllers/dashboard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,9 @@ func (r *GrafanaDashboardReconciler) fetchDashboardJson(ctx context.Context, das

func (r *GrafanaDashboardReconciler) getDashboardEnvs(ctx context.Context, dashboard *v1beta1.GrafanaDashboard) (map[string]string, error) {
envs := make(map[string]string)
if dashboard.Spec.EnvsFrom == nil && dashboard.Spec.Envs == nil {
return nil, fmt.Errorf("dashboard.Spec.Envs or dashboard.Spec.EnvFrom nil, can't get envs for dashboard: %s", dashboard.Name)
}
if dashboard.Spec.EnvsFrom != nil {
for _, ref := range dashboard.Spec.EnvsFrom {
key, val, err := r.getReferencedValue(ctx, dashboard, ref)
Expand Down Expand Up @@ -508,20 +511,22 @@ func (r *GrafanaDashboardReconciler) getReferencedValue(ctx context.Context, cr
if val, ok := s.Data[source.SecretKeyRef.Key]; ok {
return source.SecretKeyRef.Key, string(val), nil
} else {
return "", "", fmt.Errorf("missing key %s in secret %s", source.SecretKeyRef.Key, source.ConfigMapKeyRef.Name)
return "", "", fmt.Errorf("missing key %s in secret %s", source.SecretKeyRef.Key, source.SecretKeyRef.Name)
}
} else {
}
if source.ConfigMapKeyRef != nil {
s := &v1.ConfigMap{}
err := r.Client.Get(ctx, client.ObjectKey{Namespace: cr.Namespace, Name: source.SecretKeyRef.Name}, s)
err := r.Client.Get(ctx, client.ObjectKey{Namespace: cr.Namespace, Name: source.ConfigMapKeyRef.Name}, s)
if err != nil {
return "", "", err
}
if val, ok := s.Data[source.SecretKeyRef.Key]; ok {
return source.SecretKeyRef.Key, val, nil
if val, ok := s.Data[source.ConfigMapKeyRef.Key]; ok {
return source.ConfigMapKeyRef.Key, val, nil
} else {
return "", "", fmt.Errorf("missing key %s in configmap %s", source.SecretKeyRef.Key, source.ConfigMapKeyRef.Name)
return "", "", fmt.Errorf("missing key %s in configmap %s", source.ConfigMapKeyRef.Key, source.ConfigMapKeyRef.Name)
}
}
return "", "", fmt.Errorf("source couldn't be parsed source: %s", source)
}

// getDashboardModel resolves datasources, updates uid (if needed) and converts raw json to type grafana client accepts
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/example-test/05-dashboard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ spec:
matchLabels:
dashboards: "grafana"
envFrom:
- configMapRef:
- configMapKeyRef:
name: grafana-user-envs
key: "CUSTOM_RANGE_ENV"
plugins:
- name: grafana-piechart-panel
version: 1.3.9
Expand Down