---

# Copyright 2020 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: kafka-controller
  labels:
    kafka.eventing.knative.dev/release: devel
rules:
  - apiGroups:
      - "*"
    resources:
      - configmaps
    verbs:
      - get
      - list
      - watch
      - update
      - create
  - apiGroups:
      - "*"
    resources:
      - pods
    verbs:
      - list
      - update
      - get
      - watch
  - apiGroups:
      - "*"
    resources:
      - events
    verbs:
      - patch
      - create
  - apiGroups:
      - "coordination.k8s.io"
    resources:
      - "leases"
    verbs:
      - get
      - list
      - create
      - update
      - delete
      - patch
      - watch

  - apiGroups:
      - "*"
    resources:
      - secrets
    verbs:
      - list
      - get
      - watch

  # Scheduler permissions
  - apiGroups:
      - "*"
    resources:
      - nodes
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - "apps"
    resources:
      - statefulsets
      - statefulsets/scale
    verbs:
      - get
      - list
      - watch
      - update
      - patch

  # Internal APIs
  - apiGroups:
      - "internal.kafka.eventing.knative.dev"
    resources:
      - "consumers"
      - "consumers/status"
      - "consumergroups"
      - "consumergroups/status"
    verbs:
      - create
      - get
      - list
      - watch
      - patch
      - update
      - delete
  - apiGroups:
      - "internal.kafka.eventing.knative.dev"
    resources:
      - "consumers/finalizers"
      - "consumergroups/finalizers"
    verbs:
      - update
      - delete
  # Eventing resources and statuses we care about
  - apiGroups:
      - "eventing.knative.dev"
    resources:
      - "brokers"
      - "brokers/status"
      - "triggers"
      - "triggers/status"
      - "kafkasinks"
      - "kafkasinks/status"
    verbs:
      - list
      - get
      - watch
      - patch
      - update

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

  # messaging.knative.dev resources and finalizers we care about.
  - apiGroups:
      - messaging.knative.dev
    resources:
      - kafkachannels
      - kafkachannels/status
    verbs:
      - get
      - list
      - watch
      - update
      - patch
  - apiGroups:
      - messaging.knative.dev
    resources:
      - subscriptions
      - subscriptions/status
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - messaging.knative.dev
    resources:
      - kafkachannels/finalizers
    verbs:
      - update

  # sources.knative.dev resources and finalizers we care about.
  - apiGroups:
      - sources.knative.dev
    resources:
      - kafkasources
      - kafkasources/status
    verbs:
      - get
      - list
      - watch
      - update
      - patch
  - apiGroups:
      - sources.knative.dev
    resources:
      - kafkasources/finalizers
    verbs:
      - update
