# apiVersion: v1
# kind: PersistentVolumeClaim
# metadata:
#   name: grafana-pvc
#   namespace: josie-health
# spec:
#   accessModes:
#     - ReadWriteOnce
#   storageClassName: customer-workload-storage
#   resources:
#     requests:
#       storage: 2Gi
# ---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana
  namespace: josie-health
spec:
  replicas: 1
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      labels:
        app: grafana
    spec:
      containers:
      - name: grafana
        image: grafana/grafana:10.2.0
        ports:
        - containerPort: 3000
        env:
        - name: GF_SECURITY_ADMIN_PASSWORD
          valueFrom:
            secretKeyRef:
              name: josie-health-secrets
              key: GRAFANA_ADMIN_PASSWORD
        - name: GF_INSTALL_PLUGINS
          value: "grafana-mongodb-datasource,marcusolsson-json-datasource,yesoreyeram-infinity-datasource"
        volumeMounts:
        - name: grafana-provisioning
          mountPath: /etc/grafana/provisioning
        - name: grafana-dashboards
          mountPath: /var/lib/grafana/dashboards
        - name: grafana-datasources
          mountPath: /etc/grafana/provisioning/datasources
        resources:
          requests:
            memory: "256Mi"
            cpu: "100m"
          limits:
            memory: "512Mi"
            cpu: "250m"
      volumes:
      - name: grafana-provisioning
        configMap:
          name: grafana-provisioning
      - name: grafana-dashboards
        configMap:
          name: grafana-dashboards
      - name: grafana-datasources
        configMap:
          name: grafana-provisioning
---
apiVersion: v1
kind: Service
metadata:
  name: grafana
  namespace: josie-health
spec:
  selector:
    app: grafana
  ports:
  - port: 3000
    targetPort: 3000
---
apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: grafana-route
  namespace: josie-health
  annotations:
    cert-manager.io/issuer-kind: ClusterIssuer
    cert-manager.io/issuer-name: letsencrypt-prod
    haproxy.router.openshift.io/redirect-to-https: "true"
spec:
  host: josie.health
  to:
    kind: Service
    name: grafana
  port:
    targetPort: 3000
  tls:
    termination: edge
    insecureEdgeTerminationPolicy: Redirect