From bc1cc3289c004a77c06c8e2d195d94b5fc15d10f Mon Sep 17 00:00:00 2001 From: Pierre Ozoux <pierre@ozoux.net> Date: Thu, 10 Feb 2022 15:31:55 +0100 Subject: [PATCH] Adds migration for hd and nc. --- .../2022-02-07-sync-half-nc-1st-part.sh | 13 +++++++++++ .../2022-02-08-sync-half-nc-2nd-part.sh | 12 ++++++++++ migrations/2022-02-08-sync-hd-1st-part.sh | 13 +++++++++++ migrations/2022-02-08-sync-hd-2nd-part.sh | 11 +++++++++ .../change_stockage_hedgedoc_first_sync.sh | 23 +++++++++++++++++++ .../change_stockage_hedgedoc_second_sync.sh | 19 +++++++++++++++ 6 files changed, 91 insertions(+) create mode 100644 migrations/2022-02-07-sync-half-nc-1st-part.sh create mode 100644 migrations/2022-02-08-sync-half-nc-2nd-part.sh create mode 100644 migrations/2022-02-08-sync-hd-1st-part.sh create mode 100644 migrations/2022-02-08-sync-hd-2nd-part.sh create mode 100644 scripts/change_stockage_hedgedoc_first_sync.sh create mode 100644 scripts/change_stockage_hedgedoc_second_sync.sh diff --git a/migrations/2022-02-07-sync-half-nc-1st-part.sh b/migrations/2022-02-07-sync-half-nc-1st-part.sh new file mode 100644 index 0000000..bc4eb8e --- /dev/null +++ b/migrations/2022-02-07-sync-half-nc-1st-part.sh @@ -0,0 +1,13 @@ +#!/bin/bash -eu + +for nuage in `kubectl get ing -l app.kubernetes.io/name=nextcloud -A --no-headers -o custom-columns=":metadata.name" | sed s/-web//g | grep -v test | tail -n 21`; do + export NS=`echo $nuage | cut -d"-" -f2-` + export SUBDOMAIN=`echo $nuage | cut -d"-" -f1` + export OBJECTSTORE_S3_HOST=`kubectl -n ${NS} get secrets ${SUBDOMAIN}-${NS}-app -o json | jq -r ".data.OBJECTSTORE_S3_HOST" | base64 -d` + if [ "$OBJECTSTORE_S3_HOST" = "s3.standard.indie.host" ]; then + if ! kubectl get secret -n ${NS} | grep -q new; then + echo Syncing $nuage ... + /root/domains/common/scripts/change_stockage_nuage_first_sync.sh + fi + fi +done diff --git a/migrations/2022-02-08-sync-half-nc-2nd-part.sh b/migrations/2022-02-08-sync-half-nc-2nd-part.sh new file mode 100644 index 0000000..050f3c3 --- /dev/null +++ b/migrations/2022-02-08-sync-half-nc-2nd-part.sh @@ -0,0 +1,12 @@ +#!/bin/bash -eu + +for nuage in `kubectl get ing -l app.kubernetes.io/name=nextcloud -A --no-headers -o custom-columns=":metadata.name" | sed s/-web//g | grep -v test | tail -n 21`; do + export NS=`echo $nuage | cut -d"-" -f2-` + export SUBDOMAIN=`echo $nuage | cut -d"-" -f1` + export OBJECTSTORE_S3_HOST=`kubectl -n ${NS} get secrets ${SUBDOMAIN}-${NS}-app -o json | jq -r ".data.OBJECTSTORE_S3_HOST" | base64 -d` + if [ "$OBJECTSTORE_S3_HOST" = "s3.standard.indie.host" ]; then + echo Syncing $nuage ... + kubectl -n ${NS} wait --for=condition=complete --timeout=-1s job/${SUBDOMAIN}-${NS}-sync-buckets + /root/domains/common/scripts/change_stockage_nuage_second_sync.sh + fi +done diff --git a/migrations/2022-02-08-sync-hd-1st-part.sh b/migrations/2022-02-08-sync-hd-1st-part.sh new file mode 100644 index 0000000..5291001 --- /dev/null +++ b/migrations/2022-02-08-sync-hd-1st-part.sh @@ -0,0 +1,13 @@ +#!/bin/bash -eu + +for hedgedoc in `kubectl get ing -l app.kubernetes.io/name=hedgedoc -A --no-headers -o custom-columns=":metadata.name" | sed s/-app//g |grep -v redirect`; do + export NS=`echo $hedgedoc | cut -d"-" -f2-` + export SUBDOMAIN=`echo $hedgedoc | cut -d"-" -f1` + export CMD_MINIO_ENDPOINT=`kubectl -n ${NS} get cm ${SUBDOMAIN}-${NS}-config -o json | jq -r ".data.CMD_MINIO_ENDPOINT"` + if [ "$CMD_MINIO_ENDPOINT" = "s3.standard.indie.host" ]; then + if ! kubectl get secret -n ${NS} ${hedgedoc}-s3-new | grep -q new; then + echo Syncing $hedgedoc ... + /root/domains/common/scripts/change_stockage_hedgedoc_first_sync.sh + fi + fi +done diff --git a/migrations/2022-02-08-sync-hd-2nd-part.sh b/migrations/2022-02-08-sync-hd-2nd-part.sh new file mode 100644 index 0000000..eb0cb4e --- /dev/null +++ b/migrations/2022-02-08-sync-hd-2nd-part.sh @@ -0,0 +1,11 @@ +#!/bin/bash -eu + +for hedgedoc in `kubectl get ing -l app.kubernetes.io/name=hedgedoc -A --no-headers -o custom-columns=":metadata.name" | sed s/-app//g |grep -v redirect`; do + export NS=`echo $hedgedoc | cut -d"-" -f2-` + export SUBDOMAIN=`echo $hedgedoc | cut -d"-" -f1` + export CMD_MINIO_ENDPOINT=`kubectl -n ${NS} get cm ${SUBDOMAIN}-${NS}-config -o json | jq -r ".data.CMD_MINIO_ENDPOINT"` + if [ "$CMD_MINIO_ENDPOINT" = "s3.standard.indie.host" ]; then + echo Syncing $hedgedoc ... + /root/domains/common/scripts/change_stockage_hedgedoc_second_sync.sh + fi +done diff --git a/scripts/change_stockage_hedgedoc_first_sync.sh b/scripts/change_stockage_hedgedoc_first_sync.sh new file mode 100644 index 0000000..789c499 --- /dev/null +++ b/scripts/change_stockage_hedgedoc_first_sync.sh @@ -0,0 +1,23 @@ +#!/bin/bash -eu + +#export NS=liiib-re +#export SUBDOMAIN=pad + +source /root/domains/common/scripts/functions.sh + +export APP=${SUBDOMAIN}-${NS} +export S3_ENDPOINT=https://hot-objects.liiib.re +export STORAGE_CLASS=hot + +# Create new hot bucket +export AWS_ACCESS_KEY_ID=${APP} +export SECRET_NAME=${APP}-s3-new +create_bucket +mc policy set download ${STORAGE_CLASS}/${AWS_ACCESS_KEY_ID} + +kubectl -n liiib-re get secret s3-ro --export -o yaml 2> /dev/null | kubectl -n ${NS} apply -f - +kubectl -n ${NS} get secret ${APP}-s3 --export -o yaml 2> /dev/null | sed "s/${APP}-s3/${APP}-backup/g" | kubectl -n ${NS} apply -f - + +cd ~/domains/${NS}/${SUBDOMAIN} +libre apply ~/domains/common/nextcloud/other-manifests/sync-job.yml +kubectl -n ${NS} wait --for=condition=complete --timeout=-1s job/${SUBDOMAIN}-${NS}-sync-buckets diff --git a/scripts/change_stockage_hedgedoc_second_sync.sh b/scripts/change_stockage_hedgedoc_second_sync.sh new file mode 100644 index 0000000..2ee73d2 --- /dev/null +++ b/scripts/change_stockage_hedgedoc_second_sync.sh @@ -0,0 +1,19 @@ +#!/bin/bash -eu + +#export NS=liiib-re +#export SUBDOMAIN=nuage + +export APP=${SUBDOMAIN}-${NS} + +kubectl -n ${NS} scale --replicas=0 deployment/${APP}-app +cd ~/domains/${NS}/${SUBDOMAIN} +kubectl -n ${NS} delete job/${SUBDOMAIN}-${NS}-sync-buckets +libre apply ~/domains/common/nextcloud/other-manifests/sync-job.yml +kubectl -n ${NS} wait --for=condition=complete --timeout=-1s job/${SUBDOMAIN}-${NS}-sync-buckets + +kubectl -n ${NS} get configmap ${APP}-config --export -o json 2> /dev/null | jq '.data["CMD_MINIO_ENDPOINT"]="hot-objects.liiib.re"' | kubectl -n ${NS} apply -f - + +kubectl -n ${NS} delete secret ${APP}-s3 +kubectl -n ${NS} get secret ${APP}-s3-new --export -o yaml 2> /dev/null | sed "s/${APP}-s3-new/${APP}-s3/g" | kubectl -n ${NS} apply -f - + +kubectl -n ${NS} scale --replicas=1 deployment/${APP}-app -- GitLab