# Copyright 2019 The Knative Authors
#
# 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: knative-eventing-controller
  labels:
    eventing.knative.dev/release: devel
    app.kubernetes.io/version: devel
    app.kubernetes.io/part-of: knative-eventing
rules:
  - apiGroups:
      - ""
    resources:
      - "namespaces"
      - "secrets"
      - "configmaps"
      - "services"
      - "endpoints"
      - "events"
      - "serviceaccounts"
      - "pods"
    verbs: &everything
      - "get"
      - "list"
      - "create"
      - "update"
      - "delete"
      - "patch"
      - "watch"

  # Brokers and the namespace annotation controllers manipulate Deployments.
  - apiGroups:
      - "apps"
    resources:
      - "deployments"
    verbs: *everything

  # PingSource controller manipulates Deployment owner reference
  - apiGroups:
      - "apps"
    resources:
      - "deployments/finalizers"
    verbs:
      - "update"

  # The namespace annotation controller needs to manipulate RoleBindings.
  - apiGroups:
      - "rbac.authorization.k8s.io"
    resources:
      - "rolebindings"
    verbs: *everything

  # Our own resources and statuses we care about.
  - apiGroups:
      - "eventing.knative.dev"
    resources:
      - "brokers"
      - "brokers/status"
      - "triggers"
      - "triggers/status"
      - "eventtypes"
      - "eventtypes/status"
    verbs: *everything

  # Eventing resources and finalizers we care about.
  - apiGroups:
      - "eventing.knative.dev"
    resources:
      - "brokers/finalizers"
      - "triggers/finalizers"
    verbs:
      - "update"

  # Our own resources and statuses we care about.
  - apiGroups:
      - "messaging.knative.dev"
    resources:
      - "sequences"
      - "sequences/status"
      - "channels"
      - "channels/status"
      - "parallels"
      - "parallels/status"
      - "subscriptions"
      - "subscriptions/status"
    verbs: *everything

  # Flow resources and statuses we care about.
  - apiGroups:
      - "flows.knative.dev"
    resources:
      - "sequences"
      - "sequences/status"
      - "parallels"
      - "parallels/status"
    verbs: *everything

  # Messaging resources and finalizers we care about.
  - apiGroups:
      - "messaging.knative.dev"
    resources:
      - "sequences/finalizers"
      - "parallels/finalizers"
      - "channels/finalizers"
    verbs:
      - "update"

  # Flows resources and finalizers we care about.
  - apiGroups:
      - "flows.knative.dev"
    resources:
      - "sequences/finalizers"
      - "parallels/finalizers"
    verbs:
      - "update"

  # The subscription controller needs to retrieve and watch CustomResourceDefinitions.
  - apiGroups:
      - "apiextensions.k8s.io"
    resources:
      - "customresourcedefinitions"
    verbs:
      - "get"
      - "list"
      - "watch"

  # For leader election
  - apiGroups:
      - "coordination.k8s.io"
    resources:
      - "leases"
    verbs: *everything
