# Copyright 2019 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
#
#     http://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.

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: cloud-run-events-controller
  labels:
    events.cloud.run/release: devel
rules:

- apiGroups:
    - pubsub.cloud.run
  resources:
    - pullsubscriptions
    - topics
  verbs: &everything
    - get
    - list
    - watch
    - create
    - update
    - patch
    - delete

- apiGroups:
    - pubsub.cloud.run
  resources:
    - pullsubscriptions/status
    - topics/status
  verbs:
    - get
    - update
    - patch

- apiGroups:
    - messaging.cloud.run
  resources:
    - channels
    - decorators
  verbs: *everything

- apiGroups:
    - messaging.cloud.run
  resources:
    - channels/status
    - decorators/status
  verbs:
    - get
    - update
    - patch

- apiGroups:
    - events.cloud.run
  resources:
    - storages
  verbs: *everything

- apiGroups:
    - events.cloud.run
  resources:
    - storages/status
  verbs:
    - get
    - update
    - patch

- apiGroups:
    - admissionregistration.k8s.io
  resources:
    - mutatingwebhookconfigurations
  verbs: *everything

- apiGroups:
    - apps
  resources:
    - deployments
  verbs: *everything

- apiGroups:
    - serving.knative.dev
  resources:
    - services
  verbs: *everything

- apiGroups:
    - batch
  resources:
    - jobs
  verbs: *everything


- apiGroups:
    - ""
  resources:
    - services
  verbs: *everything

- apiGroups:
    - ""
  resources:
    - secrets # TODO: Does it really need global secrets access?
    - configmaps
  verbs: &readOnly
    - get
    - list
    - watch

- apiGroups: [""]
  resources:
    - events
  verbs:
    - create
    - patch

- apiGroups:
    - eventing.knative.dev
  resources:
    - eventtypes
  verbs: *everything
