apiVersion: v1
kind: Pod
metadata:
  name: grafana-configure
spec:
  restartPolicy: Never
  containers:
  - name: grafana-configure
    image: utkarshcmu/wizzy
    imagePullPolicy: IfNotPresent
    env:
      - name: GRAFANA_USER
        valueFrom:
          secretKeyRef:
            name: metricviz-grafana
            key: grafana-admin-user
      - name: GRAFANA_PASS
        valueFrom:
          secretKeyRef:
            name: metricviz-grafana
            key: grafana-admin-password
      - name: GRAFANA_HOST
        value: http://metricviz-grafana
    command: ["sh"]
    args:
      - "-c"
      - "wizzy init && wizzy set grafana username $(GRAFANA_USER) && wizzy set grafana password $(GRAFANA_PASS) && wizzy set grafana url $(GRAFANA_HOST) && mkdir datasources && for x in $(ls -1 datasources-mount); do cat datasources-mount/$x > datasources/$x; done && mkdir dashboards && for x in $(ls -1 dashboards-mount); do cat dashboards-mount/$x > dashboards/$x; done && wizzy export datasources && wizzy export dashboards"
    volumeMounts:
    - name: grafana-dashboards
      mountPath: /app/dashboards-mount
    - name: grafana-datasources
      mountPath: /app/datasources-mount
  volumes:
  - name: grafana-dashboards
    configMap:
      name: grafana-dashboards
  - name: grafana-datasources
    configMap:
      name: grafana-datasources
