From efa8ab3cd2b7013720d7e95830a8352693998b90 Mon Sep 17 00:00:00 2001 From: Julien Leduc <julien.leduc@cern.ch> Date: Tue, 14 Jan 2020 11:59:40 +0100 Subject: [PATCH] Cleanup leftover namespaces before launching the kubernetes CI tests --- .gitlab-ci.yml | 6 +++--- .../orchestration/run_systemtest.sh | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f0cc60ebc8..9cd5d16ae5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -237,7 +237,7 @@ archiveretrieve: retry: 1 script: - export NAMESPACE="archiveretrieve-${CTA_BUILD_ID}-$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 4 | head -n 1)" - - cd continuousintegration/orchestration/; ./run_systemtest.sh -n ${NAMESPACE} -p ${CI_PIPELINE_ID} -s tests/archive_retrieve.sh -O -D -t 2400 + - cd continuousintegration/orchestration/; ./run_systemtest.sh -n ${NAMESPACE} -p ${CI_PIPELINE_ID} -s tests/archive_retrieve.sh -O -D -t 2400 -C artifacts: when: always expire_in: 30 days @@ -254,7 +254,7 @@ repack: retry: 1 script: - export NAMESPACE="repack-${CTA_BUILD_ID}-$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 4 | head -n 1)" - - cd continuousintegration/orchestration/; ./run_systemtest.sh -n ${NAMESPACE} -p ${CI_PIPELINE_ID} -s tests/repack_systemtest_wrapper.sh -O -D -t 2400 + - cd continuousintegration/orchestration/; ./run_systemtest.sh -n ${NAMESPACE} -p ${CI_PIPELINE_ID} -s tests/repack_systemtest_wrapper.sh -O -D -t 2400 -C artifacts: when: always expire_in: 30 days @@ -271,7 +271,7 @@ dbunittests_oracle: retry: 1 script: - export NAMESPACE="dbunittestsoracle-${CTA_BUILD_ID}-$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 4 | head -n 1)" - - cd continuousintegration/orchestration/; ./run_systemtest.sh -n ${NAMESPACE} -p ${CI_PIPELINE_ID} -s /usr/bin/true -O -D -U -t 600 + - cd continuousintegration/orchestration/; ./run_systemtest.sh -n ${NAMESPACE} -p ${CI_PIPELINE_ID} -s /usr/bin/true -O -D -U -t 600 -C artifacts: when: always expire_in: 30 days diff --git a/continuousintegration/orchestration/run_systemtest.sh b/continuousintegration/orchestration/run_systemtest.sh index 1d3cc7ea92..149b323800 100755 --- a/continuousintegration/orchestration/run_systemtest.sh +++ b/continuousintegration/orchestration/run_systemtest.sh @@ -26,7 +26,8 @@ PREFLIGHTTEST_SCRIPT='tests/preflighttest.sh' PREFLIGHTTEST_TIMEOUT=60 # default systemtest timeout is 1 hour SYSTEMTEST_TIMEOUT=3600 - +# by default do not cleanup leftover namespaces +cleanup_namespaces=0 die() { echo "$@" 1>&2 ; exit 1; } @@ -43,7 +44,7 @@ Options: -S Use systemd to manage services inside containers -a additional kubernetes resources added to the kubernetes namespace -U Run database unit test only - + -C Cleanup leftover kubernetes namespaces Create a kubernetes instance and launch the system test script specified. Makes sure the created instance is cleaned up at the end and return the status of the system test. @@ -56,7 +57,7 @@ exit 1 # always delete DB and OBJECTSTORE for tests CREATE_OPTS="-D -O" -while getopts "n:d:s:p:b:e:a:B:t:kDOSU" o; do +while getopts "n:d:s:p:b:e:a:B:t:kDOSUC" o; do case "${o}" in s) systemtest_script=${OPTARG} @@ -103,6 +104,9 @@ while getopts "n:d:s:p:b:e:a:B:t:kDOSU" o; do CREATE_OPTS="${CREATE_OPTS} -U" PREFLIGHTTEST_SCRIPT='/usr/bin/true' # we do not run preflight test in the context of unit tests ;; + C) + cleanup_namespaces=1 + ;; *) usage ;; @@ -155,6 +159,12 @@ fi log_dir="${orchestration_dir}/../../pod_logs/${namespace}" mkdir -p ${log_dir} +if [ $cleanup_namespaces == 1 ]; then + echo "Cleaning up old namespaces:" + kubectl get namespace -o json | jq '.items[].metadata | select(.name != "default" and .name != "kube-system") | .name' | egrep '\-[0-9]+git' + kubectl get namespace -o json | jq '.items[].metadata | select(.name != "default" and .name != "kube-system") | .name' | egrep '\-[0-9]+git' | xargs -itoto ./delete_instance.sh -n toto -D + echo DONE +fi function execute_log { mycmd=$1 -- GitLab