{{- if eq .Values.customMetricsAPIService.enabled "true" }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: metrics-operator-hpa-controller
  namespace: {{ .Release.Namespace | quote }}
  {{- $annotations := include "common.annotations" (dict "context" .) }}
  {{- with $annotations }}
  annotations: {{- . -}}
  {{- end }}
  labels:
{{- include "common.labels.standard" ( dict "context" . ) | nindent 4 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: 'metrics-operator-server-resources'
subjects:
- kind: ServiceAccount
  name: horizontal-pod-autoscaler
  namespace: '{{ .Release.Namespace }}'
{{- end }}
