Create a configmap per dashboard

I the dashboard files got too large (>2Mb) Kubernetes was rejecting
the configmap.

Now each dashboard is installed with an own configmap. A sidecar container
is used to register these dashboards with Grafana.

Change-Id: I84062d6e2ac7dc2669945b54575bf239a25900a4
This commit is contained in:
Thomas Draebing 2020-03-26 09:55:39 +01:00
parent 6d3c31e50c
commit 623332e4b3
8 changed files with 27 additions and 26 deletions

View file

@ -337,20 +337,7 @@ notifiers: {}
##
## `path` must be /var/lib/grafana/dashboards/<provider_name>
##
dashboardProviders:
dashboardproviders.yaml:
apiVersion: 1
providers:
- name: 'gerrit'
orgId: 1
folder: ''
type: file
disableDeletion: true
editable: #@ data.values.grafana.dashboards.editable
updateIntervalSeconds: 60
allowUiUpdates: #@ data.values.grafana.dashboards.editable
options:
path: /var/lib/grafana/dashboards/gerrit
dashboardProviders: {}
## Configure grafana dashboard to import
## NOTE: To use dashboards you must also enable/configure dashboardProviders
@ -383,8 +370,7 @@ dashboards: {}
## example-dashboard.json: |
## RAW_JSON
##
dashboardsConfigMaps:
gerrit: "grafana-dashboards"
dashboardsConfigMaps: {}
## Grafana's primary configuration
## NOTE: values in map will be converted to ini format
@ -459,14 +445,14 @@ sidecar:
# skipTlsVerify Set to true to skip tls verification for kube api calls
# skipTlsVerify: true
dashboards:
enabled: false
enabled: true
## Method to use to detect ConfigMap changes. With WATCH the sidecar will do a WATCH requests, with SLEEP it will list all ConfigMaps, then sleep for 60 seconds.
watchMethod: WATCH
SCProvider: true
# label that the configmaps with dashboards are marked with
label: grafana_dashboard
# folder in the pod that should hold the collected dashboards (unless `defaultFolderName` is set)
folder: /tmp/dashboards
folder: /var/dashboards
# The default folder name, it will create a subfolder under the `folder` and put dashboards in there instead
defaultFolderName: null
# If specified, the sidecar will search for dashboard config-maps inside this namespace.
@ -484,9 +470,9 @@ sidecar:
# type of the provider
type: file
# disableDelete to activate a import-only behaviour
disableDelete: false
disableDelete: true
# allow updating provisioned dashboards from the UI
allowUiUpdates: false
allowUiUpdates: #@ data.values.grafana.dashboards.editable
datasources:
enabled: false
## Method to use to detect ConfigMap changes. With WATCH the sidecar will do a WATCH requests, with SLEEP it will list all ConfigMaps, then sleep for 60 seconds.

View file

@ -74,6 +74,23 @@ function addHtpasswdEntryEncrypted() {
sops --set "$COMPONENT['htpasswd'] \"$HTPASSWD\"" $TMP_CONFIG
}
function addDashboards() {
for dashboard in dashboards/*; do
local DASHBOARD_NAME="${dashboard%.json}"
local DASHBOARD_NAME="${DASHBOARD_NAME#"dashboards/"}"
kubectl create configmap $DASHBOARD_NAME \
--from-file=$dashboard \
--dry-run=true \
--namespace=$NAMESPACE \
-o yaml > $OUTPUT/dashboards/$DASHBOARD_NAME.dashboard.yaml
yq w -i $OUTPUT/dashboards/$DASHBOARD_NAME.dashboard.yaml \
metadata.labels.grafana_dashboard $DASHBOARD_NAME
done
}
function runYtt() {
ytt \
-f charts/namespace.yaml \
@ -100,18 +117,16 @@ else
echo -e "#@data/values\n---\n$(sops -d $TMP_CONFIG)" | runYtt -
fi
# Create configmap with dashboards
kubectl create configmap grafana-dashboards \
--from-file=./dashboards \
--dry-run=true \
--namespace=$NAMESPACE \
-o yaml > $OUTPUT/configuration/dashboards.cm.yaml
# Create configmaps with dashboards
mkdir -p $OUTPUT/dashboards
addDashboards
test -n "$DRYRUN" && exit 0
# Install loose components
kubectl apply -f $OUTPUT/namespace.yaml
kubectl apply -f $OUTPUT/configuration
kubectl apply -f $OUTPUT/dashboardsq
kubectl apply -f $OUTPUT/storage
# Add Loki helm repository