From a232d0f0095d97b2c063d33be33d93f149e32339 Mon Sep 17 00:00:00 2001 From: Johnny Liu Date: Wed, 27 Nov 2024 19:01:43 +0800 Subject: [PATCH] correct capacity check in upgrade cases --- ...shift-upgrade-check-capability-commands.sh | 74 +++++++++++++------ 1 file changed, 52 insertions(+), 22 deletions(-) diff --git a/ci-operator/step-registry/cucushift/upgrade/check/capability/cucushift-upgrade-check-capability-commands.sh b/ci-operator/step-registry/cucushift/upgrade/check/capability/cucushift-upgrade-check-capability-commands.sh index 6394ff884450b..7ed1c317663e0 100644 --- a/ci-operator/step-registry/cucushift/upgrade/check/capability/cucushift-upgrade-check-capability-commands.sh +++ b/ci-operator/step-registry/cucushift/upgrade/check/capability/cucushift-upgrade-check-capability-commands.sh @@ -102,6 +102,7 @@ function extract_manifests() { fi # Extract manifests + echo "INFO: Extracting manifest to ${work_dir} from ${release}" if ! oc adm release extract -a "${CLUSTER_PROFILE_DIR}/pull-secret" --to ${work_dir} --from ${release}; then echo "ERROR: Extracting manifest failed" return 1 @@ -170,25 +171,16 @@ function get_new_caps() { # compares two payloads for capabilities difference at manifest level function extract_migrated_caps() { - echo "Extracting migrated caps between 2 releases..." - local source="$1" - local target="$2" - local source_dir target_dir source_cap_files + local source_dir="$1" + local target_dir="$2" + local source_cap_files source_file filename target_file source_cap target_cap # Check for missing environment variables - if [ -z "$source" ] || [ -z "$target" ]; then + if [ -z "$source_dir" ] || [ -z "$target_dir" ]; then echo "ERROR: Missing required arguments" return 1 fi - source_dir="/tmp/source" - target_dir="/tmp/target" - mkdir -p ${source_dir} ${target_dir} - - if ! extract_manifests "${source_dir}" "${source}" || ! extract_manifests "${target_dir}" "${target}"; then - return 1 - fi - source_cap_files=$(grep -rl "capability.openshift.io/name" ${source_dir}) for source_file in ${source_cap_files}; do filename=$(basename "${source_file}") @@ -213,8 +205,34 @@ function extract_migrated_caps() { done } -function check_cvo_cap() { +# Get the capabilities which are introdcued for the 1st time in the target payload +# By comparing two payloads at manifest level +function extract_potential_new_caps() { + local source_dir="$1" + local target_dir="$2" + local target_cap_files target_file filename source_file target_cap + local candidate_new_caps="" + + # Check for missing environment variables + if [ -z "$source_dir" ] || [ -z "$target_dir" ]; then + echo "ERROR: Missing required arguments" + return 1 + fi + + target_cap_files=$(grep -rl "capability.openshift.io/name" ${target_dir}) + for target_file in ${target_cap_files}; do + filename=$(basename "${target_file}") + source_file="$source_dir/$filename" + if [ ! -f "$source_file" ]; then + target_cap=$(grep 'capability.openshift.io/name:' "$target_file" | cut -d ':' -f2 | tr -d '"' | sort | uniq ) + candidate_new_caps="${candidate_new_caps} ${target_cap}" + fi + done + echo "${candidate_new_caps}" | xargs -n1 | sort -u | xargs +} + +function check_cvo_cap() { local result=0 local capability_set=$1 local expected_status=$2 @@ -298,10 +316,12 @@ caps_resource[Build]="builds buildconfigs" caps_resource[DeploymentConfig]="deploymentconfigs" # Initialize the variables +source_manifests_dir=$(mktemp -d) +extract_manifests "${source_manifests_dir}" "${version_set[-1]}" +target_manifests_dir=$(mktemp -d) +extract_manifests "${target_manifests_dir}" "${version_set[0]}" declare -A migrated_caps=() -if ! extract_migrated_caps "${version_set[-1]}" "${version_set[0]}"; then - echo "ERROR: extract_migrated_caps failed" && exit 1 -fi +extract_migrated_caps "${source_manifests_dir}" "${target_manifests_dir}" expected_enabled_caps="" expected_implicit_caps="" @@ -313,14 +333,22 @@ target_baseline_caps=$(get_caps_for_version_capset "${version_set[0]}" "${baseli source_known_caps=$(get_caps_for_version_capset "${version_set[-1]}" "vCurrent") target_known_caps=$(get_caps_for_version_capset "${version_set[0]}" "vCurrent") +echo -e "\nsource_baseline_caps is ${source_baseline_caps}\ +\ntarget_baseline_caps is ${target_baseline_caps}\ +\nsource_known_caps is ${source_known_caps}\ +\ntarget_known_caps is ${target_known_caps}" + new_caps=$(get_new_caps "${source_known_caps}" "${target_known_caps}") +echo -e "\nnew_caps is ${new_caps}" +potential_new_caps=$(extract_potential_new_caps "${source_manifests_dir}" "${target_manifests_dir}") +for cap in $potential_new_caps; do + new_caps=${new_caps/$cap} +done +echo -e "after strip those capacities which are not existing in source version and introduced for the 1st time in target version\ +\nnew_caps is ${new_caps}" additionalcaps_from_cluster=$(oc get clusterversion version -ojson | jq -r 'if .spec.capabilities.additionalEnabledCapabilities then .spec.capabilities.additionalEnabledCapabilities[] else empty end') - -echo -e "\nsource_baseline_caps is ${source_baseline_caps}\ -\ntarget_baseline_caps is ${target_baseline_caps}\ -\nsource_known_caps is ${source_known_caps}\ntarget_known_caps is ${target_known_caps}\ -\nnew_caps is ${new_caps}\nadditionalcaps_from_cluster is ${additionalcaps_from_cluster}" +echo -e "\nadditionalcaps_from_cluster is ${additionalcaps_from_cluster}" # vCurrent baseline set should grow new caps of target version explicitly after upgrade if [[ "${baselinecaps_from_cluster}" == "vCurrent" ]]; then @@ -330,6 +358,7 @@ fi # v4.x baseline set should grow new caps in v4.x of target version explicitly after upgrade # v4.x baseline set should grow new caps in target version implicitly # v4.x baseline set should grow new caps implicitly after upgrade if cap migrates to a cap out of v4.x & additional caps of target version +# NOTE: here "new caps" means caps are existing in previous version, become optional operators in target version if [[ "${baselinecaps_from_cluster}" == "v4."* ]]; then source_enabled_caps="${source_baseline_caps} ${additionalcaps_from_cluster}" target_enabled_caps="${target_baseline_caps} ${additionalcaps_from_cluster}" @@ -374,6 +403,7 @@ fi # None baseline set should grow new caps of target version implicitly after upgrade # None baseline set should grow new caps if caps migrate to someones that are not in additional caps +# NOTE: here "new caps" means caps are existing in previous version, become optional operators in target version if [[ "${baselinecaps_from_cluster}" == "None" ]]; then expected_enabled_caps="${additionalcaps_from_cluster}" expected_enabled_caps="${expected_enabled_caps} ${new_caps}"