diff --git a/build/charts/theia/README.md b/build/charts/theia/README.md index 14ab6d2b7..09d245120 100644 --- a/build/charts/theia/README.md +++ b/build/charts/theia/README.md @@ -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: "". To dynamically provision a PersistentVolume, please set storageClassName: "". 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. | diff --git a/build/charts/theia/provisioning/dashboards/dashboard_provider.yaml b/build/charts/theia/provisioning/dashboards/dashboard_provider.yaml index 0e24accaa..01b373a30 100644 --- a/build/charts/theia/provisioning/dashboards/dashboard_provider.yaml +++ b/build/charts/theia/provisioning/dashboards/dashboard_provider.yaml @@ -5,4 +5,4 @@ providers: type: file allowUiUpdates: true options: - path: /var/lib/grafana/dashboards + path: /opt/grafana/dashboards diff --git a/build/charts/theia/templates/grafana/deployment.yaml b/build/charts/theia/templates/grafana/deployment.yaml index 4e5a075ba..4549678a9 100644 --- a/build/charts/theia/templates/grafana/deployment.yaml +++ b/build/charts/theia/templates/grafana/deployment.yaml @@ -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 }} @@ -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 diff --git a/build/charts/theia/templates/grafana/hostpath-persistentvolume.yaml b/build/charts/theia/templates/grafana/hostpath-persistentvolume.yaml new file mode 100644 index 000000000..9e3347726 --- /dev/null +++ b/build/charts/theia/templates/grafana/hostpath-persistentvolume.yaml @@ -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}} \ No newline at end of file diff --git a/build/charts/theia/templates/grafana/local-persistentvolume.yaml b/build/charts/theia/templates/grafana/local-persistentvolume.yaml new file mode 100644 index 000000000..c5e742e34 --- /dev/null +++ b/build/charts/theia/templates/grafana/local-persistentvolume.yaml @@ -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 }} diff --git a/build/charts/theia/templates/grafana/nfs-persistentvolume.yaml b/build/charts/theia/templates/grafana/nfs-persistentvolume.yaml new file mode 100644 index 000000000..e977f8fe9 --- /dev/null +++ b/build/charts/theia/templates/grafana/nfs-persistentvolume.yaml @@ -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 }} diff --git a/build/charts/theia/templates/grafana/persistentvolume.yaml b/build/charts/theia/templates/grafana/persistentvolume.yaml deleted file mode 100644 index c22862b91..000000000 --- a/build/charts/theia/templates/grafana/persistentvolume.yaml +++ /dev/null @@ -1,14 +0,0 @@ -{{- if .Values.grafana.enable }} -apiVersion: v1 -kind: PersistentVolume -metadata: - name: grafana-pv -spec: - storageClassName: grafana-storage - capacity: - storage: 2Gi - accessModes: - - ReadWriteOnce - hostPath: - path: "/data/grafana" -{{- end }} diff --git a/build/charts/theia/templates/grafana/persistentvolumeclaim.yaml b/build/charts/theia/templates/grafana/persistentvolumeclaim.yaml index 56a0e920d..012c55e61 100644 --- a/build/charts/theia/templates/grafana/persistentvolumeclaim.yaml +++ b/build/charts/theia/templates/grafana/persistentvolumeclaim.yaml @@ -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 }} diff --git a/build/charts/theia/values.yaml b/build/charts/theia/values.yaml index 32d0320d1..c88d685dd 100644 --- a/build/charts/theia/values.yaml +++ b/build/charts/theia/values.yaml @@ -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: "". + # To dynamically provision a PersistentVolume, please set + # storageClassName: "". + # 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. diff --git a/build/yamls/flow-visibility.yml b/build/yamls/flow-visibility.yml index 909c594b5..bf38f5e96 100644 --- a/build/yamls/flow-visibility.yml +++ b/build/yamls/flow-visibility.yml @@ -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 @@ -4868,7 +4868,7 @@ spec: accessModes: - ReadWriteOnce capacity: - storage: 2Gi + storage: 1Gi hostPath: path: /data/grafana storageClassName: grafana-storage @@ -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: diff --git a/docs/network-flow-visibility.md b/docs/network-flow-visibility.md index 13c4db2cb..abb171b17 100644 --- a/docs/network-flow-visibility.md +++ b/docs/network-flow-visibility.md @@ -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