Skip to content

Commit 00edd8c

Browse files
authored
Add xDS k8s url-map test Kokoro job (#4614)
1 parent 1ddab33 commit 00edd8c

File tree

3 files changed

+148
-1
lines changed

3 files changed

+148
-1
lines changed

test/kokoro/xds_k8s.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ run_test() {
129129
main() {
130130
local script_dir
131131
script_dir="$(dirname "$0")"
132-
# shellcheck source=tools/internal_ci/linux/grpc_xds_k8s_install_test_driver.sh
132+
# shellcheck source=test/kokoro/xds_k8s_install_test_driver.sh
133133
source "${script_dir}/xds_k8s_install_test_driver.sh"
134134
set -x
135135
if [[ -n "${KOKORO_ARTIFACTS_DIR}" ]]; then

test/kokoro/xds_url_map.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Config file for internal CI
2+
3+
# Location of the continuous shell script in repository.
4+
build_file: "grpc-go/test/kokoro/xds_url_map.sh"
5+
timeout_mins: 60
6+
7+
action {
8+
define_artifacts {
9+
regex: "artifacts/**/*sponge_log.xml"
10+
regex: "artifacts/**/*sponge_log.log"
11+
strip_prefix: "artifacts"
12+
}
13+
}

test/kokoro/xds_url_map.sh

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2021 gRPC authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -eo pipefail
17+
18+
# Constants
19+
readonly GITHUB_REPOSITORY_NAME="grpc-go"
20+
# GKE Cluster
21+
readonly GKE_CLUSTER_NAME="interop-test-psm-sec-v2-us-central1-a"
22+
readonly GKE_CLUSTER_ZONE="us-central1-a"
23+
## xDS test client Docker images
24+
readonly CLIENT_IMAGE_NAME="gcr.io/grpc-testing/xds-interop/go-client"
25+
readonly FORCE_IMAGE_BUILD="${FORCE_IMAGE_BUILD:-0}"
26+
27+
#######################################
28+
# Builds test app Docker images and pushes them to GCR
29+
# Globals:
30+
# CLIENT_IMAGE_NAME: Test client Docker image name
31+
# GIT_COMMIT: SHA-1 of git commit being built
32+
# Arguments:
33+
# None
34+
# Outputs:
35+
# Writes the output of `gcloud builds submit` to stdout, stderr
36+
#######################################
37+
build_test_app_docker_images() {
38+
echo "Building Go xDS interop test app Docker images"
39+
docker build -f "${SRC_DIR}/interop/xds/client/Dockerfile" -t "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" "${SRC_DIR}"
40+
gcloud -q auth configure-docker
41+
docker push "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}"
42+
}
43+
44+
#######################################
45+
# Builds test app and its docker images unless they already exist
46+
# Globals:
47+
# CLIENT_IMAGE_NAME: Test client Docker image name
48+
# GIT_COMMIT: SHA-1 of git commit being built
49+
# FORCE_IMAGE_BUILD
50+
# Arguments:
51+
# None
52+
# Outputs:
53+
# Writes the output to stdout, stderr
54+
#######################################
55+
build_docker_images_if_needed() {
56+
# Check if images already exist
57+
client_tags="$(gcloud_gcr_list_image_tags "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}")"
58+
printf "Client image: %s:%s\n" "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}"
59+
echo "${client_tags:-Client image not found}"
60+
61+
# Build if any of the images are missing, or FORCE_IMAGE_BUILD=1
62+
if [[ "${FORCE_IMAGE_BUILD}" == "1" || -z "${client_tags}" ]]; then
63+
build_test_app_docker_images
64+
else
65+
echo "Skipping Go test app build"
66+
fi
67+
}
68+
69+
#######################################
70+
# Executes the test case
71+
# Globals:
72+
# TEST_DRIVER_FLAGFILE: Relative path to test driver flagfile
73+
# KUBE_CONTEXT: The name of kubectl context with GKE cluster access
74+
# TEST_XML_OUTPUT_DIR: Output directory for the test xUnit XML report
75+
# CLIENT_IMAGE_NAME: Test client Docker image name
76+
# GIT_COMMIT: SHA-1 of git commit being built
77+
# Arguments:
78+
# Test case name
79+
# Outputs:
80+
# Writes the output of test execution to stdout, stderr
81+
# Test xUnit report to ${TEST_XML_OUTPUT_DIR}/${test_name}/sponge_log.xml
82+
#######################################
83+
run_test() {
84+
# Test driver usage:
85+
# https://github.com/grpc/grpc/tree/master/tools/run_tests/xds_k8s_test_driver#basic-usage
86+
local test_name="${1:?Usage: run_test test_name}"
87+
set -x
88+
python -m "tests.${test_name}" \
89+
--flagfile="${TEST_DRIVER_FLAGFILE}" \
90+
--kube_context="${KUBE_CONTEXT}" \
91+
--client_image="${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" \
92+
--xml_output_file="${TEST_XML_OUTPUT_DIR}/${test_name}/sponge_log.xml" \
93+
--flagfile="config/url-map.cfg"
94+
set +x
95+
}
96+
97+
#######################################
98+
# Main function: provision software necessary to execute tests, and run them
99+
# Globals:
100+
# KOKORO_ARTIFACTS_DIR
101+
# GITHUB_REPOSITORY_NAME
102+
# SRC_DIR: Populated with absolute path to the source repo
103+
# TEST_DRIVER_REPO_DIR: Populated with the path to the repo containing
104+
# the test driver
105+
# TEST_DRIVER_FULL_DIR: Populated with the path to the test driver source code
106+
# TEST_DRIVER_FLAGFILE: Populated with relative path to test driver flagfile
107+
# TEST_XML_OUTPUT_DIR: Populated with the path to test xUnit XML report
108+
# GIT_ORIGIN_URL: Populated with the origin URL of git repo used for the build
109+
# GIT_COMMIT: Populated with the SHA-1 of git commit being built
110+
# GIT_COMMIT_SHORT: Populated with the short SHA-1 of git commit being built
111+
# KUBE_CONTEXT: Populated with name of kubectl context with GKE cluster access
112+
# Arguments:
113+
# None
114+
# Outputs:
115+
# Writes the output of test execution to stdout, stderr
116+
#######################################
117+
main() {
118+
local script_dir
119+
script_dir="$(dirname "$0")"
120+
# shellcheck source=test/kokoro/xds_k8s_install_test_driver.sh
121+
source "${script_dir}/xds_k8s_install_test_driver.sh"
122+
set -x
123+
if [[ -n "${KOKORO_ARTIFACTS_DIR}" ]]; then
124+
kokoro_setup_test_driver "${GITHUB_REPOSITORY_NAME}"
125+
else
126+
local_setup_test_driver "${script_dir}"
127+
fi
128+
build_docker_images_if_needed
129+
# Run tests
130+
cd "${TEST_DRIVER_FULL_DIR}"
131+
run_test url_map
132+
}
133+
134+
main "$@"

0 commit comments

Comments
 (0)