{{- if and (not (eq .Values.agentInjector.certificate.accessMethod "mount")) .Values.agentInjector.enabled }}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: {{ include "traffic-manager.namespace" $ }}
  name: agent-injector-webhook-secret
  labels: {{- include "telepresence.labels" $ | nindent 4 }}
rules:
- apiGroups:
  - ""
  resources:
  - secrets
  resourceNames: [ {{ .Values.agentInjector.secret.name }} ]
  verbs:
  - get
  - list
  - watch

---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: agent-injector-webhook-secret
  namespace: {{ include "traffic-manager.namespace" $ }}
  labels: {{- include "telepresence.labels" $ | nindent 4 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: agent-injector-webhook-secret
subjects:
  - kind: ServiceAccount
    name: traffic-manager
    namespace: {{ include "traffic-manager.namespace" $ }}
{{- end }}