rbac.yaml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. ################################################################################
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. ################################################################################
  18. {{/*
  19. RBAC rules used to create the operator (cluster)role based on the scope
  20. */}}
  21. {{- define "flink-operator.rbacRules" }}
  22. rules:
  23. - apiGroups:
  24. - ""
  25. resources:
  26. - pods
  27. - services
  28. - events
  29. - configmaps
  30. - secrets
  31. verbs:
  32. - "*"
  33. {{- if .Values.rbac.nodesRule.create }}
  34. - apiGroups:
  35. - ""
  36. resources:
  37. - nodes
  38. verbs:
  39. - list
  40. {{- end }}
  41. - apiGroups:
  42. - apps
  43. resources:
  44. - deployments
  45. - deployments/scale
  46. - deployments/finalizers
  47. - replicasets
  48. verbs:
  49. - "*"
  50. - apiGroups:
  51. - extensions
  52. resources:
  53. - deployments
  54. - ingresses
  55. verbs:
  56. - "*"
  57. - apiGroups:
  58. - flink.apache.org
  59. resources:
  60. - flinkdeployments
  61. - flinkdeployments/status
  62. - flinkdeployments/finalizers
  63. - flinksessionjobs
  64. - flinksessionjobs/status
  65. - flinksessionjobs/finalizers
  66. verbs:
  67. - "*"
  68. - apiGroups:
  69. - networking.k8s.io
  70. resources:
  71. - ingresses
  72. verbs:
  73. - "*"
  74. - apiGroups:
  75. - coordination.k8s.io
  76. resources:
  77. - leases
  78. verbs:
  79. - "*"
  80. {{- end }}
  81. {{/*
  82. RBAC rules used to create the job (cluster)role based on the scope
  83. */}}
  84. {{- define "flink-operator.jobRbacRules" }}
  85. rules:
  86. - apiGroups:
  87. - ""
  88. resources:
  89. - pods
  90. - configmaps
  91. verbs:
  92. - '*'
  93. - apiGroups:
  94. - apps
  95. resources:
  96. - deployments
  97. - deployments/finalizers
  98. verbs:
  99. - '*'
  100. {{- end }}
  101. ---
  102. {{- if .Values.rbac.create }}
  103. ---
  104. {{/*
  105. Namespaced scoped RBAC.
  106. */}}
  107. {{- if .Values.watchNamespaces }}
  108. {{- range .Values.watchNamespaces }}
  109. {{- if $.Values.rbac.operatorRole.create }}
  110. apiVersion: rbac.authorization.k8s.io/v1
  111. kind: Role
  112. metadata:
  113. name: {{ include "flink-operator.roleName" $ }}
  114. namespace: {{ . }}
  115. labels:
  116. {{- include "flink-operator.labels" $ | nindent 4 }}
  117. {{- template "flink-operator.rbacRules" $ }}
  118. {{- end }}
  119. ---
  120. {{- if $.Values.rbac.jobRole.create }}
  121. apiVersion: rbac.authorization.k8s.io/v1
  122. kind: Role
  123. metadata:
  124. name: {{ include "flink-operator.jobRoleName" $ }}
  125. namespace: {{ . }}
  126. labels:
  127. {{- include "flink-operator.labels" $ | nindent 4 }}
  128. annotations:
  129. "helm.sh/resource-policy": keep
  130. {{- template "flink-operator.jobRbacRules" $ }}
  131. {{- end }}
  132. ---
  133. {{- if $.Values.rbac.operatorRoleBinding.create }}
  134. apiVersion: rbac.authorization.k8s.io/v1
  135. kind: RoleBinding
  136. metadata:
  137. name: {{ include "flink-operator.roleBindingName" $ }}
  138. namespace: {{ . }}
  139. labels:
  140. {{- include "flink-operator.labels" $ | nindent 4 }}
  141. roleRef:
  142. kind: {{ $role := include "flink-operator.roleName" $ }}{{ include "flink-operator.roleScope" (dict "role" $role)}}
  143. name: {{ include "flink-operator.roleName" $ }}
  144. apiGroup: rbac.authorization.k8s.io
  145. subjects:
  146. - kind: ServiceAccount
  147. name: {{ include "flink-operator.serviceAccountName" $ }}
  148. namespace: {{ $.Release.Namespace }}
  149. {{- end }}
  150. ---
  151. {{- if $.Values.rbac.jobRoleBinding.create }}
  152. apiVersion: rbac.authorization.k8s.io/v1
  153. kind: RoleBinding
  154. metadata:
  155. name: {{ include "flink-operator.jobRoleBindingName" $ }}
  156. namespace: {{ . }}
  157. labels:
  158. {{- include "flink-operator.labels" $ | nindent 4 }}
  159. annotations:
  160. "helm.sh/resource-policy": keep
  161. roleRef:
  162. kind: {{ $role := include "flink-operator.jobRoleName" $ }}{{ include "flink-operator.roleScope" (dict "role" $role)}}
  163. name: {{ include "flink-operator.jobRoleName" $ }}
  164. apiGroup: rbac.authorization.k8s.io
  165. subjects:
  166. - kind: ServiceAccount
  167. name: {{ include "flink-operator.jobServiceAccountName" $ }}
  168. namespace: {{ . }}
  169. {{- end }}
  170. ---
  171. {{- end }}
  172. {{/*
  173. Give operator the ability to operate on leases in the release namespace
  174. */}}
  175. {{- if and .Values.rbac.operatorRole.create (not (has .Release.Namespace .Values.watchNamespaces)) }}
  176. apiVersion: rbac.authorization.k8s.io/v1
  177. kind: Role
  178. metadata:
  179. name: {{ include "flink-operator.roleName" $ }}
  180. namespace: {{ .Release.Namespace }}
  181. labels:
  182. {{- include "flink-operator.labels" . | nindent 4 }}
  183. rules:
  184. - apiGroups:
  185. - coordination.k8s.io
  186. resources:
  187. - leases
  188. verbs:
  189. - "*"
  190. {{- end }}
  191. ---
  192. {{- if and .Values.rbac.operatorRole.create (not (has .Release.Namespace .Values.watchNamespaces)) }}
  193. apiVersion: rbac.authorization.k8s.io/v1
  194. kind: RoleBinding
  195. metadata:
  196. name: {{ include "flink-operator.roleBindingName" $ }}
  197. namespace: {{ .Release.Namespace }}
  198. labels:
  199. {{- include "flink-operator.labels" $ | nindent 4 }}
  200. roleRef:
  201. kind: Role
  202. name: {{ include "flink-operator.roleName" $ }}
  203. apiGroup: rbac.authorization.k8s.io
  204. subjects:
  205. - kind: ServiceAccount
  206. name: {{ include "flink-operator.serviceAccountName" . }}
  207. namespace: {{ .Release.Namespace }}
  208. {{- end }}
  209. {{ else }}
  210. {{/*
  211. Cluster scoped RBAC.
  212. */}}
  213. ---
  214. {{- if .Values.rbac.operatorRole.create }}
  215. apiVersion: rbac.authorization.k8s.io/v1
  216. kind: ClusterRole
  217. metadata:
  218. name: {{ include "flink-operator.roleName" $ }}
  219. namespace: {{ .Release.Namespace }}
  220. labels:
  221. {{- include "flink-operator.labels" . | nindent 4 }}
  222. {{- template "flink-operator.rbacRules" $ }}
  223. {{- end }}
  224. ---
  225. {{- if .Values.rbac.jobRole.create }}
  226. apiVersion: rbac.authorization.k8s.io/v1
  227. kind: Role
  228. metadata:
  229. name: {{ include "flink-operator.jobRoleName" $ }}
  230. namespace: {{ .Release.Namespace }}
  231. labels:
  232. {{- include "flink-operator.labels" . | nindent 4 }}
  233. annotations:
  234. "helm.sh/resource-policy": keep
  235. {{- template "flink-operator.jobRbacRules" $ }}
  236. {{- end }}
  237. ---
  238. {{- if .Values.rbac.operatorRoleBinding.create }}
  239. apiVersion: rbac.authorization.k8s.io/v1
  240. kind: ClusterRoleBinding
  241. metadata:
  242. name: {{ include "flink-operator.roleBindingName" $ }}
  243. namespace: {{ .Release.Namespace }}
  244. labels:
  245. {{- include "flink-operator.labels" . | nindent 4 }}
  246. roleRef:
  247. kind: ClusterRole
  248. name: {{ include "flink-operator.roleName" $ }}
  249. apiGroup: rbac.authorization.k8s.io
  250. subjects:
  251. - kind: ServiceAccount
  252. name: {{ include "flink-operator.serviceAccountName" . }}
  253. namespace: {{ .Release.Namespace }}
  254. {{- end }}
  255. ---
  256. {{- if .Values.rbac.jobRoleBinding.create }}
  257. apiVersion: rbac.authorization.k8s.io/v1
  258. kind: RoleBinding
  259. metadata:
  260. name: {{ include "flink-operator.jobRoleBindingName" $ }}
  261. namespace: {{ .Release.Namespace }}
  262. labels:
  263. {{- include "flink-operator.labels" . | nindent 4 }}
  264. annotations:
  265. "helm.sh/resource-policy": keep
  266. roleRef:
  267. kind: Role
  268. name: {{ include "flink-operator.jobRoleName" $ }}
  269. apiGroup: rbac.authorization.k8s.io
  270. subjects:
  271. - kind: ServiceAccount
  272. name: {{ include "flink-operator.jobServiceAccountName" . }}
  273. namespace: {{ .Release.Namespace }}
  274. {{- end }}
  275. {{- end }}
  276. {{- end }}