Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SERVER-2047 | added job deletion step #23

Merged
merged 3 commits into from
Aug 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions kots-exporter/kots-exporter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,29 @@ check_prereq(){
if ! command -v yq -V &> /dev/null
then
error_exit "yq could not be found."
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

# 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_required_args(){
Expand Down Expand Up @@ -308,10 +324,14 @@ 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
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
}

Expand Down Expand Up @@ -354,6 +374,18 @@ output_message(){
echo "- $path/output/helm-values.yaml"
echo ""
echo "-------------------------------------------------------------------------"

atulsingh0 marked this conversation as resolved.
Show resolved Hide resolved
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"
Expand All @@ -370,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 <image-registry-username> --password <image-registry-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 ""
Expand Down Expand Up @@ -444,6 +481,7 @@ done
check_prereq
check_required_args
set_default_value
check_postreq
if [[ "$func" == "flyway" ]]; then
execute_flyway_migration
elif [[ "$func" == "annotate" ]]; then
Expand All @@ -467,4 +505,4 @@ else
echo "############ ERROR ################"
echo "-f $func is not a valid function"
help_init_options
fi
fi