apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  annotations:
    # ensure this resource is created before and delete after the deployment to minimise errors during namespace transition
    argocd.argoproj.io/sync-wave: "1"
  name: hpa-controller-elasticsearch-metrics-apiserver
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: elasticsearch-metrics-apiserver-resources
subjects:
  - kind: ServiceAccount
    name: horizontal-pod-autoscaler
    namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  annotations:
    # ensure this resource is created before and delete after the deployment to minimise errors during namespace transition
    argocd.argoproj.io/sync-wave: "1"
  name: elasticsearch-metrics-apiserver-proxy
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: elasticsearch-metrics-apiserver-resources
subjects:
  - kind: ServiceAccount
    name: elasticsearch-metrics-apiserver
    namespace: {{ .Release.Namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  annotations:
    # ensure this resource is created before and delete after the deployment to minimise errors during namespace transition
    argocd.argoproj.io/sync-wave: "1"
  name: elasticsearch-metrics-apiserver:system:auth-delegator
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:auth-delegator
subjects:
  - kind: ServiceAccount
    name: elasticsearch-metrics-apiserver
    namespace: {{ .Release.Namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  annotations:
    # ensure this resource is created before and delete after the deployment to minimise errors during namespace transition
    argocd.argoproj.io/sync-wave: "1"
  name: elasticsearch-metrics-apiserver-resource-reader
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: elasticsearch-metrics-apiserver-resource-reader
subjects:
  - kind: ServiceAccount
    name: elasticsearch-metrics-apiserver
    namespace: {{ .Release.Namespace }}