Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand All @@ -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
Expand Down Expand Up @@ -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=""
Expand All @@ -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
Expand All @@ -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}"
Expand Down Expand Up @@ -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}"
Expand Down