{{- if and .Values.rbac.pspEnabled (.Capabilities.APIVersions.Has "policy/v1beta1/PodSecurityPolicy") }}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: {{ template "sscdpa.fullname" . }}
  namespace: {{ .Release.Namespace }}
{{ include "sscdpa.labels" . | indent 2 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: {{ template "sscdpa.psp.fullname" . }}
subjects:
  - kind: ServiceAccount
    name: csi-secrets-store-provider-azure
    namespace: {{ .Release.Namespace }}
{{- end }}
---
{{- if .Values.enableArcExtension }}
{{- if and .Values.Azure.Identity.isEnabled .Values.arc.enableMonitoring }}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: arc-extension-identity-role-binding
  namespace: {{ .Release.Namespace }}
  labels:
{{ include "sscdpa.arc.labels" . | indent 4 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: arc-extension-identity-role
subjects:
  - kind: ServiceAccount
    name: csi-secrets-store-provider-azure
    namespace: {{ .Release.Namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: arc-telegraf-role-binding
  namespace: {{ .Release.Namespace }}
  labels:
{{ include "sscdpa.arc.labels" . | indent 4 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: arc-telegraf-role
subjects:
  - kind: ServiceAccount
    name: csi-secrets-store-provider-azure
    namespace: {{ .Release.Namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: arc-geneva-role-binding
  labels:
{{ include "sscdpa.arc.labels" . | indent 4 }}
roleRef:
  kind: ClusterRole
  name: arc-geneva-role
  apiGroup: rbac.authorization.k8s.io
subjects:
  - kind: ServiceAccount
    name: csi-secrets-store-provider-azure
    namespace: {{ .Release.Namespace }}
{{- end }}
{{- end }}
