{{- if .Values.podSecurityPolicy.enabled }}
kind: PodSecurityPolicy
apiVersion: policy/v1beta1
metadata:
  name: {{ include "capsule.fullname" . }}
  labels:
    {{- include "capsule.labels" . | nindent 4 }}
  {{- with .Values.customAnnotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  fsGroup:
    rule: RunAsAny
  hostPorts:
  - max: 0
    min: 0
  runAsUser:
    rule: RunAsAny
  seLinux:
    rule: RunAsAny
  supplementalGroups:
    rule: RunAsAny
  volumes:
  - secret
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ include "capsule.fullname" . }}-use-psp
  labels:
    {{- include "capsule.labels" . | nindent 4 }}
rules:
- apiGroups:
  - extensions
  resources:
  - podsecuritypolicies
  resourceNames:
  - {{ include "capsule.fullname" . }}
  verbs:
  - use
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ include "capsule.fullname" . }}-use-psp
  labels:
    {{- include "capsule.labels" . | nindent 4 }}
  namespace: {{ .Release.Namespace }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ include "capsule.fullname" . }}-use-psp
subjects:
- apiGroup: ""
  kind: ServiceAccount
  name: {{ include "capsule.serviceAccountName" . }}
{{- end }}
