{{- if .Values.rbacEnable }}
{{- if .Capabilities.APIVersions.Has "rbac.authorization.k8s.io/v1beta1" }}
apiVersion: rbac.authorization.k8s.io/v1beta1
{{- else if .Capabilities.APIVersions.Has "rbac.authorization.k8s.io/v1alpha1" }}
apiVersion: rbac.authorization.k8s.io/v1alpha1
{{- end }}
kind: ClusterRole
metadata:
  labels:
    app: {{ template "name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version }}
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
  name: {{ template "fullname" . }}
rules:
  - apiGroups: [""]
    resources: ["configmaps", "secrets"]
    verbs: ["*"]

  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["delete", "list"]

  - apiGroups: [""]
    resources: ["services", "endpoints"]
    verbs: ["create", "get", "update"]

  - apiGroups: [""]
    resources: ["nodes"]
    verbs: ["list", "watch"]

  - apiGroups: ["apps"]
    resources: ["statefulsets"]
    verbs: ["*"]

  - apiGroups: ["extensions"]
    resources: ["thirdpartyresources"]
    verbs: ["create", "get"]

  - apiGroups: ["monitoring.coreos.com"]
    resources: ["alertmanagers", "prometheuses", "servicemonitors"]
    verbs: ["*"]
{{- end }}

{{- if .Values.rbacEnable }}
{{- if .Capabilities.APIVersions.Has "rbac.authorization.k8s.io/v1beta1" }}
apiVersion: rbac.authorization.k8s.io/v1beta1
{{- else if .Capabilities.APIVersions.Has "rbac.authorization.k8s.io/v1alpha1" }}
apiVersion: rbac.authorization.k8s.io/v1alpha1
{{- end }}
kind: ClusterRole
metadata:
  labels:
    app: {{ template "name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version }}
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
  name: {{ template "fullname" . }}
rules:
  - apiGroups: [""]
    resources: ["configmaps", "secrets"]
    verbs: ["*"]

  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["delete", "list"]

  - apiGroups: [""]
    resources: ["services", "endpoints"]
    verbs: ["create", "get", "update"]

  - apiGroups: [""]
    resources: ["nodes"]
    verbs: ["list", "watch"]

  - apiGroups: ["apps"]
    resources: ["statefulsets"]
    verbs: ["*"]

  - apiGroups: ["apiextensions.k8s.io"]
    resources: ["customresourcedefinitions"]
    verbs: ["create", "get"]

  - apiGroups: ["monitoring.coreos.com"]
    resources: ["alertmanagers", "prometheuses", "servicemonitors"]
    verbs: ["*"]
{{- end }}

Fix RBAC support for CRD
Fix RBAC support for CRD
