Skip to content

Commit

Permalink
Move Grafana setting files to Persistent Volume
Browse files Browse the repository at this point in the history
Signed-off-by: Yanjun Zhou <zhouya@vmware.com>
  • Loading branch information
yanjunz97 committed Aug 9, 2022
1 parent d2bb968 commit 634f01b
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 28 deletions.
8 changes: 8 additions & 0 deletions build/charts/theia/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ Kubernetes: `>= 1.16.0-0`
| grafana.loginSecret | object | `{"password":"admin","username":"admin"}` | Credentials to login to Grafana. They will be stored in a Secret. |
| grafana.service.tcpPort | int | `3000` | TCP port number for the Grafana service. |
| grafana.service.type | string | `"NodePort"` | The type of Service exposing Grafana. It must be one of NodePort or LoadBalancer. |
| grafana.storage.createPersistentVolume.hostPath.path | string | `"/data/grafana"` | The host path. Required when type is "HostPath". |
| grafana.storage.createPersistentVolume.local.affinity | object | `{}` | Affinity for the Local Persistent Volume. By default it requires to label the Node used to store the Grafana configuration files with "antrea.io/grafana-config-node=". |
| grafana.storage.createPersistentVolume.local.path | string | `"/data/grafana"` | The local path. Required when type is "Local". |
| grafana.storage.createPersistentVolume.nfs.host | string | `""` | The NFS server hostname or IP address. Required when type is "NFS". |
| grafana.storage.createPersistentVolume.nfs.path | string | `""` | The path exported on the NFS server. Required when type is "NFS". |
| grafana.storage.createPersistentVolume.type | string | `"HostPath"` | Type of PersistentVolume. Can be set to "HostPath", "Local" or "NFS". Please set this value to use a PersistentVolume created by Theia. |
| grafana.storage.persistentVolumeClaimSpec | object | `{}` | Specification for PersistentVolumeClaim. This is ignored if createPersistentVolume.type is non-empty. To use a custom PersistentVolume, please set storageClassName: "" volumeName: "<my-pv>". To dynamically provision a PersistentVolume, please set storageClassName: "<my-storage-class>". HostPath storage is used if both createPersistentVolume.type and persistentVolumeClaimSpec are empty. |
| grafana.storage.size | string | `"1Gi"` | Grafana storage size. It is used to store Grafana configuration files. Can be a plain integer or as a fixed-point number using one of these quantity suffixes: E, P, T, G, M, K. Or the power-of-two equivalents: Ei, Pi, Ti, Gi, Mi, Ki. |
| sparkOperator.enable | bool | `false` | Determine whether to install Spark Operator. It is required to run Network Policy Recommendation jobs. |
| sparkOperator.image | object | `{"pullPolicy":"IfNotPresent","repository":"projects.registry.vmware.com/antrea/theia-spark-operator","tag":"v1beta2-1.3.3-3.1.1"}` | Container image used by Spark Operator. |
| sparkOperator.name | string | `"policy-recommendation"` | Name of Spark Operator. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ providers:
type: file
allowUiUpdates: true
options:
path: /var/lib/grafana/dashboards
path: /opt/grafana/dashboards
12 changes: 10 additions & 2 deletions build/charts/theia/templates/grafana/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ spec:
fsGroup: 472
supplementalGroups:
- 0
initContainers:
- name: init-pv
image: projects.registry.vmware.com/antrea/busybox
imagePullPolicy: IfNotPresent
command: ["chown", "-R", "472:472", "/data"]
volumeMounts:
- mountPath: /data
name: grafana-pv
containers:
- name: grafana
image: {{ .Values.grafana.image.repository }}:{{ .Values.grafana.image.tag }}
Expand Down Expand Up @@ -78,13 +86,13 @@ spec:
cpu: 250m
memory: 750Mi
volumeMounts:
- mountPath: /data
- mountPath: /var/lib/grafana
name: grafana-pv
- mountPath: /etc/grafana/provisioning/datasources
name: grafana-datasource-provider
- mountPath: /etc/grafana/provisioning/dashboards
name: grafana-dashboard-provider
- mountPath: /var/lib/grafana/dashboards
- mountPath: /opt/grafana/dashboards
name: grafana-dashboard-config
volumes:
- name: grafana-pv
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- if .Values.grafana.enable }}
{{- $customizedPV := or .Values.grafana.storage.createPersistentVolume.type .Values.grafana.storage.persistentVolumeClaimSpec }}
{{- if or (eq .Values.grafana.storage.createPersistentVolume.type "HostPath") (not $customizedPV) }}
apiVersion: v1
kind: PersistentVolume
metadata:
name: grafana-pv
spec:
storageClassName: grafana-storage
capacity:
storage: {{ .Values.grafana.storage.size }}
accessModes:
- ReadWriteOnce
hostPath:
path: {{ .Values.grafana.storage.createPersistentVolume.hostPath.path }}
{{- end }}
{{- end}}
29 changes: 29 additions & 0 deletions build/charts/theia/templates/grafana/local-persistentvolume.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{- if .Values.grafana.enable }}
{{- if eq .Values.grafana.storage.createPersistentVolume.type "Local" }}
apiVersion: v1
kind: PersistentVolume
metadata:
name: grafana-pv
spec:
storageClassName: grafana-storage
capacity:
storage: {{ .Values.grafana.storage.size }}
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
local:
path: {{ .Values.grafana.storage.createPersistentVolume.local.path }}
nodeAffinity:
{{- if .Values.grafana.storage.createPersistentVolume.local.affinity }}
{{- with .Values.grafana.storage.createPersistentVolume.local.affinity }}
{{- toYaml . | trim | nindent 4 }}
{{- end }}
{{- else }}
required:
nodeSelectorTerms:
- matchExpressions:
- key: antrea.io/grafana-config-node
operator: Exists
{{- end }}
{{- end }}
{{- end }}
18 changes: 18 additions & 0 deletions build/charts/theia/templates/grafana/nfs-persistentvolume.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- if .Values.grafana.enable }}
{{- if eq .Values.grafana.storage.createPersistentVolume.type "NFS" }}
apiVersion: v1
kind: PersistentVolume
metadata:
name: grafana-pv
spec:
storageClassName: grafana-storage
capacity:
storage: {{ .Values.grafana.storage.size }}
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
nfs:
path: {{ .Values.grafana.storage.createPersistentVolume.nfs.path }}
server: {{ .Values.grafana.storage.createPersistentVolume.nfs.host }}
{{- end }}
{{- end }}
14 changes: 0 additions & 14 deletions build/charts/theia/templates/grafana/persistentvolume.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ metadata:
name: grafana-pvc
namespace: {{ .Release.Namespace }}
spec:
{{- if .Values.grafana.storage.persistentVolumeClaimSpec }}
{{- with .Values.grafana.storage.persistentVolumeClaimSpec }}
{{- toYaml . | trim | nindent 2 }}
{{- end }}
{{- else }}
storageClassName: grafana-storage
{{- end }}
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storage: {{ .Values.grafana.storage.size }}
{{- end }}
34 changes: 34 additions & 0 deletions build/charts/theia/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,40 @@ grafana:
- pod_to_external_dashboard.json
- node_to_node_dashboard.json
- networkpolicy_dashboard.json
storage:
# -- Grafana storage size. It is used to store Grafana configuration files.
# Can be a plain integer or as a fixed-point number using one of these
# quantity suffixes: E, P, T, G, M, K. Or the power-of-two equivalents:
# Ei, Pi, Ti, Gi, Mi, Ki.
size: "1Gi"
createPersistentVolume:
# -- Type of PersistentVolume. Can be set to "HostPath", "Local" or "NFS". Please set
# this value to use a PersistentVolume created by Theia.
type: "HostPath"
hostPath:
# -- The host path. Required when type is "HostPath".
path: "/data/grafana"
local:
# -- The local path. Required when type is "Local".
path: "/data/grafana"
# -- Affinity for the Local Persistent Volume. By default it requires to label the
# Node used to store the Grafana configuration files with "antrea.io/grafana-config-node=".
affinity: {}
nfs:
# -- The NFS server hostname or IP address. Required when type is "NFS".
host: ""
# -- The path exported on the NFS server. Required when type is "NFS".
path: ""
# -- Specification for PersistentVolumeClaim. This is ignored if createPersistentVolume.type is non-empty.
# To use a custom PersistentVolume, please set
# storageClassName: ""
# volumeName: "<my-pv>".
# To dynamically provision a PersistentVolume, please set
# storageClassName: "<my-storage-class>".
# HostPath storage is used if both createPersistentVolume.type and persistentVolumeClaimSpec are empty.
persistentVolumeClaimSpec: {}
# storageClassName: ""
# volumeName: ""
sparkOperator:
# -- Determine whether to install Spark Operator. It is required to run Network
# Policy Recommendation jobs.
Expand Down
20 changes: 16 additions & 4 deletions build/yamls/flow-visibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4763,7 +4763,7 @@ data:
type: file
allowUiUpdates: true
options:
path: /var/lib/grafana/dashboards
path: /opt/grafana/dashboards
kind: ConfigMap
metadata:
name: grafana-dashboard-provider
Expand Down Expand Up @@ -4868,7 +4868,7 @@ spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 2Gi
storage: 1Gi
hostPath:
path: /data/grafana
storageClassName: grafana-storage
Expand Down Expand Up @@ -4961,14 +4961,26 @@ spec:
cpu: 250m
memory: 750Mi
volumeMounts:
- mountPath: /data
- mountPath: /var/lib/grafana
name: grafana-pv
- mountPath: /etc/grafana/provisioning/datasources
name: grafana-datasource-provider
- mountPath: /etc/grafana/provisioning/dashboards
name: grafana-dashboard-provider
- mountPath: /var/lib/grafana/dashboards
- mountPath: /opt/grafana/dashboards
name: grafana-dashboard-config
initContainers:
- command:
- chown
- -R
- 472:472
- /data
image: projects.registry.vmware.com/antrea/busybox
imagePullPolicy: IfNotPresent
name: init-pv
volumeMounts:
- mountPath: /data
name: grafana-pv
securityContext:
fsGroup: 472
supplementalGroups:
Expand Down
20 changes: 14 additions & 6 deletions docs/network-flow-visibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -741,16 +741,24 @@ Mouse out or click on the background will bring all the traffic back.

### Dashboard Customization

If you would like to make any changes to any of the pre-built dashboards, or build
If you would like to make any change to any of the pre-built dashboards, or build
a new dashboard, please follow this [doc](https://grafana.com/docs/grafana/latest/dashboards/)
on how to build a dashboard.

By clicking on the "Save dashboard" button in the Grafana UI, the changes to the
dashboards will be persisted in the Grafana database at runtime, but they will be
lost after restarting the Grafana deployment. To restore those changes after a restart,
From Theia 0.2, we use PersistentVolume for the Grafana configuration database.
If you create a new dashboard or modify the pre-built dashboards, once you click
on the "Save dashboard" button, the changes will be kept after a Grafana
Deployment restart. Other changes in settings like passwords and preferences will
also be kept. By default, we use HostPath PersistentVolume, which only works when
the Grafana Pod is deployed on the same host. In order to make sure settings are
preserved regardless of where the Grafana Pod is deployed, please choose to use
Local PV, NFS PV or other dynamic provisioning by defining your own StorageClasses.

In Theia 0.1, the changes to dashboards and settings will be lost after restarting
the Grafana Deployment. To restore those changes to dashboards after a restart,
as the first step, you will need to export the dashboard JSON file following the
[doc](https://grafana.com/docs/grafana/latest/dashboards/export-import/), then there
are two ways to import the dashboard depending on your needs:
[doc](https://grafana.com/docs/grafana/latest/dashboards/export-import/),
then there are two ways to import the dashboard depending on your needs:

- In the running Grafana UI, manually import the dashboard JSON files.
- If you want the changed dashboards to be automatically provisioned in Grafana
Expand Down

0 comments on commit 634f01b

Please sign in to comment.