Skip to content

Commit 2cbdfd0

Browse files
authored
Shared kokoro lib: address feedback (#79)
Improves the transparency into the build scripts. 1. Reduces the number of the environment variables required to be set in per-lang buildscripts 2. Deprecate `kokoro_setup_test_driver` in favor of `psm::setup::kokoro`, more consistent with the local setup 3. Instead of implicitly sourcing `psm-interop-build-${GRPC_LANGUAGE}.sh`, have the per-lang buildscripts define `psm::lang::build_docker_images`
1 parent a7ae649 commit 2cbdfd0

File tree

1 file changed

+70
-22
lines changed

1 file changed

+70
-22
lines changed

.kokoro/psm_interop_kokoro_lib.sh

Lines changed: 70 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -250,27 +250,21 @@ psm::csm::run_test() {
250250
# Provisions necessary software, configures the test driver, and executes the test suite.
251251
#
252252
# Globals:
253-
# KOKORO_ARTIFACTS_DIR
254-
# GITHUB_REPOSITORY_NAME
255-
# GRPC_LANGUAGE
256-
# SRC_DIR: Populated with absolute path to the source repo
257-
# TEST_DRIVER_REPO_DIR: Populated with the path to the repo containing
258-
# the test driver
259-
# TEST_DRIVER_FULL_DIR: Populated with the path to the test driver source code
260-
# TEST_DRIVER_FLAGFILE: Populated with relative path to test driver flagfile
261-
# TEST_XML_OUTPUT_DIR: Populated with the path to test xUnit XML report
262-
# GIT_ORIGIN_URL: Populated with the origin URL of git repo used for the build
263-
# GIT_COMMIT: Populated with the SHA-1 of git commit being built
264-
# GIT_COMMIT_SHORT: Populated with the short SHA-1 of git commit being built
265-
# KUBE_CONTEXT: Populated with name of kubectl context with GKE cluster access
253+
# GRPC_LANGUAGE: The name of gRPC languages under test
254+
# BUILD_SCRIPT_DIR: Absolute path to the directory with lang-specific buildscript
255+
# in the source repo.
266256
# Arguments:
267-
# Test suite name, one of (lb, security, url_map)
257+
# Test suite name, one of (lb, security, url_map, csm)
268258
# Outputs:
269259
# Writes the output of test execution to stdout, stderr
270260
#######################################
271261
psm::run() {
272262
local test_suite="${1:?${FUNCNAME[0]} missing the test suite argument}"
273263
psm::tools::log "Starting PSM Interop tests: ${test_suite}"
264+
if [[ $(type -t psm::lang::build_docker_images) != function ]]; then
265+
psm::tools::log "Method psm::lang::build_docker_images must be defined by the buildscript."
266+
exit 1
267+
fi
274268

275269
psm::setup::docker_image_names "${GRPC_LANGUAGE}" "${test_suite}"
276270

@@ -467,20 +461,69 @@ psm::setup::docker_image_names() {
467461
}
468462

469463
psm::setup::test_driver() {
470-
local build_docker_script="${BUILD_SCRIPT_DIR}/psm-interop-build-${GRPC_LANGUAGE}.sh"
471-
psm::tools::log "Looking for docker image build script ${build_docker_script}"
472-
if [[ -f "${build_docker_script}" ]]; then
473-
psm::tools::log "Sourcing docker image build script: ${build_docker_script}"
474-
source "${build_docker_script}"
475-
fi
476-
477464
if [[ -n "${KOKORO_ARTIFACTS_DIR}" ]]; then
478-
kokoro_setup_test_driver "${GITHUB_REPOSITORY_NAME}"
465+
psm::setup::kokoro "${BUILD_SCRIPT_DIR}"
479466
else
480467
local_setup_test_driver "${BUILD_SCRIPT_DIR}"
481468
fi
482469
}
483470

471+
#######################################
472+
# Installs and configures the test driver for testing build script locally.
473+
# Globals:
474+
# TEST_DRIVER_REPO_NAME The repository name of the test driver directory
475+
# TEST_DRIVER_REPO_DIR: The path to the test driver directory (optional)
476+
# SRC_DIR: Populated with absolute path to the source repo
477+
# KUBE_CONTEXT: Populated with name of kubectl context with GKE cluster access
478+
# SECONDARY_KUBE_CONTEXT: Populated with name of kubectl context with secondary GKE cluster
479+
# access, if any
480+
# TEST_DRIVER_FLAGFILE: Populated with relative path to test driver flagfile
481+
# TEST_XML_OUTPUT_DIR: Populated with the path to test xUnit XML report
482+
# GIT_ORIGIN_URL: Populated with the origin URL of git repo used for the build
483+
# GIT_COMMIT: Populated with the SHA-1 of git commit being built
484+
# GIT_COMMIT_SHORT: Populated with the short SHA-1 of git commit being built
485+
# Arguments:
486+
# Absolute path to the directory with lang-specific buildscript, must be in the source repo.
487+
# Outputs:
488+
# Writes the output to stdout, stderr, files
489+
#######################################
490+
psm::setup::kokoro() {
491+
local script_dir="${1:?${FUNCNAME[0]} missing the build script dir argument}"
492+
493+
psm::tools::log "Starting Kokoro provisioning"
494+
# Capture Kokoro VM version info in the log.
495+
kokoro_print_version
496+
# Get testing version from the job name.
497+
kokoro_get_testing_version
498+
499+
# Absolute path to the root of the source git repo.
500+
readonly SRC_DIR="$(git -C "${script_dir}" rev-parse --show-toplevel)"
501+
502+
# Test artifacts dir: xml reports, logs, etc.
503+
local artifacts_dir="${KOKORO_ARTIFACTS_DIR}/artifacts"
504+
# Folders after $artifacts_dir reported as target name
505+
readonly TEST_XML_OUTPUT_DIR="${artifacts_dir}/${KOKORO_JOB_NAME}"
506+
readonly BUILD_LOGS_ROOT="${TEST_XML_OUTPUT_DIR}"
507+
508+
mkdir -p "${artifacts_dir}" "${TEST_XML_OUTPUT_DIR}" "${BUILD_LOGS_ROOT}"
509+
parse_src_repo_git_info SRC_DIR
510+
kokoro_write_sponge_properties
511+
512+
psm::tools::log "Installing packages with apt, see install-apt.log"
513+
kokoro_install_dependencies &> "${BUILD_LOGS_ROOT}/install-apt.log"
514+
515+
# Get kubectl cluster credentials.
516+
psm::tools::log "Fetching GKE cluster credentials"
517+
gcloud_get_cluster_credentials
518+
519+
# Install the driver.
520+
local test_driver_repo_dir
521+
test_driver_repo_dir="${TEST_DRIVER_REPO_DIR:-$(mktemp -d)/${TEST_DRIVER_REPO_NAME}}"
522+
test_driver_install "${test_driver_repo_dir}"
523+
# shellcheck disable=SC2034 # Used in the main script
524+
readonly TEST_DRIVER_FLAGFILE="config/grpc-testing.cfg"
525+
}
526+
484527
# --- Common test build logic -----------
485528

486529
#######################################
@@ -514,6 +557,7 @@ psm::build::docker_images_if_needed() {
514557
{
515558
psm::tools::log "Building xDS interop test app Docker images"
516559
gcloud -q auth configure-docker "${DOCKER_REGISTRY}"
560+
# This method must be defined in the language-specific buildscript.
517561
psm::lang::build_docker_images
518562
psm::tools::log "Finished xDS interop test app Docker images"
519563
} | tee -a "${BUILD_LOGS_ROOT}/build-docker.log"
@@ -1015,6 +1059,9 @@ kokoro_get_testing_version() {
10151059

10161060
#######################################
10171061
# Installs and configures the test driver on Kokoro VM.
1062+
#
1063+
# Deprecated. Use psm::setup::kokoro
1064+
#
10181065
# Globals:
10191066
# KOKORO_ARTIFACTS_DIR
10201067
# KOKORO_JOB_NAME
@@ -1037,6 +1084,7 @@ kokoro_get_testing_version() {
10371084
# Writes the output to stdout, stderr, files
10381085
#######################################
10391086
kokoro_setup_test_driver() {
1087+
# TODO(sergiitk): Remove after per-lang buildscripts are backported.
10401088
# Unset noisy verbose mode often set in the parent scripts.
10411089
set +x
10421090

0 commit comments

Comments
 (0)