{{- if .Values.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: {{ template "k8s-spot-termination-handler.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ template "k8s-spot-termination-handler.name" . }}
    helm.sh/chart: {{ template "k8s-spot-termination-handler.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
rules:
  # For draining nodes
  - apiGroups:
      - ""
    resources:
      - nodes
    verbs:
      - get
      - list
      - patch
  - apiGroups:
      - ""
    resources:
      - pods
    verbs:
      - get
      - list
  - apiGroups:
      - extensions
    resources:
      - replicasets
      - daemonsets
    verbs:
      - get
      - list
  - apiGroups:
      - apps
    resources:
      - statefulsets
    verbs:
      - get
      - list
  - apiGroups:
      - ""
    resources:
      - pods/eviction
    verbs:
      - create
{{- end}}
