-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--- | ||
{{ $config := lookup "v1" "ConfigMap" .Release.Namespace "rocketchat-mongodb-fix-clustermonitor-role-configmap" }} | ||
{{ if not $config }} | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: rocketchat-mongodb-fix-clustermonitor-role-configmap | ||
labels: | ||
app.kubernetes.io/name: {{ include "rocketchat.name" . }} | ||
helm.sh/chart: {{ include "rocketchat.chart" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
|
||
data: | ||
user_set_role_clusrerMonitor.sh: | | ||
#! /bin/bash | ||
# #include <everything> | ||
source /opt/bitnami/scripts/libmongodb.sh | ||
error_and_abort() { | ||
error "$@" | ||
exit 1 | ||
} | ||
main() { | ||
# mongodb_wait_for_primary_node "$MONGODB_INITIAL_PRIMARY_HOST" "$MONGODB_INITIAL_PRIMARY_PORT_NUMBER" "$MONGODB_INITIAL_PRIMARY_ROOT_USER" "$MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD" | ||
# Shouldn't be looping over all dbs, but currently no way of knowing which db is for rocketchat | ||
# and which might not be. | ||
# Either way, having clusterMonitor role shouldn't hurt | ||
local databases=($MONGODB_DATABASE) | ||
databases+=($MONGODB_EXTRA_DATABASES) | ||
local usernames=($MONGODB_USERNAME) | ||
usernames+=($MONGODB_EXTRA_USERNAMES) | ||
# each array should be of the same length | ||
local database username last=$((${#databases[@]}-1)) | ||
for idx in $(seq 0 $last); do | ||
database=${databases[$idx]} | ||
username=${usernames[$idx]} | ||
info "attempting to add clusterMonitor role to user $username" | ||
local cmd=" | ||
db.getSiblingDB('$database').grantRolesToUser( | ||
'$username', | ||
[ | ||
{ | ||
role: 'clusterMonitor', | ||
db: 'admin' | ||
} | ||
] | ||
) | ||
" | ||
debug "Executing: ${cmd:5:-1}" | ||
local out=$(mongodb_execute_print_output "$MONGODB_ROOT_USER" "$MONGODB_ROOT_PASSWORD" "admin" "" "" "--quiet" <<< "$cmd") | ||
# local ok=$(perl -MJSON -0ne 'print decode_json($_)->{"ok"}' <<< "$out") | ||
local ok=$(awk '/ok:/ { print $2 }' <<< ${out/,/}) | ||
{ [[ -n $out ]] && ! ((ok)); } && error_and_abort "failed to add role clusterMonitor to user \"$username\"; Error: $out" | ||
info "clusterMonitor role added to $username" | ||
done | ||
} | ||
main | ||
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters