apiVersion: v1
kind: ServiceAccount
metadata:
  name: {{ .component.fullName }}-svc-account
  {{- if .this.utils.includeNamespace }}
  namespace: {{ .Release.Namespace }}
  {{- end }}
  labels:
    {{- include "nplus.instanceLabels" . | nindent 4 }}
  annotations:
    {{- include "nplus.argoSharedResource" . | nindent 4 }}
    {{- include "nplus.annotations" . | nindent 4 }}

---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: {{ .component.fullName }}-role
  {{- if .this.utils.includeNamespace }}
  namespace: {{ .Release.Namespace }}
  {{- end }}
  labels:
    {{- include "nplus.instanceLabels" . | nindent 4 }}
  annotations:
    {{- include "nplus.argoSharedResource" . | nindent 4 }}
    {{- include "nplus.annotations" . | nindent 4 }}

rules:
  - apiGroups: ["apps"]
    resources: ["deployments","deployments/scale", "statefulsets","statefulsets/scale", "replicasets"]
    verbs: ["get", "patch", "list"]

---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: {{ .component.fullName }}-role-binding
  {{- if .this.utils.includeNamespace }}
  namespace: {{ .Release.Namespace }}
  {{- end }}
  labels:
    {{- include "nplus.instanceLabels" . | nindent 4 }}
  annotations:
    {{- include "nplus.argoSharedResource" . | nindent 4 }}
    {{- include "nplus.annotations" . | nindent 4 }}

roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: {{ .component.fullName }}-role
subjects:
- kind: ServiceAccount
  name: {{ .component.fullName }}-svc-account
