{{- /*
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
*/}}
{{- if .Values.collector.rbac.create -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: gmp-system:operator
  {{- if .Values.commonLabels }}
  labels:
    {{- include "prometheus-engine.labels" . | nindent 4 }}
  {{- end }}
roleRef:
  name: gmp-system:operator
  kind: ClusterRole
  apiGroup: rbac.authorization.k8s.io
subjects:
- name: operator
  namespace: {{.Values.namespace.system}}
  kind: ServiceAccount
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: gmp-system:operator:webhook-admin
  {{- if .Values.commonLabels }}
  labels:
    {{- include "prometheus-engine.labels" . | nindent 4 }}
  {{- end }}
roleRef:
  name: gmp-system:operator:webhook-admin
  kind: ClusterRole
  apiGroup: rbac.authorization.k8s.io
subjects:
- name: operator
  namespace: {{.Values.namespace.system}}
  kind: ServiceAccount
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: operator
  namespace: {{.Values.namespace.public}}
  {{- if .Values.commonLabels }}
  labels:
    {{- include "prometheus-engine.labels" . | nindent 4 }}
  {{- end }}
roleRef:
  name: operator
  kind: Role
  apiGroup: rbac.authorization.k8s.io
subjects:
- name: operator
  namespace: {{.Values.namespace.system}}
  kind: ServiceAccount
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: operator
  namespace: {{.Values.namespace.system}}
  {{- if .Values.commonLabels }}
  labels:
    {{- include "prometheus-engine.labels" . | nindent 4 }}
  {{- end }}
roleRef:
  name: operator
  kind: Role
  apiGroup: rbac.authorization.k8s.io
subjects:
- name: operator
  kind: ServiceAccount
{{- end }}
{{- if .Values.collector.rbac.create -}}
  {{- if .Values.operator.rbac.create }}
---
  {{- end }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: gmp-system:collector
  {{- if .Values.commonLabels }}
  labels:
    {{- include "prometheus-engine.labels" . | nindent 4 }}
  {{- end }}
roleRef:
  name: gmp-system:collector
  kind: ClusterRole
  apiGroup: rbac.authorization.k8s.io
subjects:
- name: collector
  namespace: {{.Values.namespace.system}}
  kind: ServiceAccount
{{- end -}}
