# Copyright 2018 The Knative Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: v1
kind: ConfigMap
metadata:
  name: grafana-datasources
  namespace: knative-monitoring
  labels:
    serving.knative.dev/release: devel
data:
  prometheus.yaml: |+
    datasources:
     - name: prometheus
       type: prometheus
       access: proxy
       org_id: 1
       url: http://prometheus-system-np:8080
       version: 1
       editable: false
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: grafana-dashboards
  namespace: knative-monitoring
  labels:
    serving.knative.dev/release: devel
data:
  dashboards.yaml: |+
    - name: 'knative'
      org_id: 1
      folder: ''
      type: file
      options:
        folder: /grafana-dashboard-definition/knative
    - name: 'knative-efficiency'
      org_id: 1
      folder: ''
      type: file
      options:
        folder: /grafana-dashboard-definition/knative-efficiency
    - name: 'knative-reconciler'
      org_id: 1
      folder: ''
      type: file
      options:
        folder: /grafana-dashboard-definition/knative-reconciler
    - name: 'istio'
      org_id: 1
      folder: ''
      type: file
      options:
        folder: /grafana-dashboard-definition/istio
    - name: 'mixer'
      org_id: 1
      folder: ''
      type: file
      options:
        folder: /grafana-dashboard-definition/mixer
    - name: 'pilot'
      org_id: 1
      folder: ''
      type: file
      options:
        folder: /grafana-dashboard-definition/pilot
    - name: 'kubernetes-deployment'
      org_id: 1
      folder: ''
      type: file
      options:
        folder: /grafana-dashboard-definition/kubernetes-deployment
    - name: 'kubernetes-capacity-planning'
      org_id: 1
      folder: ''
      type: file
      options:
        folder: /grafana-dashboard-definition/kubernetes-capacity-planning
    - name: 'kubernetes-cluster-health'
      org_id: 1
      folder: ''
      type: file
      options:
        folder: /grafana-dashboard-definition/kubernetes-cluster-health
    - name: 'kubernetes-cluster-status'
      org_id: 1
      folder: ''
      type: file
      options:
        folder: /grafana-dashboard-definition/kubernetes-cluster-status
    - name: 'kubernetes-control-plane-status'
      org_id: 1
      folder: ''
      type: file
      options:
        folder: /grafana-dashboard-definition/kubernetes-control-plane-status
    - name: 'kubernetes-resource-requests'
      org_id: 1
      folder: ''
      type: file
      options:
        folder: /grafana-dashboard-definition/kubernetes-resource-requests
    - name: 'kubernetes-nodes'
      org_id: 1
      folder: ''
      type: file
      options:
        folder: /grafana-dashboard-definition/kubernetes-nodes
    - name: 'kubernetes-pods'
      org_id: 1
      folder: ''
      type: file
      options:
        folder: /grafana-dashboard-definition/kubernetes-pods
    - name: 'kubernetes-statefulset'
      org_id: 1
      folder: ''
      type: file
      options:
        folder: /grafana-dashboard-definition/kubernetes-statefulset
    - name: 'knative-serving-scaling'
      org_id: 1
      folder: ''
      type: file
      options:
        folder: /grafana-dashboard-definition/scaling
---
apiVersion: v1
kind: Service
metadata:
  name: grafana
  namespace: knative-monitoring
  labels:
    app: grafana
    serving.knative.dev/release: devel
spec:
  type: NodePort
  ports:
  - port: 30802
    protocol: TCP
    targetPort: 3000
  selector:
    app: grafana
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana
  namespace: knative-monitoring
  labels:
    serving.knative.dev/release: devel
spec:
  replicas: 1
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      labels:
        app: grafana
        serving.knative.dev/release: devel
    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser: 65534
      containers:
      - name: grafana
        image: quay.io/coreos/monitoring-grafana:5.0.3
        volumeMounts:
        - name: grafana-storage
          mountPath: /data
        - name: grafana-datasources
          mountPath: /grafana/conf/provisioning/datasources
        - name: grafana-dashboards
          mountPath: /grafana/conf/provisioning/dashboards
        - name: grafana-dashboard-definition-knative
          mountPath: /grafana-dashboard-definition/knative
        - name: grafana-dashboard-definition-knative-efficiency
          mountPath: /grafana-dashboard-definition/knative-efficiency
        - name: grafana-dashboard-definition-knative-reconciler
          mountPath: /grafana-dashboard-definition/knative-reconciler
        - name: grafana-dashboard-definition-istio
          mountPath: /grafana-dashboard-definition/istio
        - name: grafana-dashboard-definition-mixer
          mountPath: /grafana-dashboard-definition/mixer
        - name: grafana-dashboard-definition-pilot
          mountPath: /grafana-dashboard-definition/pilot
        - name: grafana-dashboard-definition-kubernetes-deployment
          mountPath: /grafana-dashboard-definition/kubernetes-deployment
        - name: grafana-dashboard-definition-kubernetes-capacity-planning
          mountPath: /grafana-dashboard-definition/kubernetes-capacity-planning
        - name: grafana-dashboard-definition-kubernetes-cluster-health
          mountPath: /grafana-dashboard-definition/kubernetes-cluster-health
        - name: grafana-dashboard-definition-kubernetes-cluster-status
          mountPath: /grafana-dashboard-definition/kubernetes-cluster-status
        - name: grafana-dashboard-definition-kubernetes-control-plane-status
          mountPath: /grafana-dashboard-definition/kubernetes-control-plane-status
        - name: grafana-dashboard-definition-kubernetes-resource-requests
          mountPath: /grafana-dashboard-definition/kubernetes-resource-requests
        - name: grafana-dashboard-definition-kubernetes-nodes
          mountPath: /grafana-dashboard-definition/kubernetes-nodes
        - name: grafana-dashboard-definition-kubernetes-pods
          mountPath: /grafana-dashboard-definition/kubernetes-pods
        - name: grafana-dashboard-definition-kubernetes-statefulset
          mountPath: /grafana-dashboard-definition/kubernetes-statefulset
        - name: scaling-config
          mountPath: /grafana-dashboard-definition/scaling  
        ports:
        - name: web
          containerPort: 3000
        resources:
          requests:
            memory: 100Mi
            cpu: 100m
          limits:
            memory: 200Mi
            cpu: 200m
      volumes:
      - name: grafana-storage
        emptyDir: {}
      - name: grafana-datasources
        configMap:
          name: grafana-datasources
      - name: grafana-dashboards
        configMap:
          name: grafana-dashboards
      - name: grafana-dashboard-definition-knative
        configMap:
          name: grafana-dashboard-definition-knative
      - name: grafana-dashboard-definition-knative-efficiency
        configMap:
          name: grafana-dashboard-definition-knative-efficiency
      - name: grafana-dashboard-definition-knative-reconciler
        configMap:
          name: grafana-dashboard-definition-knative-reconciler
      - name: grafana-dashboard-definition-istio
        configMap:
          name: grafana-dashboard-definition-istio
      - name: grafana-dashboard-definition-mixer
        configMap:
          name: grafana-dashboard-definition-mixer
      - name: grafana-dashboard-definition-pilot
        configMap:
          name: grafana-dashboard-definition-pilot
      - name: grafana-dashboard-definition-kubernetes-deployment
        configMap:
          name: grafana-dashboard-definition-kubernetes-deployment
      - name: grafana-dashboard-definition-kubernetes-capacity-planning
        configMap:
          name: grafana-dashboard-definition-kubernetes-capacity-planning
      - name: grafana-dashboard-definition-kubernetes-cluster-health
        configMap:
          name: grafana-dashboard-definition-kubernetes-cluster-health
      - name: grafana-dashboard-definition-kubernetes-cluster-status
        configMap:
          name: grafana-dashboard-definition-kubernetes-cluster-status
      - name: grafana-dashboard-definition-kubernetes-control-plane-status
        configMap:
          name: grafana-dashboard-definition-kubernetes-control-plane-status
      - name: grafana-dashboard-definition-kubernetes-resource-requests
        configMap:
          name: grafana-dashboard-definition-kubernetes-resource-requests
      - name: grafana-dashboard-definition-kubernetes-nodes
        configMap:
          name: grafana-dashboard-definition-kubernetes-nodes
      - name: grafana-dashboard-definition-kubernetes-pods
        configMap:
          name: grafana-dashboard-definition-kubernetes-pods
      - name: grafana-dashboard-definition-kubernetes-statefulset
        configMap:
          name: grafana-dashboard-definition-kubernetes-statefulset
      - name: scaling-config
        configMap:
          name: scaling-config
---
