{{- if .Values.podSecurityPolicy.enabled }}
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
  name: {{ include "aitbc-coordinator.fullname" . }}
  labels:
    {{- include "aitbc-coordinator.labels" . | nindent 4 }}
spec:
  privileged: false
  allowPrivilegeEscalation: false
  requiredDropCapabilities:
    - ALL
  volumes:
    - 'configMap'
    - 'emptyDir'
    - 'projected'
    - 'secret'
    - 'downwardAPI'
    - 'persistentVolumeClaim'
  runAsUser:
    rule: 'MustRunAsNonRoot'
  seLinux:
    rule: 'RunAsAny'
  fsGroup:
    rule: 'RunAsAny'
  readOnlyRootFilesystem: false
  securityContext:
    runAsNonRoot: true
    runAsUser: 1000
    fsGroup: 1000
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: {{ include "aitbc-coordinator.fullname" }}-psp
  labels:
    {{- include "aitbc-coordinator.labels" . | nindent 4 }}
rules:
- apiGroups: ['policy']
  resources: ['podsecuritypolicies']
  verbs: ['use']
  resourceNames:
  - {{ include "aitbc-coordinator.fullname" . }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: {{ include "aitbc-coordinator.fullname" }}-psp
  labels:
    {{- include "aitbc-coordinator.labels" . | nindent 4 }}
roleRef:
  kind: Role
  name: {{ include "aitbc-coordinator.fullname" }}-psp
  apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
  name: {{ include "aitbc-coordinator.serviceAccountName" . }}
  namespace: {{ .Release.Namespace }}
{{- end }}
