Skip to content

Commit 009747b

Browse files
authored
Merge pull request #2125 from murgatroid99/grpc-js-xds_k8s_interop
grpc-js-xds: Add support for k8s interop test framework
2 parents 0679e3e + e61c8f9 commit 009747b

File tree

3 files changed

+231
-0
lines changed

3 files changed

+231
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright 2022 gRPC authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Dockerfile for building the xDS interop client. To build the image, run the
16+
# following command from grpc-node directory:
17+
# docker build -t <TAG> -f packages/grpc-js-xds/interop/Dockerfile .
18+
19+
FROM node:16-alpine as build
20+
21+
# Make a grpc-node directory and copy the repo into it.
22+
WORKDIR /node/src/grpc-node
23+
COPY . .
24+
25+
WORKDIR /node/src/grpc-node/packages/grpc-js
26+
RUN npm install
27+
WORKDIR /node/src/grpc-node/packages/grpc-js-xds
28+
RUN npm install
29+
30+
FROM node:16-alpine
31+
WORKDIR /node/src/grpc-node
32+
COPY --from=build /node/src/grpc-node/packages/grpc-js ./packages/grpc-js/
33+
COPY --from=build /node/src/grpc-node/packages/grpc-js-xds ./packages/grpc-js-xds/
34+
35+
ENTRYPOINT [ "node", "/node/src/grpc-node/packages/grpc-js-xds/build/interop/xds-interop-client" ]
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2022 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-node"
20+
readonly TEST_DRIVER_INSTALL_SCRIPT_URL="https://raw.githubusercontent.com/${TEST_DRIVER_REPO_OWNER:-grpc}/grpc/${TEST_DRIVER_BRANCH:-master}/tools/internal_ci/linux/grpc_xds_k8s_install_test_driver.sh"
21+
## xDS test client Docker images
22+
readonly SERVER_IMAGE_NAME="gcr.io/grpc-testing/xds-interop/java-server:v1.46.x"
23+
readonly CLIENT_IMAGE_NAME="gcr.io/grpc-testing/xds-interop/node-client"
24+
readonly FORCE_IMAGE_BUILD="${FORCE_IMAGE_BUILD:-0}"
25+
readonly BUILD_APP_PATH="packages/grpc-js-xds/interop/Dockerfile"
26+
readonly LANGUAGE_NAME="Node"
27+
28+
#######################################
29+
# Builds test app Docker images and pushes them to GCR
30+
# Globals:
31+
# BUILD_APP_PATH
32+
# CLIENT_IMAGE_NAME: Test client Docker image name
33+
# GIT_COMMIT: SHA-1 of git commit being built
34+
# Arguments:
35+
# None
36+
# Outputs:
37+
# Writes the output of `gcloud builds submit` to stdout, stderr
38+
#######################################
39+
build_test_app_docker_images() {
40+
echo "Building ${LANGUAGE_NAME} xDS interop test app Docker images"
41+
42+
pushd "${SRC_DIR}"
43+
docker build \
44+
-f "${BUILD_APP_PATH}" \
45+
-t "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" \
46+
.
47+
48+
popd
49+
50+
gcloud -q auth configure-docker
51+
52+
docker push "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}"
53+
}
54+
55+
#######################################
56+
# Builds test app and its docker images unless they already exist
57+
# Globals:
58+
# CLIENT_IMAGE_NAME: Test client Docker image name
59+
# GIT_COMMIT: SHA-1 of git commit being built
60+
# FORCE_IMAGE_BUILD
61+
# Arguments:
62+
# None
63+
# Outputs:
64+
# Writes the output to stdout, stderr
65+
#######################################
66+
build_docker_images_if_needed() {
67+
# Check if images already exist
68+
client_tags="$(gcloud_gcr_list_image_tags "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}")"
69+
printf "Client image: %s:%s\n" "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}"
70+
echo "${client_tags:-Client image not found}"
71+
72+
# Build if any of the images are missing, or FORCE_IMAGE_BUILD=1
73+
if [[ "${FORCE_IMAGE_BUILD}" == "1" || -z "${client_tags}" ]]; then
74+
build_test_app_docker_images
75+
else
76+
echo "Skipping ${LANGUAGE_NAME} test app build"
77+
fi
78+
}
79+
80+
#######################################
81+
# Executes the test case
82+
# Globals:
83+
# TEST_DRIVER_FLAGFILE: Relative path to test driver flagfile
84+
# KUBE_CONTEXT: The name of kubectl context with GKE cluster access
85+
# SECONDARY_KUBE_CONTEXT: The name of kubectl context with secondary GKE cluster access, if any
86+
# TEST_XML_OUTPUT_DIR: Output directory for the test xUnit XML report
87+
# CLIENT_IMAGE_NAME: Test client Docker image name
88+
# GIT_COMMIT: SHA-1 of git commit being built
89+
# Arguments:
90+
# Test case name
91+
# Outputs:
92+
# Writes the output of test execution to stdout, stderr
93+
# Test xUnit report to ${TEST_XML_OUTPUT_DIR}/${test_name}/sponge_log.xml
94+
#######################################
95+
run_test() {
96+
# Test driver usage:
97+
# https://github.com/grpc/grpc/tree/master/tools/run_tests/xds_k8s_test_driver#basic-usage
98+
local test_name="${1:?Usage: run_test test_name}"
99+
# testing_version is used by the framework to determine the supported PSM
100+
# features. It's captured from Kokoro job name of the Node repo, which takes
101+
# the form:
102+
# grpc/node/<branch name>/<job name>
103+
python3 -m "tests.${test_name}" \
104+
--flagfile="${TEST_DRIVER_FLAGFILE}" \
105+
--kube_context="${KUBE_CONTEXT}" \
106+
--secondary_kube_context="${SECONDARY_KUBE_CONTEXT}" \
107+
--client_image="${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" \
108+
--server_image="${SERVER_IMAGE_NAME}" \
109+
--testing_version=$(echo "$KOKORO_JOB_NAME" | sed -E 's|^grpc/node/([^/]+)/.*|\1|') \
110+
--xml_output_file="${TEST_XML_OUTPUT_DIR}/${test_name}/sponge_log.xml"
111+
}
112+
113+
#######################################
114+
# Main function: provision software necessary to execute tests, and run them
115+
# Globals:
116+
# KOKORO_ARTIFACTS_DIR
117+
# GITHUB_REPOSITORY_NAME
118+
# SRC_DIR: Populated with absolute path to the source repo
119+
# TEST_DRIVER_REPO_DIR: Populated with the path to the repo containing
120+
# the test driver
121+
# TEST_DRIVER_FULL_DIR: Populated with the path to the test driver source code
122+
# TEST_DRIVER_FLAGFILE: Populated with relative path to test driver flagfile
123+
# TEST_XML_OUTPUT_DIR: Populated with the path to test xUnit XML report
124+
# GIT_ORIGIN_URL: Populated with the origin URL of git repo used for the build
125+
# GIT_COMMIT: Populated with the SHA-1 of git commit being built
126+
# GIT_COMMIT_SHORT: Populated with the short SHA-1 of git commit being built
127+
# KUBE_CONTEXT: Populated with name of kubectl context with GKE cluster access
128+
# SECONDARY_KUBE_CONTEXT: Populated with name of kubectl context with secondary GKE cluster access, if any
129+
# Arguments:
130+
# None
131+
# Outputs:
132+
# Writes the output of test execution to stdout, stderr
133+
#######################################
134+
main() {
135+
local script_dir
136+
script_dir="$(dirname "$0")"
137+
138+
cd "${script_dir}"
139+
140+
git submodule update --init --recursive
141+
142+
# Source the test driver from the master branch.
143+
echo "Sourcing test driver install script from: ${TEST_DRIVER_INSTALL_SCRIPT_URL}"
144+
source /dev/stdin <<< "$(curl -s "${TEST_DRIVER_INSTALL_SCRIPT_URL}")"
145+
146+
activate_gke_cluster GKE_CLUSTER_PSM_LB
147+
activate_secondary_gke_cluster GKE_CLUSTER_PSM_LB
148+
149+
set -x
150+
if [[ -n "${KOKORO_ARTIFACTS_DIR}" ]]; then
151+
kokoro_setup_test_driver "${GITHUB_REPOSITORY_NAME}"
152+
else
153+
local_setup_test_driver "${script_dir}"
154+
fi
155+
build_docker_images_if_needed
156+
157+
# Run tests
158+
cd "${TEST_DRIVER_FULL_DIR}"
159+
local failed_tests=0
160+
test_suites=("baseline_test" "api_listener_test" "change_backend_service_test" "failover_test" "remove_neg_test" "round_robin_test")
161+
for test in "${test_suites[@]}"; do
162+
run_test $test || (( failed_tests++ ))
163+
done
164+
echo "Failed test suites: ${failed_tests}"
165+
if (( failed_tests > 0 )); then
166+
exit 1
167+
fi
168+
}
169+
170+
main "$@"

test/kokoro/xds_k8s_lb.cfg

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2022 gRPC authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Config file for Kokoro (in protobuf text format)
16+
17+
# Location of the continuous shell script in repository.
18+
build_file: "grpc-node/packages/grpc-js-xds/scripts/xds_k8s_lb.sh"
19+
timeout_mins: 180
20+
action {
21+
define_artifacts {
22+
regex: "artifacts/**/*sponge_log.xml"
23+
regex: "artifacts/**/*sponge_log.log"
24+
strip_prefix: "artifacts"
25+
}
26+
}

0 commit comments

Comments
 (0)