Skip to content

Commit

Permalink
set database namespace to match watch namespace by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ryu-sato committed Dec 28, 2024
1 parent 21f7614 commit d8ae6e4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
13 changes: 13 additions & 0 deletions charts/community-operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,16 @@ Operator's watch namespaces
{{- $namespaces | toYaml }}
{{- end }}
{{- end }}
{{/*
Database namespaces
*/}}
{{- define "community-operator.database.namespaces" -}}
{{- $defaultNamespaces := include "community-operator.watchNamespaces" . | fromYamlArray }}
{{- $namespaces := default $defaultNamespaces .Values.database.namespaces }}
{{- if has "*" $namespaces }}
{{- list | toYaml }}
{{- else }}
{{- $namespaces | toYaml }}
{{- end }}
{{- end }}
22 changes: 14 additions & 8 deletions charts/community-operator/templates/database_roles.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
{{- $databaseNamespaces := include "community-operator.database.namespaces" . | fromYamlArray }}
{{- $databaseName := $.Values.database.name }}
{{- range $namespace := $databaseNamespaces }}

---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Values.database.name }}
namespace: {{ if .Values.database.namespace }} {{ .Values.database.namespace }} {{ else }} {{ .Release.Namespace }} {{ end }}
name: {{ $databaseName }}
namespace: {{ $namespace }}

---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ .Values.database.name }}
namespace: {{ if .Values.database.namespace }} {{ .Values.database.namespace }} {{ else }} {{ .Release.Namespace }} {{ end }}
name: {{ $databaseName }}
namespace: {{ $namespace }}
rules:
- apiGroups:
- ""
Expand All @@ -31,12 +35,14 @@ rules:
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ .Values.database.name }}
namespace: {{ if .Values.database.namespace }} {{ .Values.database.namespace }} {{ else }} {{ .Release.Namespace }} {{ end }}
name: {{ $databaseName }}
namespace: {{ $namespace }}
subjects:
- kind: ServiceAccount
name: {{ .Values.database.name }}
name: {{ $databaseName }}
roleRef:
kind: Role
name: {{ .Values.database.name }}
name: {{ $databaseName }}
apiGroup: rbac.authorization.k8s.io

{{- end }}
9 changes: 3 additions & 6 deletions charts/community-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,11 @@ operator:
## Operator's database
database:
name: mongodb-database
# set this to the namespace where you would like
# to deploy the MongoDB database,
# Note if the database namespace is not same
# as the operator namespace,
# make sure to set "watchNamespace" to "*"
# If "watchNamespaces" is set to ["*"],
# then set the database namespaces
# to ensure that the operator has the
# permission to reconcile resources in other namespaces
# namespace: mongodb-database
# namespaces: ["mongodb-database"]

agent:
name: mongodb-agent-ubi
Expand Down

0 comments on commit d8ae6e4

Please sign in to comment.