apiVersion: v1
kind: ServiceAccount
metadata:
  name: harness-admin-sa
---

{{- if .Values.clusterWideRbacScope}}
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: {{ .Values.delegateName }}-cluster-admin
subjects:
  - kind: ServiceAccount
    name: harness-admin-sa
    namespace: {{ .Release.Namespace }}
roleRef:
  kind: ClusterRole
  name: cluster-admin
  apiGroup: rbac.authorization.k8s.io
---
{{- else }}

apiVersion: rbac.authorization.k8s.io/v1beta1
kind: Role
metadata:
  name: {{ .Values.delegateName }}-admin
rules:
- apiGroups: ["", "extensions", "apps"]
  resources: ["deployments", "replicasets", "pods", "configmaps", "secrets", "services"]
  verbs: ["*"]
- apiGroups: ["", "extensions", "apps"]
  resources: ["events", "namespaces", "resourcequotas", "limitranges"]
  verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
  name: {{ .Values.delegateName }}-admin
subjects:
- kind: ServiceAccount
  name: harness-admin-sa
  namespace: {{ .Release.Namespace }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: {{ .Values.delegateName }}-admin

{{- end}}

