diff --git a/manifests/grafana-deployment.yaml b/manifests/grafana-deployment.yaml index 2c3c7b2..74bc1a2 100644 --- a/manifests/grafana-deployment.yaml +++ b/manifests/grafana-deployment.yaml @@ -88,8 +88,9 @@ spec: runAsUser: 65534 serviceAccountName: grafana volumes: - - emptyDir: {} - name: grafana-storage + - name: grafana-storage + persistentVolumeClaim: + claimName: grafana-storage - name: grafana-datasources secret: secretName: grafana-datasources diff --git a/manifests/grafana-storage.yaml b/manifests/grafana-storage.yaml new file mode 100644 index 0000000..e5a18b6 --- /dev/null +++ b/manifests/grafana-storage.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: grafana-storage + namespace: monitoring +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 2Gi diff --git a/operator_stack.jsonnet b/operator_stack.jsonnet index c271ebd..d36b052 100644 --- a/operator_stack.jsonnet +++ b/operator_stack.jsonnet @@ -89,46 +89,36 @@ local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') + }, }, - # Override command for Grafana persist data - // grafana+:: { - // local pvc = k.core.v1.persistentVolumeClaim, - // local deployment = k.apps.v1beta2.deployment, - // local container = deployment.mixin.spec.template.spec.containersType, - // local containerVolumeMount = container.volumeMountsType, - // local volume = deployment.mixin.spec.template.spec.volumesType, - // local grafanaStorage = pvc.new() + pvc.mixin.metadata.withNamespace($._config.namespace) + - // pvc.mixin.metadata.withName("grafana-storage") + - // pvc.mixin.spec.withAccessModes('ReadWriteMany') + - // pvc.mixin.spec.resources.withRequests({ storage: '2Gi' }), - // deployment+: { - // // local storageVolumeName = grafanaStorage, - // // local storageVolume = volume.fromPersistentVolumeClaim(grafanaStorage), - // // }, - // // { - // spec+: { - // template+: { - // spec+: { - // containers: - // std.map( - // function(c) - // if c.name == 'grafana' then - // c { - // volumeMounts+: [ - // containerVolumeMount.new("grafana-storage", "/var/lib/grafana"), - // ], - // } - // else - // c, - // super.containers, - // ), - // volumes+: [ - // volume.fromPersistentVolumeClaim(grafanaStorage, "grafana-storage"), - // ], - // }, - // }, - // }, - // }, - // }, + # Override deployment for Grafana data persistence + grafana+:: { + deployment+: { + spec+: { + template+: { + spec+: { + volumes: + std.map( + function(v) + if v.name == 'grafana-storage' then + {'name':'grafana-storage', + 'persistentVolumeClaim': { + 'claimName': 'grafana-storage'} + } + else + v, + super.volumes + ), + }, + }, + }, + }, + storage: + local pvc = k.core.v1.persistentVolumeClaim; + local deployment = k.apps.v1beta2.deployment; + pvc.new() + pvc.mixin.metadata.withNamespace($._config.namespace) + + pvc.mixin.metadata.withName("grafana-storage") + + pvc.mixin.spec.withAccessModes('ReadWriteMany') + + pvc.mixin.spec.resources.withRequests({ storage: '2Gi' }), + }, // Add custom dashboards grafanaDashboards+:: {