Skip to content

Commit a1ecfa1

Browse files
committed
Fix: refine functions
Signed-off-by: Penghao <[email protected]>
1 parent 9fb036e commit a1ecfa1

File tree

1 file changed

+71
-42
lines changed

1 file changed

+71
-42
lines changed

prow.sh

Lines changed: 71 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -856,20 +856,20 @@ inject_vgs_feature_gate() {
856856
fi
857857
}
858858

859-
# Replace controller image based on the deployment mode
859+
# Replace the snapshot controller image based on the test mode
860860
# Arguments:
861861
# $1: yaml content
862-
# $2: mode ("external-snapshotter", "canary", or "default")
863-
# $3: new_tag (for external-snapshotter mode)
862+
# $2: mode ("local-build", "canary", or "default")
863+
# $3: new_tag (for local-build mode)
864864
# $4: registry (for canary mode)
865-
replace_controller_image() {
865+
replace_snapshot_controller_image() {
866866
local yaml="$1"
867867
local mode="$2"
868868
local new_tag="${3:-}"
869869
local registry="${4:-}"
870870

871871
case "$mode" in
872-
external-snapshotter)
872+
local-build)
873873
# Replace with snapshot-controller:new_tag
874874
echo "$yaml" | sed -E \
875875
"s|^([[:space:]]*image: )(.*snapshot-controller):[^[:space:]]*|\1snapshot-controller:${new_tag}|"
@@ -936,7 +936,7 @@ install_snapshot_controller() {
936936
# Replace image in SNAPSHOT_CONTROLLER_YAML with snapshot-controller:csiprow and deploy
937937
# NOTE: This logic is similar to the logic here:
938938
# https://github.com/kubernetes-csi/csi-driver-host-path/blob/v1.4.0/deploy/util/deploy-hostpath.sh#L155
939-
modified="$(replace_controller_image "$yaml" "external-snapshotter" "$NEW_TAG" | inject_vgs_feature_gate)"
939+
modified="$(replace_snapshot_controller_image "$yaml" "local-build" "$NEW_TAG" | inject_vgs_feature_gate)"
940940
diff <(echo "$yaml") <(echo "$modified")
941941
if ! echo "$modified" | kubectl apply -f -; then
942942
echo "modified version of ${SNAPSHOT_CONTROLLER_YAML}:"
@@ -945,7 +945,7 @@ install_snapshot_controller() {
945945
fi
946946
elif [ "${CSI_PROW_DRIVER_CANARY}" = "canary" ]; then
947947
echo "Deploying snapshot-controller from ${SNAPSHOT_CONTROLLER_YAML} with canary images."
948-
modified="$(replace_controller_image "$yaml" "canary" "" "${CSI_PROW_DRIVER_CANARY_REGISTRY}" | inject_vgs_feature_gate)"
948+
modified="$(replace_snapshot_controller_image "$yaml" "canary" "" "${CSI_PROW_DRIVER_CANARY_REGISTRY}" | inject_vgs_feature_gate)"
949949
diff <(echo "$yaml") <(echo "$modified")
950950
if ! echo "$modified" | kubectl apply -f -; then
951951
echo "modified version of ${SNAPSHOT_CONTROLLER_YAML}:"
@@ -955,7 +955,7 @@ install_snapshot_controller() {
955955
else
956956
echo "kubectl apply -f $SNAPSHOT_CONTROLLER_YAML"
957957
# Replace snapshot-controller container tag to make it consistent with CSI_SNAPSHOTTER_VERSION
958-
modified="$(replace_controller_image "$yaml" "default" | inject_vgs_feature_gate)"
958+
modified="$(replace_snapshot_controller_image "$yaml" "default" | inject_vgs_feature_gate)"
959959
diff <(echo "$yaml") <(echo "$modified")
960960
if ! echo "$modified" | kubectl apply -f -; then
961961
echo "modified version of ${SNAPSHOT_CONTROLLER_YAML}:"
@@ -1060,23 +1060,24 @@ install_e2e () {
10601060
if sidecar_tests_enabled; then
10611061
run_with_go "${CSI_PROW_GO_VERSION_BUILD}" go test -c -o "${CSI_PROW_WORK}/e2e-local.test" "${CSI_PROW_SIDECAR_E2E_IMPORT_PATH}"
10621062
fi
1063-
1063+
1064+
local e2e_src_dir
10641065
# In kubernetes presubmit do not need clone the src
10651066
if [[ $(basename "${REPO_DIR}") == "kubernetes" ]]; then
10661067
echo "Using existing repo at ${REPO_DIR}"
1067-
E2E_SRC_DIR="${REPO_DIR}"
1068+
e2e_src_dir="${REPO_DIR}"
10681069
else
10691070
git_checkout "${CSI_PROW_E2E_REPO}" "${GOPATH}/src/${CSI_PROW_E2E_IMPORT_PATH}" "${CSI_PROW_E2E_VERSION}" --depth=1
1070-
E2E_SRC_DIR="${GOPATH}/src/${CSI_PROW_E2E_IMPORT_PATH}"
1071+
e2e_src_dir="${GOPATH}/src/${CSI_PROW_E2E_IMPORT_PATH}"
10711072
fi
10721073

10731074
if [ "${CSI_PROW_E2E_IMPORT_PATH}" = "k8s.io/kubernetes" ]; then
10741075
patch_kubernetes "${GOPATH}/src/${CSI_PROW_E2E_IMPORT_PATH}" "${CSI_PROW_WORK}" &&
1075-
go_version="${CSI_PROW_GO_VERSION_E2E:-$(go_version_for_kubernetes "${E2E_SRC_DIR}" "${CSI_PROW_E2E_VERSION}")}" &&
1076-
run_with_go "$go_version" make WHAT=test/e2e/e2e.test "-C${E2E_SRC_DIR}" &&
1077-
ln -s "${E2E_SRC_DIR}/_output/bin/e2e.test" "${CSI_PROW_WORK}" &&
1078-
run_with_go "$go_version" make WHAT=vendor/github.com/onsi/ginkgo/ginkgo "-C${E2E_SRC_DIR}" &&
1079-
ln -s "${E2E_SRC_DIR}/_output/bin/ginkgo" "${CSI_PROW_BIN}"
1076+
go_version="${CSI_PROW_GO_VERSION_E2E:-$(go_version_for_kubernetes "${e2e_src_dir}" "${CSI_PROW_E2E_VERSION}")}" &&
1077+
run_with_go "$go_version" make WHAT=test/e2e/e2e.test "-C${e2e_src_dir}" &&
1078+
ln -s "${e2e_src_dir}/_output/bin/e2e.test" "${CSI_PROW_WORK}" &&
1079+
run_with_go "$go_version" make WHAT=vendor/github.com/onsi/ginkgo/ginkgo "-C${e2e_src_dir}" &&
1080+
ln -s "${e2e_src_dir}/_output/bin/ginkgo" "${CSI_PROW_BIN}"
10801081
else
10811082
run_with_go "${CSI_PROW_GO_VERSION_E2E}" go test -c -o "${CSI_PROW_WORK}/e2e.test" "${CSI_PROW_E2E_IMPORT_PATH}/test/e2e"
10821083
fi
@@ -1119,33 +1120,56 @@ run_e2e () (
11191120
# the full Kubernetes E2E testsuite while only running a few tests.
11201121
# shellcheck disable=SC2329
11211122
move_junit () {
1122-
# shellcheck disable=SC2317
1123-
FILTER='External.Storage|CSI.mock.volume'
1124-
# shellcheck disable=SC2317
1125-
if [ "${CSI_PROW_ENABLE_GROUP_SNAPSHOT}" = "true" ]; then
1126-
FILTER="${FILTER}|\[Feature:volumegroupsnapshot\]"
1127-
fi
1128-
11291123
# shellcheck disable=SC2317
11301124
if ls "${ARTIFACTS}"/junit_[0-9]*.xml 2>/dev/null >/dev/null; then
11311125
mkdir -p "${ARTIFACTS}/junit/${name}" &&
11321126
mkdir -p "${ARTIFACTS}/junit/steps" &&
1133-
run_filter_junit -t="${FILTER}" -o "${ARTIFACTS}/junit/steps/junit_${name}.xml" "${ARTIFACTS}"/junit_[0-9]*.xml &&
1127+
run_filter_junit -t="External.Storage|CSI.mock.volume" -o "${ARTIFACTS}/junit/steps/junit_${name}.xml" "${ARTIFACTS}"/junit_[0-9]*.xml &&
11341128
mv "${ARTIFACTS}"/junit_[0-9]*.xml "${ARTIFACTS}/junit/${name}/"
11351129
fi
11361130
}
1137-
trap move_junit EXIT
1138-
1139-
if [ "${name}" == "local" ]; then
1140-
cd "${GOPATH}/src/${CSI_PROW_SIDECAR_E2E_PATH}" &&
1141-
run_with_loggers env KUBECONFIG="$KUBECONFIG" KUBE_TEST_REPO_LIST="$(if [ -e "${CSI_PROW_WORK}/e2e-repo-list" ]; then echo "${CSI_PROW_WORK}/e2e-repo-list"; fi)" ginkgo --timeout="${CSI_PROW_GINKGO_TIMEOUT}" -v "$@" "${CSI_PROW_WORK}/e2e-local.test" -- -report-dir "${ARTIFACTS}" -report-prefix local
1142-
elif [ "${CSI_PROW_ENABLE_GROUP_SNAPSHOT}" = "true" ] && [ "${name}" == "parallel-features" ]; then
1143-
cd "${GOPATH}/src/${CSI_PROW_E2E_IMPORT_PATH}" &&
1144-
run_with_loggers env KUBECONFIG="$KUBECONFIG" KUBE_TEST_REPO_LIST="$(if [ -e "${CSI_PROW_WORK}/e2e-repo-list" ]; then echo "${CSI_PROW_WORK}/e2e-repo-list"; fi)" ginkgo --timeout="${CSI_PROW_GINKGO_TIMEOUT}" -v "$@" "${CSI_PROW_WORK}/e2e.test" -- -report-dir "${ARTIFACTS}" -report-prefix vgs
1131+
1132+
# Only set up move_junit for non-VGS tests
1133+
if [ "$name" != "vgs" ]; then
1134+
trap move_junit EXIT
1135+
fi
1136+
1137+
# Determine ginkgo target and options
1138+
local ginkgo_target=""
1139+
local extra_args=""
1140+
local e2e_src_dir=""
1141+
local args=()
1142+
1143+
if [[ $(basename "${REPO_DIR}") == "kubernetes" ]]; then
1144+
e2e_src_dir="${REPO_DIR}"
11451145
else
1146-
cd "${GOPATH}/src/${CSI_PROW_E2E_IMPORT_PATH}" &&
1147-
run_with_loggers env KUBECONFIG="$KUBECONFIG" KUBE_TEST_REPO_LIST="$(if [ -e "${CSI_PROW_WORK}/e2e-repo-list" ]; then echo "${CSI_PROW_WORK}/e2e-repo-list"; fi)" ginkgo --timeout="${CSI_PROW_GINKGO_TIMEOUT}" -v "$@" "${CSI_PROW_WORK}/e2e.test" -- -report-dir "${ARTIFACTS}" -storage.testdriver="${CSI_PROW_WORK}/test-driver.yaml"
1146+
e2e_src_dir="${GOPATH}/src/${CSI_PROW_E2E_IMPORT_PATH}"
11481147
fi
1148+
1149+
case "$name" in
1150+
local)
1151+
ginkgo_target="${CSI_PROW_WORK}/e2e-local.test"
1152+
extra_args="-report-prefix local"
1153+
cd "${GOPATH}/src/${CSI_PROW_SIDECAR_E2E_PATH}" || die "cd ${GOPATH}/src/${CSI_PROW_SIDECAR_E2E_PATH} failed"
1154+
;;
1155+
vgs)
1156+
# VGS tests are in in-tree/core tests; do NOT pass -storage.testdriver
1157+
ginkgo_target="${CSI_PROW_WORK}/e2e.test"
1158+
cd "${e2e_src_dir}" || die "cd ${e2e_src_dir} failed"
1159+
;;
1160+
*)
1161+
# Default: CSI external driver tests
1162+
ginkgo_target="${CSI_PROW_WORK}/e2e.test"
1163+
extra_args="-storage.testdriver=${CSI_PROW_WORK}/test-driver.yaml"
1164+
cd "${e2e_src_dir}" || die "cd ${e2e_src_dir} failed"
1165+
;;
1166+
esac
1167+
1168+
[ -n "$extra_args" ] && args+=("$extra_args")
1169+
run_with_loggers env \
1170+
KUBECONFIG="$KUBECONFIG" \
1171+
KUBE_TEST_REPO_LIST="$(if [ -e "${CSI_PROW_WORK}/e2e-repo-list" ]; then echo "${CSI_PROW_WORK}/e2e-repo-list"; fi)" \
1172+
ginkgo --timeout="${CSI_PROW_GINKGO_TIMEOUT}" -v "$@" "$ginkgo_target" -- -report-dir "${ARTIFACTS}" "${args[@]}"
11491173
)
11501174

11511175
# Run csi-sanity against installed CSI driver.
@@ -1444,18 +1468,11 @@ main () {
14441468
ret=1
14451469
fi
14461470

1447-
# Only add feature regex if groupsnapshot is not enabled
1448-
if [ "${CSI_PROW_ENABLE_GROUP_SNAPSHOT}" = "true" ]; then
1449-
combined_focus="${CSI_PROW_E2E_FOCUS}"
1450-
else
1451-
combined_focus="$focus.*($(regex_join "${CSI_PROW_E2E_FOCUS}"))"
1452-
fi
1453-
14541471
# Run tests that are feature tagged, but non-alpha
14551472
# Ignore: Double quote to prevent globbing and word splitting.
14561473
# shellcheck disable=SC2086
14571474
if ! run_e2e parallel-features ${CSI_PROW_GINKGO_PARALLEL} \
1458-
-focus="$combined_focus" \
1475+
-focus="$focus.*($(regex_join "${CSI_PROW_E2E_FOCUS}"))" \
14591476
-skip="$(regex_join "${CSI_PROW_E2E_SERIAL}")"; then
14601477
warn "E2E parallel features failed"
14611478
ret=1
@@ -1479,6 +1496,18 @@ main () {
14791496
ret=1
14801497
fi
14811498
fi
1499+
1500+
# Run VGS in-tree tests only if enabled
1501+
if [ "${CSI_PROW_ENABLE_GROUP_SNAPSHOT}" = "true" ]; then
1502+
vgs_focus="\[Feature:volumegroupsnapshot\]"
1503+
if ! run_e2e vgs \
1504+
-focus="${vgs_focus}" \
1505+
-skip="$(regex_join "${CSI_PROW_E2E_SERIAL}" "${CSI_PROW_E2E_SKIP}")"; then
1506+
warn "E2E VGS tests failed"
1507+
ret=1
1508+
fi
1509+
fi
1510+
14821511
fi
14831512
delete_cluster_inside_prow_job non-alpha
14841513
fi

0 commit comments

Comments
 (0)