From b463960b8f7ee3b9d4e4e301062490d1ed624a7f Mon Sep 17 00:00:00 2001 From: Greg O'Grady Date: Wed, 11 Dec 2024 17:33:21 -0500 Subject: [PATCH] refactor: env_name.txt to always have the used env name --- .../vfcli-create-or-get-free-env-from-pool.yml | 13 ++++--------- .../vfcli/vfcli-delete-or-release-env.yml | 2 +- src/commands/vfcli/vfcli-suspend-env.yml | 15 ++++++--------- src/jobs/e2e/collect-e2e-logs.yml | 8 ++++---- src/jobs/smoke/report_smoke_failures.yml | 3 ++- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/commands/vfcli/vfcli-create-or-get-free-env-from-pool.yml b/src/commands/vfcli/vfcli-create-or-get-free-env-from-pool.yml index 53dd0f4c..360c8d04 100644 --- a/src/commands/vfcli/vfcli-create-or-get-free-env-from-pool.yml +++ b/src/commands/vfcli/vfcli-create-or-get-free-env-from-pool.yml @@ -33,17 +33,15 @@ steps: # otherwise creates a new environment with the provided name # and stores the env name in the cache force="<< parameters.force >>" + + echo "<< parameters.env-name >>" >env_name.txt # default use the passed in env name if [[ -n "<< parameters.pool-type >>" ]]; then if [[ $force == true ]]; then echo "Force option is enabled... Proceeding with environment creation." - echo "null" > env_name.txt # Write 'null' to indicate no environment was found - echo "create" > skip_create_env else result=$(vfcli pool get-free-env --pool-type "<< parameters.pool-type >>" --output json) if [[ -z $result ]] || [[ $(echo "$result" | jq 'keys | length') -eq 0 ]]; then echo "No free environment found. Proceeding with environment creation." - echo "null" > env_name.txt # Write 'null' to indicate no environment was found - echo "create" > skip_create_env else echo "Free environment found: $result" env_name=$(echo "$result" | jq -r '.name') @@ -51,14 +49,11 @@ steps: cat env_name.txt echo "export ENV_NAME=${env_name}" >> $BASH_ENV vfcli pool use-env --env-name ${env_name} - echo "skip" > skip_create_env # Indicate no need to create environment - exit 0 # Skip environment creation + exit 0 fi fi else echo "Pool type not provided." - echo "null" > env_name.txt # Handle case where pool-type is not provided - echo "create" > skip_create_env fi - save_cache: @@ -69,7 +64,7 @@ steps: - run: name: Create environment command: | - if [[ -f skip_create_env && $(cat skip_create_env) != "skip" ]]; then + if [[ $(cat env_name.txt) != "<< parameters.env-name >>" ]]; then if [ -n "<< parameters.track-file >>" ]; then TRACK_ARG=("--track-file" "<< parameters.track-file >>") fi diff --git a/src/commands/vfcli/vfcli-delete-or-release-env.yml b/src/commands/vfcli/vfcli-delete-or-release-env.yml index fc26bff1..8fd15e13 100644 --- a/src/commands/vfcli/vfcli-delete-or-release-env.yml +++ b/src/commands/vfcli/vfcli-delete-or-release-env.yml @@ -31,7 +31,7 @@ steps: if [[ $force == true ]]; then vfcli env delete --name "<< parameters.env-name >>" --interactive false else - if [[ -f << parameters.env-name-path >> ]]; then + if [ -f << parameters.env-name-path >> ] && [ "$(cat << parameters.env-name-path >> )" != "null" ]; then env_name=$(cat << parameters.env-name-path >>) echo "Env: $env_name will be released" else diff --git a/src/commands/vfcli/vfcli-suspend-env.yml b/src/commands/vfcli/vfcli-suspend-env.yml index c29e920b..b0e33efd 100644 --- a/src/commands/vfcli/vfcli-suspend-env.yml +++ b/src/commands/vfcli/vfcli-suspend-env.yml @@ -17,17 +17,14 @@ steps: - run: name: Suspend Environment command: | - echo "Contents of << parameters.env-name-path >>:" - cat << parameters.env-name-path >> - if [[ -f << parameters.env-name-path >> ]]; then + if [ -f << parameters.env-name-path >> ] && + [ -n "$(cat << parameters.env-name-path >> )" ] && + [ "$(cat << parameters.env-name-path >> )" != "null" ]; then + echo "Using env_name from file << parameters.env-name-path >> in the suspend action" env_name=$(cat << parameters.env-name-path >>) else env_name="<< parameters.env-name >>" fi - if [[ "$env_name" == "null" ]] || [[ -z "$env_name" ]]; then - # If env_name from file is "null" or empty, use the default parameter - env_name="<< parameters.env-name >>" - fi - - vfcli env suspend "$env_name" --interactive false --wait --track-file "<< parameters.track-file >>" + echo "Using env: ${env_name-}" + vfcli env suspend "${env_name-}" --interactive false --wait --track-file "<< parameters.track-file >>" diff --git a/src/jobs/e2e/collect-e2e-logs.yml b/src/jobs/e2e/collect-e2e-logs.yml index 4cca86ae..7206524b 100644 --- a/src/jobs/e2e/collect-e2e-logs.yml +++ b/src/jobs/e2e/collect-e2e-logs.yml @@ -44,10 +44,10 @@ steps: echo "Contents of << parameters.env-name-path >>:" cat << parameters.env-name-path >> if [ -f << parameters.env-name-path >> ] && [ "$(cat << parameters.env-name-path >> )" != "null" ]; then - DEV_ENV_NAME=$(cat << parameters.env-name-path >> ) - else - DEV_ENV_NAME=<< parameters.e2e-env-name >> - fi + DEV_ENV_NAME=$(cat << parameters.env-name-path >> ) + else + DEV_ENV_NAME=<< parameters.e2e-env-name >> + fi # Gather summary state of all pods in the namespace echo "Gathering Kubernetes state before run for env $DEV_ENV_NAME" kubectl get pods -n $DEV_ENV_NAME >> "${LOG_DIR:?}/${KUBE_STATE_DIR:?}/pods-summary-state-before-run.log" diff --git a/src/jobs/smoke/report_smoke_failures.yml b/src/jobs/smoke/report_smoke_failures.yml index 892d77b4..54db0c19 100644 --- a/src/jobs/smoke/report_smoke_failures.yml +++ b/src/jobs/smoke/report_smoke_failures.yml @@ -26,7 +26,8 @@ steps: - run: name: Report Test Failures command: | - if [[ -f << parameters.env-name-path >> ]]; then + + if [ -f << parameters.env-name-path >> ] && [ "$(cat << parameters.env-name-path >> )" != "null" ]; then echo "Using env_name from file << parameters.env-name-path >> in the suspend action" env_name=$(cat << parameters.env-name-path >>) else