Helm persistent volume type selection between EBS and NFS?

2/18/2019

I need help with "if" statements in my Prometheus Helm chart. What I am trying to achieve is Prometheus chart with persistent volumes in EBS or NFS. It works fine for EBS, but it doesn't work for NFS. I think the problem is with my if statement logic.

When I set storageClass: "nfs" values.yaml, then I am gettting error:

Error: release prometheus failed: PersistentVolume "prometheus-alertmanager" is invalid: spec: Required value: must specify a volume type

In my values.yaml file I have:

  persistentVolume:
    enabled: true
    accessModes:
      - ReadWriteOnce
    annotations: {}
    existingClaim: ""
    mountPath: /data
    subPath: "alertmanager/"
    size: 4Gi
    ReclaimPolicy: "Recycle"
    storageClass: "aws"
    volumeID: "vol-xxx"
    fs_mounts:
      path: /data/alertmanager
      server: 127.0.0.1

The difference for Prometheus server is in subPath and in path under fs_mounts.

In my alertmanager-pv I have:

{{- if not .Values.alertmanager.statefulSet.enabled -}}
{{- if and .Values.alertmanager.enabled .Values.alertmanager.persistentVolume.enabled -}}
apiVersion: v1
kind: PersistentVolume
metadata:
  name: prometheus-alertmanager
spec:
  capacity:
    storage: {{ .Values.alertmanager.persistentVolume.size }}
  accessModes:
{{ toYaml .Values.alertmanager.persistentVolume.accessModes | indent 4 }}
  persistentVolumeReclaimPolicy: "{{ .Values.alertmanager.persistentVolume.ReclaimPolicy }}"
{{- if (eq "aws" .Values.alertmanager.persistentVolume.storageClass) }}
  storageClassName: "gp2"
  awsElasticBlockStore:
    fsType: "ext4"
    volumeID: {{ .Values.alertmanager.persistentVolume.volumeID }}
{{- if (eq "nfs" .Values.alertmanager.persistentVolume.storageClass) }}
  StorageClassName: "nfs"
    mountOptions:
      - hard
      - nfsvers=4.1
      - timeo=600
      - retrans=2
    nfs:
      server: {{ .Values.alertmanager.persistentVolume.fs_mounts.server }}
      path: {{ .Values.alertmanager.persistentVolume.fs_mounts.path }}
{{- end }}
{{- end }}
{{- end -}}
{{- end -}}

and in alertmanager-pvc:

{{- if not .Values.alertmanager.statefulSet.enabled -}}
{{- if and .Values.alertmanager.enabled .Values.alertmanager.persistentVolume.enabled -}}
{{- if not .Values.alertmanager.persistentVolume.existingClaim -}}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
  name: prometheus-alertmanager
spec:
  accessModes:
{{ toYaml .Values.alertmanager.persistentVolume.accessModes | indent 4 }}
{{- if (eq "aws" .Values.alertmanager.persistentVolume.storageClass) }}
  storageClassName: "gp2"
  resources:
    requests:
      storage: {{ .Values.alertmanager.persistentVolume.size }}
{{- if (eq "nfs" .Values.alertmanager.persistentVolume.storageClass) }}
  storageClassName: "nfs"
  resources:
    requests:
      storage: {{ .Values.alertmanager.persistentVolume.size }}
{{- end }}
{{- end }}
{{- end -}}
{{- end -}}
{{- end -}}
-- Syn Romana
if-statement
kubernetes-helm
persistent-storage

1 Answer

2/18/2019

The problem was with wrong idents in nfs if statement.

-- Syn Romana
Source: StackOverflow