apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  annotations:
    "helm.sh/hook": pre-install,post-install,pre-delete
    "helm.sh/hook-delete-policy": "hook-succeeded,before-hook-creation,hook-failed"
    "helm.sh/hook-weight": "5"
  labels:
    {{- include "etcd.labels" . | nindent 4 }}
  name: {{ include "etcd.roleName" . }}
  namespace: {{ .Release.Namespace }}
rules:
  - apiGroups:
      - ""
    resources:
      - secrets
    verbs:
      - get
      - patch
      - delete
    resourceNames:
      - {{ include "etcd.caSecretName" . }}
      - {{ include "etcd.clientSecretName" . }}
  - apiGroups:
      - ""
    resources:
      - secrets
    verbs:
      - create
  - apiGroups:
      - apps
    resources:
      - statefulsets
    verbs:
      - get
      - list
      - watch
      - patch
    resourceNames:
      - {{ include "etcd.stsName" . }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  annotations:
    "helm.sh/hook": pre-install,post-install,pre-delete
    "helm.sh/hook-delete-policy": "hook-succeeded,before-hook-creation,hook-failed"
    "helm.sh/hook-weight": "5"
  labels:
    {{- include "etcd.labels" . | nindent 4 }}
  name: {{ include "etcd.roleBindingName" . }}
  namespace: {{ .Release.Namespace }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: {{ include "etcd.roleName" . }}
subjects:
  - kind: ServiceAccount
    name: {{ include "etcd.serviceAccountName" . }}
    namespace: {{ .Release.Namespace }}
