From 16fbdd07e60e6a252eac7fe0d7de5da3fdf21061 Mon Sep 17 00:00:00 2001 From: Johannes Malsam Date: Mon, 19 Jun 2023 15:12:00 +0200 Subject: [PATCH 1/5] replace PSP k8s version check with kubectl api-resources in e2e tests --- tests/e2e/lib.sh | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/e2e/lib.sh b/tests/e2e/lib.sh index 8b7e673ca0c06..f539a7b6ae947 100755 --- a/tests/e2e/lib.sh +++ b/tests/e2e/lib.sh @@ -368,21 +368,20 @@ setup_generated_certs_for_test() { setup_podsecuritypolicies_config() { info "Set POD_SECURITY_POLICIES variable based on kubernetes version" - local version - version=$(kubectl version --output json) - local majorVersion - majorVersion=$(echo "$version" | jq -r .serverVersion.major) - local minorVersion - minorVersion=$(echo "$version" | jq -r .serverVersion.minor) - - # PodSecurityPolicy was removed in version 1.25 - if (( "$majorVersion" >= 1 && "$minorVersion" >= 25 )); then - ci_export "POD_SECURITY_POLICIES" "false" - info "POD_SECURITY_POLICIES set to false" - else + available_api_resources=$(kubectl api-resources -o name) + + # using && true to ignore errexit option and store the command exit code in $? instead + echo $available_api_resources | grep -Fxq podsecuritypolicies.policy && true + + if [ $? ] + then ci_export "POD_SECURITY_POLICIES" "true" info "POD_SECURITY_POLICIES set to true" + else + ci_export "POD_SECURITY_POLICIES" "false" + info "POD_SECURITY_POLICIES set to false" fi + } # wait_for_collectors_to_be_operational() ensures that collector pods are able From a5717e57ec641b88067c1dfba69d808c029fc0ce Mon Sep 17 00:00:00 2001 From: Johannes Malsam Date: Mon, 19 Jun 2023 15:29:08 +0200 Subject: [PATCH 2/5] fix error code check --- tests/e2e/lib.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/lib.sh b/tests/e2e/lib.sh index f539a7b6ae947..4bf8f6ba92b30 100755 --- a/tests/e2e/lib.sh +++ b/tests/e2e/lib.sh @@ -371,9 +371,9 @@ setup_podsecuritypolicies_config() { available_api_resources=$(kubectl api-resources -o name) # using && true to ignore errexit option and store the command exit code in $? instead - echo $available_api_resources | grep -Fxq podsecuritypolicies.policy && true + echo $available_api_resources | grep -q podsecuritypolicies.policu && true - if [ $? ] + if [ $? -eq 0 ] then ci_export "POD_SECURITY_POLICIES" "true" info "POD_SECURITY_POLICIES set to true" From c4d2f26e0dbeff121d5b9c6911d8e8a453afe60a Mon Sep 17 00:00:00 2001 From: Johannes Malsam Date: Mon, 19 Jun 2023 15:30:49 +0200 Subject: [PATCH 3/5] fix typo --- tests/e2e/lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/lib.sh b/tests/e2e/lib.sh index 4bf8f6ba92b30..0298b3b307c93 100755 --- a/tests/e2e/lib.sh +++ b/tests/e2e/lib.sh @@ -371,7 +371,7 @@ setup_podsecuritypolicies_config() { available_api_resources=$(kubectl api-resources -o name) # using && true to ignore errexit option and store the command exit code in $? instead - echo $available_api_resources | grep -q podsecuritypolicies.policu && true + echo $available_api_resources | grep -q podsecuritypolicies.policy && true if [ $? -eq 0 ] then From a6e04796c4bb6677e0419145438c3e6a18e6976d Mon Sep 17 00:00:00 2001 From: Johannes Malsam Date: Tue, 20 Jun 2023 08:02:16 +0200 Subject: [PATCH 4/5] fix shell style --- tests/e2e/lib.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/e2e/lib.sh b/tests/e2e/lib.sh index 0298b3b307c93..171d8b917b527 100755 --- a/tests/e2e/lib.sh +++ b/tests/e2e/lib.sh @@ -370,10 +370,7 @@ setup_podsecuritypolicies_config() { info "Set POD_SECURITY_POLICIES variable based on kubernetes version" available_api_resources=$(kubectl api-resources -o name) - # using && true to ignore errexit option and store the command exit code in $? instead - echo $available_api_resources | grep -q podsecuritypolicies.policy && true - - if [ $? -eq 0 ] + if echo "$available_api_resources" | grep -q podsecuritypolicies.policy; then ci_export "POD_SECURITY_POLICIES" "true" info "POD_SECURITY_POLICIES set to true" From 61a9316f458a2042f73384e8a0e5c371031eac80 Mon Sep 17 00:00:00 2001 From: Johannes Malsam Date: Tue, 20 Jun 2023 11:18:03 +0200 Subject: [PATCH 5/5] use common approach to determine PSP support --- tests/e2e/lib.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/e2e/lib.sh b/tests/e2e/lib.sh index 171d8b917b527..8b2249a2dae86 100755 --- a/tests/e2e/lib.sh +++ b/tests/e2e/lib.sh @@ -368,17 +368,15 @@ setup_generated_certs_for_test() { setup_podsecuritypolicies_config() { info "Set POD_SECURITY_POLICIES variable based on kubernetes version" - available_api_resources=$(kubectl api-resources -o name) - if echo "$available_api_resources" | grep -q podsecuritypolicies.policy; - then - ci_export "POD_SECURITY_POLICIES" "true" - info "POD_SECURITY_POLICIES set to true" - else + SUPPORTS_PSP=$(kubectl api-resources | grep "podsecuritypolicies" -c || true) + if [[ "${SUPPORTS_PSP}" -eq 0 ]]; then ci_export "POD_SECURITY_POLICIES" "false" info "POD_SECURITY_POLICIES set to false" + else + ci_export "POD_SECURITY_POLICIES" "true" + info "POD_SECURITY_POLICIES set to true" fi - } # wait_for_collectors_to_be_operational() ensures that collector pods are able