Skip to content

Commit

Permalink
Cleanup preload (#2133)
Browse files Browse the repository at this point in the history
* add cleanup

Signed-off-by: Ben Luzarraga <[email protected]>

* reword error message

Signed-off-by: Ben Luzarraga <[email protected]>

---------

Signed-off-by: Ben Luzarraga <[email protected]>
  • Loading branch information
bluzarraga authored Aug 2, 2024
1 parent 45f3768 commit 5e83b7f
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions preload_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ TEMPFILE="_TMP.yaml"
DEBUG=0
z_or_power_ENV="false"
RERUN="false"
CLEANUP="false"
ARGUMENTS=""

# ---------- Command variables ----------

Expand All @@ -46,29 +48,35 @@ LOG_FILE="preload_data_log_$(date +'%Y%m%d%H%M%S').log"
trap 'error "Error occurred in function $FUNCNAME at line $LINENO"' ERR

function main() {
ARGUMENTS="$@"
parse_arguments "$@"
save_log "cp3pt0-deployment/logs" "preload_data_log" "$DEBUG"
trap cleanup_log EXIT
prereq
if [[ $RERUN == "true" ]]; then
info "Rerun specified..."
if [[ $CLEANUP == "false" ]]; then
if [[ $RERUN == "true" ]]; then
info "Rerun specified..."
deletemongocopy
fi
# run backup preload
backup_preload_mongo
# copy im credentials
copy_resource "secret" "platform-auth-idp-credentials"
copy_resource "secret" "platform-auth-ldaps-ca-cert"
copy_resource "secret" "platform-oidc-credentials"
copy_resource "secret" "oauth-client-secret"
copy_resource "configmap" "ibm-cpp-config"
copy_resource "configmap" "common-web-ui-config"
copy_resource "configmap" "platform-auth-idp"
copy_resource "commonservice" "common-service" "preload-common-service-from-$FROM_NAMESPACE"
copy_resource "secret" "icp-mongodb-client-cert"
copy_resource "secret" "mongodb-root-ca-cert"
copy_resource "secret" "icp-mongodb-admin"
# any extra config
else
info "Cleanup selected. Cleaning MongoDB in services namespace $TO_NAMESPACE"
deletemongocopy
fi
# run backup preload
backup_preload_mongo
# copy im credentials
copy_resource "secret" "platform-auth-idp-credentials"
copy_resource "secret" "platform-auth-ldaps-ca-cert"
copy_resource "secret" "platform-oidc-credentials"
copy_resource "secret" "oauth-client-secret"
copy_resource "configmap" "ibm-cpp-config"
copy_resource "configmap" "common-web-ui-config"
copy_resource "configmap" "platform-auth-idp"
copy_resource "commonservice" "common-service" "preload-common-service-from-$FROM_NAMESPACE"
copy_resource "secret" "icp-mongodb-client-cert"
copy_resource "secret" "mongodb-root-ca-cert"
copy_resource "secret" "icp-mongodb-admin"
# any extra config
}

function parse_arguments() {
Expand Down Expand Up @@ -96,6 +104,9 @@ function parse_arguments() {
--rerun)
RERUN="true"
;;
--cleanup)
CLEANUP="true"
;;
-v | --debug)
shift
DEBUG=$1
Expand Down Expand Up @@ -125,6 +136,7 @@ function print_usage() {
echo " --original-cs-ns string Required. Namespace to migrate Cloud Pak 2 Foundational services data from."
echo " --services-ns string Required. Namespace to migrate Cloud Pak 2 Foundational services data too"
echo " --rerun Optional. If specified, will cleanup the previous attempt's mongo copy installed in specified services namespace before executing script."
echo " --cleanup Optional. Overrides --rerun. If specified, will cleanup the previous attempt's mongo copy installed in specified services namespace without executing the rest of the script."
echo " -v, --debug integer Optional. Verbosity of logs. Default is 0. Set to 1 for debug logs"
echo " -h, --help Print usage information"
echo ""
Expand Down Expand Up @@ -2051,6 +2063,10 @@ function success() {

function error() {
msg "\33[31m[✘] ${1}\33[0m"
echo "The script can be re-run using one of the following commands:"
echo "For simple cleanup to prepare another run: ./preload_data.sh --cleanup $ARGUMENTS"
echo "For an immediate re-run of preload_data: ./preload_data.sh --rerun $ARGUMENTS"
echo "Run ./preload_data.sh --help to see usage."
exit 1
}

Expand Down

0 comments on commit 5e83b7f

Please sign in to comment.