From 3003fd45392512fbedc9520263110b381e1fc07d Mon Sep 17 00:00:00 2001 From: Atul Singh Date: Wed, 17 Aug 2022 11:01:16 -0400 Subject: [PATCH 1/3] server-2047-flyway-migration-job | added job deletion step --- kots-exporter/kots-exporter.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/kots-exporter/kots-exporter.sh b/kots-exporter/kots-exporter.sh index c1b9b75..a38136d 100755 --- a/kots-exporter/kots-exporter.sh +++ b/kots-exporter/kots-exporter.sh @@ -311,7 +311,8 @@ execute_flyway_migration(){ echo "Removing job/circle-migrator -" kubectl delete job/circle-migrator --namespace "$namespace" else - error_exit "Status wait timeout for job/circle-migrator, Check the Log via - kubectl logs pods -l app=circle-migrator" + echo "Status wait timeout for job/circle-migrator, Check the Log via - kubectl logs pods -l app=circle-migrator" + export job_migrator_status="unknown" fi } @@ -354,6 +355,18 @@ output_message(){ echo "- $path/output/helm-values.yaml" echo "" echo "-------------------------------------------------------------------------" + + if [[ "${job_migrator_status}" == "unknown" ]]; then + echo "## Delete circle-migrator job if completed" + echo "# Wait for job circle-migrator to complete... " + echo "kubectl wait job/circle-migrator --namespace $namespace --for condition='complete' --timeout=300s" + echo "# Check job status " + echo "kubectl get job/circle-migrator --namespace $namespace" + echo "# Delete the job once complete" + echo "kubectl delete job/circle-migrator --namespace $namespace" + echo "" + echo "-------------------------------------------------------------------------" + fi echo "## Postgres Chart Upgrade Preparation" echo "Upgrading to server CircleCI Server 4.0 includes upgrading the Postgres chart" From 619833dc56aac6ccb864cb4576239c46f9c3d846 Mon Sep 17 00:00:00 2001 From: Atul Singh Date: Wed, 17 Aug 2022 12:39:03 -0400 Subject: [PATCH 2/3] server-2047-flyway-migration-job | added post check --- kots-exporter/kots-exporter.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/kots-exporter/kots-exporter.sh b/kots-exporter/kots-exporter.sh index a38136d..4111f97 100755 --- a/kots-exporter/kots-exporter.sh +++ b/kots-exporter/kots-exporter.sh @@ -67,6 +67,22 @@ check_prereq(){ if ! kubectl get secret/regcred -n "$namespace" -o name > /dev/null 2>&1 then error_exit "Secret regcred does not exist in k8s namespace - $namespace" + fi +} + +check_postreq(){ + echo "" + echo "############ CHECKING K8S NAMESPACE and HELM RELEASE ################" + # check if helm release exists + if [[ "$(helm list -o yaml | yq '.[].name')" != "$slug" ]] + then + error_exit "Helm release $slug does not exist." + fi + + # check if namespace exists + if ! kubectl get ns "$namespace" -o name > /dev/null 2>&1 + then + error_exit "Namespace $namespace does not exist in k8s cluster." fi } @@ -308,6 +324,9 @@ execute_flyway_migration(){ echo "Waiting job/circle-migrator to complete -" if (kubectl wait job/circle-migrator --namespace "$namespace" --for condition="complete" --timeout=300s); then echo "++++ DB Migration job is successful." + echo "Fetching pod logs -" + kubectl -n "$namespace" logs "$(kubectl -n $namespace get pods -l app=circle-migrator -o name)" > "$path"/logs/circle-migrator.log + echo "Pod log is available at $path/logs/circle-migrator.log" echo "Removing job/circle-migrator -" kubectl delete job/circle-migrator --namespace "$namespace" else @@ -457,6 +476,7 @@ done check_prereq check_required_args set_default_value +check_postreq if [[ "$func" == "flyway" ]]; then execute_flyway_migration elif [[ "$func" == "annotate" ]]; then @@ -480,4 +500,4 @@ else echo "############ ERROR ################" echo "-f $func is not a valid function" help_init_options -fi +fi \ No newline at end of file From 0f0b3811642c6bd3e76b172db39f87654c0a3a58 Mon Sep 17 00:00:00 2001 From: Atul Singh Date: Wed, 17 Aug 2022 15:38:24 -0400 Subject: [PATCH 3/3] server-2047-flyway-migration-job | suffle post check --- kots-exporter/kots-exporter.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/kots-exporter/kots-exporter.sh b/kots-exporter/kots-exporter.sh index 4111f97..8e11061 100755 --- a/kots-exporter/kots-exporter.sh +++ b/kots-exporter/kots-exporter.sh @@ -61,13 +61,7 @@ check_prereq(){ if ! command -v yq -V &> /dev/null then error_exit "yq could not be found." - fi - - # check if secret/regcred exists - if ! kubectl get secret/regcred -n "$namespace" -o name > /dev/null 2>&1 - then - error_exit "Secret regcred does not exist in k8s namespace - $namespace" - fi + fi } check_postreq(){ @@ -84,6 +78,12 @@ check_postreq(){ then error_exit "Namespace $namespace does not exist in k8s cluster." fi + + # check if secret/regcred exists + if ! kubectl get secret/regcred -n "$namespace" -o name > /dev/null 2>&1 + then + error_exit "Secret regcred does not exist in k8s namespace - $namespace" + fi } check_required_args(){ @@ -402,6 +402,11 @@ output_message(){ echo "" echo "-------------------------------------------------------------------------" + echo "## Helm login to cciserver.azurecr.io" + echo "export HELM_EXPERIMENTAL_OCI=1" + echo "helm registry login cciserver.azurecr.io --username --password " + echo "" + echo "## Helm Diff (optional)" echo "The Helm Diff tool is used to verify that the changes between your current install and the upgrade are expected." echo ""