From 9b84227f0b4caa62bf7322691354825e684053cd Mon Sep 17 00:00:00 2001 From: "alvaro.gonzalez" Date: Wed, 17 Jul 2024 16:19:17 +0300 Subject: [PATCH 1/3] Add configuration of mongodb and rabbotmq hosts --- update-config-map.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/update-config-map.sh b/update-config-map.sh index ebf3485..53797de 100755 --- a/update-config-map.sh +++ b/update-config-map.sh @@ -10,11 +10,24 @@ then env exit 1 fi + +if [ -z "$MONGO_HOST" ]; +then + MONGO_HOST='mongodb' +fi + +if [ -z "$RABBIT_HOST" ]; +then + RABBIT_HOST='rabbitmq' +fi + echo "Inputs:" echo " CONFIG MAP NAME: $CONFIG_MAP_NAME" echo " API SERVER: $APISERVER" echo " APP CONFIG PATH: $APP_CONFIG_PATH" echo " WES APP NAME: $WES_APP_NAME" +echo " MONGO HOST: $MONGO_HOST" +echo " RABBIT HOST: $RABBIT_HOST" NAMESPACE=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace) @@ -29,7 +42,11 @@ echo "Current Kubernetes namespace: $NAMESPACE"; echo echo " * Getting current default configuration" -APP_CONFIG=$(cat "$APP_CONFIG_PATH") +APP_CONFIG=$(yq --arg MONGO_HOST "$MONGO_HOST" \ + --arg RABBIT_HOST "$RABBIT_HOST" \ + '.db.host = $MONGO_HOST | + .jobs.host = $RABBIT_HOST' \ + "$APP_CONFIG_PATH") echo " * Getting current configMap" curl -s \ From 0ce74799184bebb72d520f209c21f161500f33e0 Mon Sep 17 00:00:00 2001 From: "alvaro.gonzalez" Date: Thu, 18 Jul 2024 15:44:47 +0300 Subject: [PATCH 2/3] Allow updating rabbitmq and mongodb URLs --- requirements.txt | 1 + update-config-map.sh | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/requirements.txt b/requirements.txt index f972f64..9147613 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ drs-cli~=0.2.3 gunicorn~=19.9.0 py-tes~=0.4.2 importlib-metadata==4.13.0 +yq==3.2.3 diff --git a/update-config-map.sh b/update-config-map.sh index 53797de..ec99864 100755 --- a/update-config-map.sh +++ b/update-config-map.sh @@ -4,9 +4,9 @@ # ############################################################################### -if [ -z "$CONFIG_MAP_NAME" -o -z "$APISERVER" -o -z "$APP_CONFIG_PATH" -o -z "$WES_APP_NAME" ]; +if [ -z "$CONFIG_MAP_NAME" -o -z "$APISERVER" -o -z "$APP_CONFIG_PATH" -o -z "$WES_APP_NAME" -o -z "$CELERY_APP_NAME" ]; then - echo "CONFIG_MAP_NAME, APISERVER, APP_CONFIG_PATH, and WES_APP_NAME env vars required" + echo "CONFIG_MAP_NAME, APISERVER, APP_CONFIG_PATH, WES_APP_NAME, and CELERY_APP_NAME env vars required" env exit 1 fi @@ -26,6 +26,7 @@ echo " CONFIG MAP NAME: $CONFIG_MAP_NAME" echo " API SERVER: $APISERVER" echo " APP CONFIG PATH: $APP_CONFIG_PATH" echo " WES APP NAME: $WES_APP_NAME" +echo " CELERY APP NAME: $CELERY_APP_NAME" echo " MONGO HOST: $MONGO_HOST" echo " RABBIT HOST: $RABBIT_HOST" @@ -42,11 +43,11 @@ echo "Current Kubernetes namespace: $NAMESPACE"; echo echo " * Getting current default configuration" -APP_CONFIG=$(yq --arg MONGO_HOST "$MONGO_HOST" \ +APP_CONFIG=$(yq -y --arg MONGO_HOST "$MONGO_HOST" \ --arg RABBIT_HOST "$RABBIT_HOST" \ '.db.host = $MONGO_HOST | .jobs.host = $RABBIT_HOST' \ - "$APP_CONFIG_PATH") + "$APP_CONFIG_PATH") || exit 4 echo " * Getting current configMap" curl -s \ @@ -64,7 +65,7 @@ jq . /tmp/configmap.json || exit 2 echo " JSON file is valid";echo echo " * Creating update for secret" -jq ".data.\"app_config.yaml\" = \"$APP_CONFIG\"" /tmp/configmap.json >/tmp/configmap-patch.json +jq --arg APP_CONFIG "$APP_CONFIG" '.data."app_config.yaml" = $APP_CONFIG' /tmp/configmap.json >/tmp/configmap-patch.json || exit 5 echo " * Validating JSON file patched:"; echo jq . /tmp/configmap-patch.json || exit 3 @@ -102,8 +103,27 @@ do "https://$APISERVER/api/v1/namespaces/${NAMESPACE}/pods/$pod" done -echo " All Done" - -sleep 3600 +### +echo " * Deleting current $CELERY_APP_NAME pod" +curl -s \ + --cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt \ + -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" \ + -X GET \ + -H "Accept: application/json, */*" \ + "https://$APISERVER/api/v1/namespaces/${NAMESPACE}/pods/" | \ +jq '.items | .[] | .metadata.name ' -r | grep "^${CELERY_APP_NAME}-" | \ +while read pod; +do + echo " - Deleting: $pod" + curl -s \ + --cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt \ + -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" \ + -X DELETE \ + -H "Accept: application/json, */*" \ + -o /dev/null \ + "https://$APISERVER/api/v1/namespaces/${NAMESPACE}/pods/$pod" +done +### +echo " All Done" From 733ec40cde618e2f850a3c523bf462fbd34157ab Mon Sep 17 00:00:00 2001 From: "alvaro.gonzalez" Date: Fri, 19 Jul 2024 08:37:49 +0300 Subject: [PATCH 3/3] Ensuring yq is installed --- update-config-map.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/update-config-map.sh b/update-config-map.sh index ec99864..1b1b269 100755 --- a/update-config-map.sh +++ b/update-config-map.sh @@ -43,6 +43,8 @@ echo "Current Kubernetes namespace: $NAMESPACE"; echo echo " * Getting current default configuration" +command -V yq || echo "yq not found, exiting"; exit 6 + APP_CONFIG=$(yq -y --arg MONGO_HOST "$MONGO_HOST" \ --arg RABBIT_HOST "$RABBIT_HOST" \ '.db.host = $MONGO_HOST |