From 5ef7aca3697ad6ee246e8877bc4a6454a0efd3a4 Mon Sep 17 00:00:00 2001 From: sekka1 Date: Sat, 18 Aug 2018 12:50:43 -0700 Subject: [PATCH] [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 --- stable/mongodb-replicaset/Chart.yaml | 2 +- .../mongodb-replicaset/ci/default-values.yaml | 1 + .../mongodb-replicaset/ci/metrics-values.yaml | 10 +++++++ stable/mongodb-replicaset/init/on-start.sh | 28 +++++++++++++------ 4 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 stable/mongodb-replicaset/ci/default-values.yaml create mode 100644 stable/mongodb-replicaset/ci/metrics-values.yaml diff --git a/stable/mongodb-replicaset/Chart.yaml b/stable/mongodb-replicaset/Chart.yaml index 110e94d711..3698e7b600 100644 --- a/stable/mongodb-replicaset/Chart.yaml +++ b/stable/mongodb-replicaset/Chart.yaml @@ -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. diff --git a/stable/mongodb-replicaset/ci/default-values.yaml b/stable/mongodb-replicaset/ci/default-values.yaml new file mode 100644 index 0000000000..a8bad27cda --- /dev/null +++ b/stable/mongodb-replicaset/ci/default-values.yaml @@ -0,0 +1 @@ +# No config change. Just use defaults. diff --git a/stable/mongodb-replicaset/ci/metrics-values.yaml b/stable/mongodb-replicaset/ci/metrics-values.yaml new file mode 100644 index 0000000000..df64aca1e8 --- /dev/null +++ b/stable/mongodb-replicaset/ci/metrics-values.yaml @@ -0,0 +1,10 @@ +auth: + enabled: true + adminUser: username + adminPassword: password + metricsUser: metrics + metricsPassword: password + key: keycontent + +metrics: + enabled: true diff --git a/stable/mongodb-replicaset/init/on-start.sh b/stable/mongodb-replicaset/init/on-start.sh index 184b3faf9d..2ac58f09ab 100644 --- a/stable/mongodb-replicaset/init/on-start.sh +++ b/stable/mongodb-replicaset/init/on-start.sh @@ -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