apiVersion: rbac.authorization.k8s.io/v1
{{- if .Values.restrictedNamespace }}
kind: Role
{{- else }}
kind: ClusterRole
{{- end }}
metadata:
  name: {{ include "nemo-kubernetes-operator.fullname" . }}-manager-role
{{- if .Values.restrictedNamespace }}
  namespace: {{ .Values.restrictedNamespace }}
{{- end }}
  labels:
  {{- include "nemo-kubernetes-operator.labels" . | nindent 4 }}
rules:
- apiGroups:
  - ""
  resources:
  - persistentvolumeclaims
  verbs:
  - create
  - delete
  - get
  - list
  - watch
- apiGroups:
  - batch
  resources:
  - jobs
  verbs:
  - create
  - delete
  - get
  - list
  - patch
  - update
  - watch
{{- if eq .Values.controllerManager.manager.scheduler "volcano" }}
- apiGroups:
  - batch.volcano.sh
  resources:
  - jobs
  verbs:
  - create
  - delete
  - get
  - list
  - patch
  - update
  - watch
- apiGroups:
  - scheduling.volcano.sh
  resources:
  - podgroups
  verbs:
  - get
  - list
  - watch
{{- end }}
- apiGroups:
  - nvidia.com
  resources:
  - nemoentityhandlers
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - nvidia.com
  resources:
  - nemotrainingjobs
  verbs:
  - create
  - delete
  - get
  - list
  - patch
  - update
  - watch
- apiGroups:
  - nvidia.com
  resources:
  - nemotrainingjobs/finalizers
  verbs:
  - update
- apiGroups:
  - nvidia.com
  resources:
  - nemotrainingjobs/status
  verbs:
  - get
  - patch
  - update
- apiGroups:
  - nvidia.com
  resources:
  - nemotrainingworkloads
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - nvidia.com
  resources:
  - nemovalidationjobs
  verbs:
  - create
  - delete
  - get
  - list
  - patch
  - update
  - watch
- apiGroups:
  - nvidia.com
  resources:
  - nemovalidationjobs/finalizers
  verbs:
  - update
- apiGroups:
  - nvidia.com
  resources:
  - nemovalidationjobs/status
  verbs:
  - get
  - patch
  - update
{{- if eq .Values.controllerManager.manager.scheduler "runai" }}
- apiGroups:
  - run.ai
  resources:
  - trainingworkloads
  verbs:
  - create
  - delete
  - get
  - list
  - patch
  - update
  - watch
{{- end }}
---
apiVersion: rbac.authorization.k8s.io/v1
{{- if .Values.restrictedNamespace }}
kind: RoleBinding
{{- else }}
kind: ClusterRoleBinding
{{- end }}
metadata:
  name: {{ include "nemo-kubernetes-operator.fullname" . }}-manager-rolebinding
{{- if .Values.restrictedNamespace }}
  namespace: {{ .Values.restrictedNamespace }}
{{- end }}
  labels:
    app.kubernetes.io/component: rbac
    app.kubernetes.io/created-by: nemo-kubernetes-operator
    app.kubernetes.io/part-of: nemo-kubernetes-operator
  {{- include "nemo-kubernetes-operator.labels" . | nindent 4 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
{{- if .Values.restrictedNamespace }}
  kind: Role
{{- else }}
  kind: ClusterRole
{{- end }} 
  name: '{{ include "nemo-kubernetes-operator.fullname" . }}-manager-role'
subjects:
- kind: ServiceAccount
  name: '{{ include "nemo-kubernetes-operator.fullname" . }}-controller-manager'
  namespace: '{{ .Release.Namespace }}'