|
| 1 | +{{- $operatorWatchNamespaces := include "community-operator.watchNamespaces" . | fromYamlArray }} |
| 2 | +{{- $operatorWatchAllNamespace := has "*" $operatorWatchNamespaces }} |
| 3 | +{{- $operatorName := .Values.operator.name -}} |
| 4 | +{{- $operatorRBAC := (.Files.Lines "operator_rbac.yaml")}} |
| 5 | + |
1 | 6 | ---
|
2 | 7 | apiVersion: v1
|
3 | 8 | kind: ServiceAccount
|
4 | 9 | metadata:
|
5 |
| - name: {{ .Values.operator.name }} |
| 10 | + name: {{ $operatorName }} |
6 | 11 | namespace: {{ .Release.Namespace }}
|
7 | 12 |
|
| 13 | +{{- if $operatorWatchAllNamespace }} |
| 14 | + |
8 | 15 | ---
|
9 | 16 | apiVersion: rbac.authorization.k8s.io/v1
|
10 |
| -kind: {{ if eq (.Values.operator.watchNamespace | default "") "*" }} ClusterRole {{ else }} Role {{ end }} |
| 17 | +kind: ClusterRole |
11 | 18 | metadata:
|
12 |
| - name: {{ .Values.operator.name }} |
13 |
| - {{- if not (eq (.Values.operator.watchNamespace | default "*") "*") }} |
14 |
| - namespace: {{ .Values.operator.watchNamespace }} |
15 |
| - {{- else }} |
16 |
| - namespace: {{ .Release.Namespace }} |
17 |
| - {{- end }} |
| 19 | + name: {{ $operatorName }} |
18 | 20 | rules:
|
19 |
| -- apiGroups: |
20 |
| - - "" |
21 |
| - resources: |
22 |
| - - pods |
23 |
| - - services |
24 |
| - - configmaps |
25 |
| - - secrets |
26 |
| - verbs: |
27 |
| - - create |
28 |
| - - delete |
29 |
| - - get |
30 |
| - - list |
31 |
| - - patch |
32 |
| - - update |
33 |
| - - watch |
34 |
| -- apiGroups: |
35 |
| - - apps |
36 |
| - resources: |
37 |
| - - statefulsets |
38 |
| - verbs: |
39 |
| - - create |
40 |
| - - delete |
41 |
| - - get |
42 |
| - - list |
43 |
| - - patch |
44 |
| - - update |
45 |
| - - watch |
46 |
| -- apiGroups: |
47 |
| - - mongodbcommunity.mongodb.com |
48 |
| - resources: |
49 |
| - - mongodbcommunity |
50 |
| - - mongodbcommunity/status |
51 |
| - - mongodbcommunity/spec |
52 |
| - - mongodbcommunity/finalizers |
53 |
| - verbs: |
54 |
| - - get |
55 |
| - - patch |
56 |
| - - list |
57 |
| - - update |
58 |
| - - watch |
| 21 | + {{- range $operatorRBAC }} |
| 22 | + {{ . -}} |
| 23 | + {{- end }} |
59 | 24 |
|
60 | 25 | ---
|
61 |
| -kind: {{ if eq (.Values.operator.watchNamespace | default "") "*" }} ClusterRoleBinding {{ else }} RoleBinding {{ end }} |
| 26 | +kind: ClusterRoleBinding |
62 | 27 | apiVersion: rbac.authorization.k8s.io/v1
|
63 | 28 | metadata:
|
64 |
| - name: {{ .Values.operator.name }} |
65 |
| - {{- if ne (.Values.operator.watchNamespace | default "*") "*" }} |
66 |
| - namespace: {{ .Values.operator.watchNamespace }} |
67 |
| - {{- else }} |
68 |
| - namespace: {{ .Release.Namespace }} |
| 29 | + name: {{ $operatorName }} |
| 30 | +subjects: |
| 31 | +- kind: ServiceAccount |
| 32 | + name: {{ $operatorName }} |
| 33 | + namespace: {{ $.Release.Namespace }} |
| 34 | +roleRef: |
| 35 | + kind: ClusterRole |
| 36 | + name: {{ $operatorName }} |
| 37 | + apiGroup: rbac.authorization.k8s.io |
| 38 | + |
| 39 | +{{- else }} |
| 40 | + |
| 41 | +{{- range $namespace := $operatorWatchNamespaces }} |
| 42 | + |
| 43 | +--- |
| 44 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 45 | +kind: Role |
| 46 | +metadata: |
| 47 | + name: {{ $operatorName }} |
| 48 | + namespace: {{ $namespace }} |
| 49 | +rules: |
| 50 | + {{- range $operatorRBAC }} |
| 51 | + {{ . -}} |
69 | 52 | {{- end }}
|
| 53 | + |
| 54 | +--- |
| 55 | +kind: RoleBinding |
| 56 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 57 | +metadata: |
| 58 | + name: {{ $operatorName }} |
| 59 | + namespace: {{ $namespace }} |
70 | 60 | subjects:
|
71 | 61 | - kind: ServiceAccount
|
72 |
| - name: {{ .Values.operator.name }} |
73 |
| - namespace: {{ .Release.Namespace }} |
| 62 | + name: {{ $operatorName }} |
| 63 | + namespace: {{ $.Release.Namespace }} |
74 | 64 | roleRef:
|
75 |
| - kind: {{ if eq (.Values.operator.watchNamespace | default "") "*" }} ClusterRole {{ else }} Role {{ end }} |
76 |
| - name: {{ .Values.operator.name }} |
| 65 | + kind: Role |
| 66 | + name: {{ $operatorName }} |
77 | 67 | apiGroup: rbac.authorization.k8s.io
|
| 68 | + |
| 69 | +{{- end }} |
| 70 | + |
| 71 | +{{- end }} |
0 commit comments