# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you 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.
#
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nuvolaris-operator-role
  namespace: nuvolaris
  labels:
    app: nuvolaris-operator-role
rules:

# edit secrets cm po svc pvc ingresses serviceaccounts events
- apiGroups: [""]
  resources: ["routes", "configmaps", "secrets", "pods", "services", "persistentvolumeclaims", "ingresses","serviceaccounts","events","pods/exec", "*/finalizers"]
  verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]

# required for etcd #resources: 
- apiGroups: ["policy"]  
  resources: ["poddisruptionbudgets"]
  verbs: ["get","patch","list","update","watch","create","delete"]   

- apiGroups: [""]
  resources: ["services/status"]
  verbs: ["update", "patch"]

# read logs
- apiGroups: [""]
  resources: ["pods/log"]
  verbs: ["get", "list"]

# edit deployments daemonset statefulset
- apiGroups: ["extensions", "apps"]
  resources: ["deployments", "daemonsets", "statefulsets", "statefulsets/scale", "*/finalizers" ]
  verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]

# rbac
- apiGroups: ["rbac.authorization.k8s.io"]
  resources: ["roles", "rolebindings", "rolebindings/finalizers"]
  verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]

# edit jobs
- apiGroups: ["batch"]
  resources: ["jobs", "cronjobs", "*/finalizers"]
  verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]

# edit nuvolaris crds
- apiGroups: ["nuvolaris.org"]
  resources: ["whisks","whisks/status","whisksusers","whisksusers/status","workflows","workflows/status","*/finalizers"]
  verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]

# networking.k8s.io
- apiGroups: ["networking.k8s.io"]
  resources: ["ingresses"]
  verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]

# required for mongodb
- apiGroups: ["rbac.authorization.k8s.io"]
  resources: ["roles","rolebindings"]
  verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]

- apiGroups: ["route.openshift.io"]
  resources: ["routes"]
  verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]

- apiGroups: ["mongodbcommunity.mongodb.com"]
  resources: ["mongodbcommunity","mongodbcommunity/finalizers","mongodbcommunity/spec","mongodbcommunity/status"]
  verbs: ["get","patch","list","update","watch","create","delete"]

# required for traefik middlewares
- apiGroups: ["traefik.containo.us"]
  resources: ["middlewares"]
  verbs: ["get","patch","list","update","watch","create","delete"]

# required for kubegres #resources: 
- apiGroups: ["kubegres.reactive-tech.io"]  
  resources: ["kubegres","kubegres/status","kubegres/finalizers"]
  verbs: ["get","patch","list","update","watch","create","delete"] 

# required for milvus #resources: 
- apiGroups: ["milvus.io"]  
  resources: ["milvus","milvus/status","milvus/finalizers"]
  verbs: ["get","patch","list","update","watch","create","delete"]

---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nuvolaris-operator-rb
  namespace: nuvolaris
  labels:
    app: nuvolaris-operator-rb
subjects:
- kind: ServiceAccount
  namespace: nuvolaris
  name:  nuvolaris-operator
roleRef:
  kind: Role
  name: nuvolaris-operator-role
  apiGroup: rbac.authorization.k8s.io
