{{ if .Values.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: {{ template "stash.fullname" . }}
  labels:
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    app: "{{ template "stash.name" . }}"
    heritage: "{{ .Release.Service }}"
    release: "{{ .Release.Name }}"
rules:
- apiGroups:
  - apiextensions.k8s.io
  resources:
  - customresourcedefinitions
  verbs:
  - "*"
- apiGroups:
  - extensions
  resources:
  - thirdpartyresources
  verbs:
  - "*"
- apiGroups:
  - stash.appscode.com
  resources: ["*"]
  verbs: ["*"]
- apiGroups:
  - apps
  resources:
  - deployments
  - statefulsets
  verbs: ["get", "list", "watch", "patch"]
- apiGroups:
  - batch
  resources:
  - jobs
  - cronjobs
  verbs: ["get", "list", "watch", "create", "delete", "patch"]
- apiGroups:
  - extensions
  resources:
  - replicasets
  - daemonsets
  verbs: ["get", "list", "watch", "patch"]
- apiGroups: [""]
  resources:
  - namespaces
  - replicationcontrollers
  verbs: ["get", "list", "watch", "patch"]
- apiGroups: [""]
  resources:
  - configmaps
  verbs: ["create", "update", "get", "delete"]
- apiGroups: [""]
  resources:
  - secrets
  verbs: ["get"]
- apiGroups: [""]
  resources:
  - events
  verbs: ["create"]
- apiGroups: [""]
  resources:
  - nodes
  verbs: ["list"]
- apiGroups: [""]
  resources:
  - pods
  verbs: ["get", "create", "list", "delete", "deletecollection"]
- apiGroups: [""]
  resources:
  - serviceaccounts
  verbs: ["get", "create", "patch", "delete"]
- apiGroups:
  - rbac.authorization.k8s.io
  resources:
  - clusterroles
  - roles
  - rolebindings
  verbs: ["get", "create", "delete", "patch"]
{{ end }}
