[stable/mongodb-replicaset] Mongo enabling metrics crashes (#6834)

* updating script to create the metrics user if it doesnt exist

* fixing the mongo auth string

* increasing chart version

* checking if auth is enabled before creating the metric user

* Add minor adjustments and values for CI
This commit is contained in:
sekka1
2018-08-18 12:50:43 -07:00
committed by k8s-ci-robot
parent ead4e79279
commit 5ef7aca369
4 changed files with 31 additions and 10 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
name: mongodb-replicaset
home: https://github.com/mongodb/mongo
version: 3.5.4
version: 3.5.5
appVersion: 3.6
description: NoSQL document-oriented database that stores JSON-like documents with
dynamic schemas, simplifying the integration of data in content-driven applications.
@@ -0,0 +1 @@
# No config change. Just use defaults.
@@ -0,0 +1,10 @@
auth:
enabled: true
adminUser: username
adminPassword: password
metricsUser: metrics
metricsPassword: password
key: keycontent
metrics:
enabled: true
+19 -9
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# Copyright 2016 The Kubernetes Authors. All rights reserved.
# Copyright 2018 The Kubernetes Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -24,19 +24,18 @@ if [[ "$AUTH" == "true" ]]; then
if [[ "$METRICS" == "true" ]]; then
metrics_user="$METRICS_USER"
metrics_password="$METRICS_PASSWORD"
monitor_creds=(-u "$monitor_user" -p "$admin_password")
fi
auth_args=(--auth --keyFile=/data/configdb/key.txt)
auth_args=("--auth" "--keyFile=/data/configdb/key.txt")
fi
function log() {
log() {
local msg="$1"
local timestamp
timestamp=$(date --iso-8601=ns)
echo "[$timestamp] [$script_name] $msg" >> /work-dir/log.txt
}
function shutdown_mongo() {
shutdown_mongo() {
if [[ $# -eq 1 ]]; then
args="timeoutSecs: $1"
else
@@ -122,12 +121,23 @@ for peer in "${peers[@]}"; do
sleep 3
log 'Waiting for replica to reach SECONDARY state...'
until printf '.' && [[ $(mongo admin "${admin_creds[@]}" "${ssl_args[@]}" --quiet --eval "rs.status().myState") == '2' ]]; do
until printf '.' && [[ $(mongo admin "${admin_creds[@]}" "${ssl_args[@]}" --quiet --eval "rs.status().myState") == '2' ]]; do
sleep 1
done
log '✓ Replica reached SECONDARY state.'
# create the metric user if it does not exist
if [[ "$AUTH" == "true" ]]; then
if [[ "$METRICS" == "true" ]]; then
metric_user_count=$(mongo admin --host "$peer" "${admin_creds[@]}" "${ssl_args[@]}" --eval "db.system.users.find({user: '$metrics_user'}).count()" --quiet)
if [ "$metric_user_count" == "0" ]; then
log "Creating clusterMonitor user..."
mongo admin --host "$peer" "${admin_creds[@]}" "${ssl_args[@]}" --eval "db.createUser({user: '$metrics_user', pwd: '$metrics_password', roles: [{role: 'clusterMonitor', db: 'admin'}, {role: 'read', db: 'local'}]})"
fi
fi
fi
shutdown_mongo "60"
log "Good bye."
exit 0
@@ -142,7 +152,7 @@ if mongo "${ssl_args[@]}" --eval "rs.status()" | grep "no replset config has bee
sleep 3
log 'Waiting for replica to reach PRIMARY state...'
until printf '.' && [[ $(mongo "${ssl_args[@]}" --quiet --eval "rs.status().myState") == '1' ]]; do
until printf '.' && [[ $(mongo "${ssl_args[@]}" --quiet --eval "rs.status().myState") == '1' ]]; do
sleep 1
done
@@ -152,8 +162,8 @@ if mongo "${ssl_args[@]}" --eval "rs.status()" | grep "no replset config has bee
log "Creating admin user..."
mongo admin "${ssl_args[@]}" --eval "db.createUser({user: '$admin_user', pwd: '$admin_password', roles: [{role: 'root', db: 'admin'}]})"
if [[ "$METRICS" == "true" ]]; then
log "Creating cluterMonitor user..."
mongo admin "${ssl_args[@]}" --eval "db.auth('$admin_user', '$admin_password'); db.createUser({user: '$metrics_user', pwd: '$metrics_password', roles: [{role: 'clusterMonitor', db: 'admin'}, {role: 'read', db: 'local'}]})"
log "Creating clusterMonitor user..."
mongo admin "${admin_creds[@]}" "${ssl_args[@]}" --eval "db.createUser({user: '$metrics_user', pwd: '$metrics_password', roles: [{role: 'clusterMonitor', db: 'admin'}, {role: 'read', db: 'local'}]})"
fi
fi