{{- if .Values.local.enabled }}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: {{ include "nebulous.localRoleName" . }}
  namespace: {{ include "nebulous.namespace" . }}
  labels:
    {{- include "common.labels" . | nindent 4 }}
rules:
  - apiGroups: ["batch"]
    resources: ["jobs"]
    verbs: ["create", "get", "list", "watch", "delete", "update"]
  - apiGroups: [""]
    resources: ["pods", "services", "secrets", "persistentvolumeclaims", "pods/log"]
    verbs: ["create", "get", "list", "watch", "delete", "update"]
  - apiGroups: ["apps"]
    resources: ["deployments", "deployments/status"]
    verbs: ["create", "get", "list", "watch", "delete", "update"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: {{ include "nebulous.localRoleName" . }}-binding
  namespace: {{ include "nebulous.namespace" . }}
  labels:
    {{- include "common.labels" . | nindent 4 }}
subjects:
  - kind: ServiceAccount
    name: {{ include "nebulous.serviceAccountName" . }}
roleRef:
  kind: Role
  name: {{ include "nebulous.localRoleName" . }}
  apiGroup: rbac.authorization.k8s.io
{{- end }}
