From 3821d6eaf31fdc8591164d897a1840a74a918d17 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Thu, 9 Jan 2025 11:17:17 +0800 Subject: [PATCH] Cleanup .modified pipeline files Also update comments accordingly to make it clear what pipeline files are used to check validity. Signed-off-by: Chenxiong Qi --- hack/validate-migration.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/hack/validate-migration.sh b/hack/validate-migration.sh index ca03e9a872..dbc53d1123 100755 --- a/hack/validate-migration.sh +++ b/hack/validate-migration.sh @@ -101,6 +101,7 @@ list_preprocessed_pipelines() { # This function checks two aspects: # - whether the migration file exits successfully or not. # - whether the migration file modifies a pipeline. If nothing changed, it is treated a failure. +# The modified pipeline is saved into a separate file with suffix '.modified'. check_apply_on_pipelines() { local -r migration_file=$1 local -r run_log_file=$(mktemp --suffix=-migration-run-test) @@ -300,8 +301,15 @@ check_apply_in_real_cluster() { else kubectl create namespace ${K8S_TEST_NS} fi - local -r apply_logfile=$(mktemp --suffix="-${FUNCNAME[0]}") - local -r modified_pipeline_files=$(find "${WORK_DIR}/pipelines" -type f -name "*.modified") + local apply_logfile + local modified_pipeline_files + apply_logfile=$(mktemp --suffix="-${FUNCNAME[0]}") + modified_pipeline_files=$(find "${WORK_DIR}/pipelines" -type f -name "*.modified") + if [ -z "$modified_pipeline_files" ]; then + echo "error: No modified pipeline file is found." >&2 + echo "error: Please check if migrations work correctly to update pipelines." >&2 + exit 1 + fi while read -r pl_file; do if ! kubectl apply -f "$pl_file" -n ${K8S_TEST_NS} 2>"$apply_logfile" >/dev/null; then echo "${FUNCNAME[0]}: failed to apply pipeline to cluster: $pl_file" >&2 @@ -338,6 +346,8 @@ main() { check_pass_shellcheck "$migration_file" check_migrations_is_in_task_version_specific_dir "$migration_file" check_version_match "$migration_file" + # Cleanup any existing pipeline files modified previously. + find "${WORK_DIR}/pipelines" -type f -name "*.modified" -delete check_apply_on_pipelines "$migration_file" check_apply_in_real_cluster done