Skip to content

Commit

Permalink
tidy up job script
Browse files Browse the repository at this point in the history
  • Loading branch information
tomklapiscak committed Apr 25, 2024
1 parent e14a82c commit b241af2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: mas-{{ .Values.instance.id }}-syncres
annotations:
argocd.argoproj.io/sync-wave: "00"
labels:
argocd.argoproj.io/managed-by: {{ .Values.argoapp_namespace }}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
# If this happens, the old user will NOT be cleaned up, but I think we can live with this for now
# In future we could look at stashing the old docdb config in an AWS secret and make sure this Job cleans up
# those creds if the secret is present.
name: aws-docdb-process-user-sync-role-{{ .Values.docdb | toYaml | adler32sum }}
name: aws-docdb-add-user-{{ .Values.docdb | toYaml | adler32sum }}
namespace: mas-{{ .Values.instance.id }}-syncres
annotations:
argocd.argoproj.io/sync-wave: "02"
Expand Down Expand Up @@ -89,54 +89,59 @@ spec:
- |
set -e
export MAS_CONFIG_DIR="/tmp/${MAS_INSTANCE_ID}/aws_documentdb_user"
mkdir -p ${MAS_CONFIG_DIR}
export USER_ACTION="add"
DOCDB_INSTANCE_USERNAME=${DOCDB_INSTANCE_USERNAME:-"masinst_${MAS_INSTANCE_ID}"}
DOCDB_INSTANCE_PASSWORD=${DOCDB_INSTANCE_PASSWORD:-`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c 20`}
DOCDB_MASTER_INFO_ESCAPED=${DOCDB_MASTER_INFO//\"/\\\"}
DOCDB_MASTER_INFO_ESCAPED=${DOCDB_MASTER_INFO_ESCAPED//$'\n'/\\n}
SECRETS_KEY_SEPERATOR="/"
export SECRET_NAME_MONGO=${ACCOUNT_ID}${SECRETS_KEY_SEPERATOR}${CLUSTER_ID}${SECRETS_KEY_SEPERATOR}${MAS_INSTANCE_ID}${SECRETS_KEY_SEPERATOR}mongo
echo
echo "================================================================================"
echo "Settings"
echo "================================================================================"
echo "USER_ACTION=${USER_ACTION}"
echo "MAS_CONFIG_DIR=${MAS_CONFIG_DIR}"
echo "ACCOUNT_ID=${ACCOUNT_ID}"
echo "CLUSTER_ID=${CLUSTER_ID}"
echo "MAS_INSTANCE_ID=${MAS_INSTANCE_ID}"
echo "DOCDB_HOST=${DOCDB_HOST}"
echo "DOCDB_PORT=${DOCDB_PORT}"
echo "DOCDB_MASTER_USERNAME=${DOCDB_MASTER_USERNAME:0:2}<snip>"
echo "DOCDB_MASTER_PASSWORD=${DOCDB_MASTER_PASSWORD:0:2}<snip>"
echo "DOCDB_MASTER_INFO=${DOCDB_MASTER_INFO}"
echo "DOCDB_INSTANCE_USERNAME=${DOCDB_INSTANCE_USERNAME:0:2}<snip>"
echo "DOCDB_INSTANCE_PASSWORD=${DOCDB_INSTANCE_PASSWORD:0:2}<snip>"
echo "SM_AWS_REGION=${SM_AWS_REGION}"
echo "SM_AWS_ACCESS_KEY_ID=${SM_AWS_ACCESS_KEY_ID:0:2}<snip>"
echo "SM_AWS_SECRET_ACCESS_KEY=${SM_AWS_SECRET_ACCESS_KEY:0:2}<snip>"
if [[ -z "${DOCDB_INSTANCE_USERNAME}" || "${DOCDB_INSTANCE_USERNAME}" == "" ]]; then
export DOCDB_INSTANCE_USERNAME=masinst_${MAS_INSTANCE_ID}
echo "DOCDB_INSTANCE_USERNAME=${DOCDB_INSTANCE_USERNAME:0:2}<snip>"
fi
if [[ -z "${DOCDB_INSTANCE_PASSWORD}" || "${DOCDB_INSTANCE_PASSWORD}" == "" ]]; then
export DOCDB_INSTANCE_PASSWORD=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c 20`
echo "DOCDB_INSTANCE_PASSWORD=${DOCDB_INSTANCE_PASSWORD:0:2}<snip>"
fi
echo "SECRET_NAME_MONGO=${SECRET_NAME_MONGO}"
echo
echo "DOCDB_MASTER_INFO_ESCAPED:"
echo ${DOCDB_MASTER_INFO_ESCAPED}"
echo
echo "================================================================================"
echo "/opt/app-root/src/run-role.sh aws_documentdb_user"
echo "================================================================================"
mkdir -p ${MAS_CONFIG_DIR}
# /opt/app-root/src/run-role.sh aws_documentdb_user
# rc=$?
# [ $rc -ne 0 ] && exit $rc
echo "TODO: Run /opt/app-root/src/run-role.sh aws_documentdb_user"
source /mascli/functions/gitops_utils
sm_login
SECRETS_KEY_SEPERATOR="/"
export SECRET_NAME_MONGO=${ACCOUNT_ID}${SECRETS_KEY_SEPERATOR}${CLUSTER_ID}${SECRETS_KEY_SEPERATOR}${MAS_INSTANCE_ID}${SECRETS_KEY_SEPERATOR}mongo
echo "TODO: Run /opt/app-root/src/run-role.sh aws_documentdb_user (user action ${USER_ACTION})"
# Setting instance username and password into mongo instance secret, along with Info
ESCAPED_INFO=${DOCDB_MASTER_INFO//\"/\\\"}
ESCAPED_INFO=${ESCAPED_INFO//$'\n'/\\n}
echo "DOCDB_MASTER_INFO (ESCAPED_INFO)=${DOCDB_MASTER_INFO}"
sm_update_secret $SECRET_NAME_MONGO "{\"info\":\"$ESCAPED_INFO\", \"username\":\"$DOCDB_INSTANCE_USERNAME\", \"password\":\"$DOCDB_INSTANCE_PASSWORD\"}"
echo
echo "================================================================================"
echo "Updating $SECRET_NAME_MONGO"
echo "================================================================================"
source /mascli/functions/gitops_utils
sm_login
sm_update_secret $SECRET_NAME_MONGO "{\"info\":\"$DOCDB_MASTER_INFO_ESCAPED\", \"username\":\"$DOCDB_INSTANCE_USERNAME\", \"password\":\"$DOCDB_INSTANCE_PASSWORD\"}"
restartPolicy: Never
serviceAccountName: sync-sa
Expand Down

0 comments on commit b241af2

Please sign in to comment.