[PSM Interop] Allow `dev` TESTING_VERSION that doesn't override images (#33062)

Resolve `TESTING_VERSION` to `dev-VERSION` when the job is initiated by
a user, and not the CI. Override this behavior with setting
`FORCE_TESTING_VERSION`.

This solves the problem with the manual job runs executed against a WIP
branch (f.e. a PR) overriding the tag of the CI-built image we use for
daily testing.

The `dev` and `dev-VERSION` "magic" values supported by the
`--testing_version` flag:

- `dev` and `dev-master` and treated as `master`: all
`config.version_gte` checks resolve to `True`.
- `dev-VERSION` is treated as `VERSION`: `dev-v1.55.x` is treated as
simply `v1.55.x`. We do this so that when manually running jobs for old
branches the feature skip check still works, and unsupported tests are
skipped.

This changes will take care of all langs/branches, no backports needed.

ref b/256845629
pull/33072/head
Sergii Tkachenko 2 years ago committed by GitHub
parent 0ed3bb7955
commit c182e6b252
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 57
      tools/internal_ci/linux/grpc_xds_k8s_install_test_driver.sh
  2. 33
      tools/run_tests/xds_k8s_test_driver/framework/helpers/skips.py
  3. 2
      tools/run_tests/xds_k8s_test_driver/framework/xds_flags.py

@ -23,6 +23,7 @@ readonly TEST_DRIVER_REPO_URL="https://github.com/${TEST_DRIVER_REPO_OWNER:-grpc
readonly TEST_DRIVER_BRANCH="${TEST_DRIVER_BRANCH:-master}"
readonly TEST_DRIVER_PATH="tools/run_tests/xds_k8s_test_driver"
readonly TEST_DRIVER_PROTOS_PATH="src/proto/grpc/testing"
readonly FORCE_TESTING_VERSION="${FORCE_TESTING_VERSION:-}"
# GKE cluster identifiers.
readonly GKE_CLUSTER_PSM_LB="psm-lb"
@ -372,6 +373,46 @@ kokoro_setup_python_virtual_environment() {
python3 -m pip --version
}
#######################################
# Determines the version branch under test from Kokoro environment.
# Globals:
# KOKORO_JOB_NAME
# KOKORO_BUILD_INITIATOR
# FORCE_TESTING_VERSION: Forces the testing version to be something else.
# TESTING_VERSION: Populated with the version branch under test,
# f.e. master, dev, v1.42.x.
# Outputs:
# Sets TESTING_VERSION global variable.
#######################################
kokoro_get_testing_version() {
# All grpc kokoro jobs names structured to have the version identifier in the third position:
# - grpc/core/master/linux/...
# - grpc/core/v1.42.x/branch/linux/...
# - grpc/java/v1.47.x/branch/...
# - grpc/go/v1.47.x/branch/...
# - grpc/node/v1.6.x/...
local version_from_job_name
version_from_job_name=$(echo "${KOKORO_JOB_NAME}" | cut -d '/' -f3)
if [[ -n "${FORCE_TESTING_VERSION}" ]]; then
# Allows to override the testing version, and force tagging the built
# images, if necessary.
readonly TESTING_VERSION="${FORCE_TESTING_VERSION}"
elif [[ "${KOKORO_BUILD_INITIATOR:-anonymous}" != "kokoro" ]]; then
# If not initiated by Kokoro, it's a dev branch.
# This allows to know later down the line that the built image doesn't need
# to be tagged, and avoid overriding an actual versioned image used in tests
# (e.g. v1.42.x, master) with a dev build.
if [[ -n "${version_from_job_name}" ]]; then
readonly TESTING_VERSION="dev-${version_from_job_name}"
else
readonly TESTING_VERSION="dev"
fi
else
readonly TESTING_VERSION="${version_from_job_name}"
fi
}
#######################################
# Installs and configures the test driver on Kokoro VM.
# Globals:
@ -400,13 +441,8 @@ kokoro_setup_test_driver() {
# Capture Kokoro VM version info in the log.
kokoro_print_version
# All grpc kokoro jobs names structured to have the version identifier in the third position:
# - grpc/core/master/linux/...
# - grpc/core/v1.42.x/branch/linux/...
# - grpc/java/v1.47.x/branch/...
# - grpc/go/v1.47.x/branch/...
# - grpc/node/v1.6.x/...
readonly TESTING_VERSION=$(echo "${KOKORO_JOB_NAME}" | cut -d '/' -f3)
# Get testing version from the job name.
kokoro_get_testing_version
# Kokoro clones repo to ${KOKORO_ARTIFACTS_DIR}/github/${GITHUB_REPOSITORY}
local github_root="${KOKORO_ARTIFACTS_DIR}/github"
@ -456,6 +492,13 @@ local_setup_test_driver() {
readonly KUBE_CONTEXT="${KUBE_CONTEXT:-$(kubectl config current-context)}"
readonly SECONDARY_KUBE_CONTEXT="${SECONDARY_KUBE_CONTEXT}"
# Never override docker image for local runs, unless explicitly forced.
if [[ -n "${FORCE_TESTING_VERSION}" ]]; then
readonly TESTING_VERSION="${FORCE_TESTING_VERSION}"
else
readonly TESTING_VERSION="dev"
fi
local test_driver_repo_dir
test_driver_repo_dir="${TEST_DRIVER_REPO_DIR:-$(mktemp -d)/${TEST_DRIVER_REPO_NAME}}"
test_driver_install "${test_driver_repo_dir}"

@ -57,16 +57,24 @@ class TestConfig:
version: Optional[str]
def version_gte(self, another: str) -> bool:
"""Returns a bool for whether the version is >= another one.
"""Returns a bool for whether this VERSION is >= then ANOTHER version.
A version is greater than or equal to another version means its version
number is greater than or equal to another version's number. Version
"master" is always considered latest.
E.g., master >= v1.41.x >= v1.40.x >= v1.9.x.
Special cases:
Unspecified version is treated as 'master', but isn't explicitly set.
1) Versions "master" or "dev" are always greater than ANOTHER:
- master > v1.999.x > v1.55.x
- dev > v1.999.x > v1.55.x
- dev == master
2) Versions "dev-VERSION" behave the same as the VERSION:
- dev-master > v1.999.x > v1.55.x
- dev-master == dev == master
- v1.55.x > dev-v1.54.x > v1.53.x
- dev-v1.54.x == v1.54.x
3) Unspecified version (self.version is None) is treated as "master".
"""
if self.version == 'master' or self.version is None:
if self.version in ('master', 'dev', 'dev-master', None):
return True
if another == 'master':
return False
@ -77,10 +85,13 @@ class TestConfig:
f"server_lang='{self.server_lang}', version={self.version!r})")
@staticmethod
def _parse_version(s: str) -> pkg_version.Version:
if s.endswith(".x"):
s = s[:-2]
return pkg_version.Version(s)
def _parse_version(version: str) -> pkg_version.Version:
if version.startswith('dev-'):
# Treat "dev-VERSION" as "VERSION".
version = version[4:]
if version.endswith('.x'):
version = version[:-2]
return pkg_version.Version(version)
def _get_lang(image_name: str) -> Lang:

@ -120,7 +120,7 @@ CLIENT_PORT = flags.DEFINE_integer(
TESTING_VERSION = flags.DEFINE_string(
"testing_version",
default=None,
help="The testing gRPC version branch name. Like master, v1.41.x, v1.37.x")
help="The testing gRPC version branch name. Like master, dev, v1.55.x")
FORCE_CLEANUP = flags.DEFINE_bool(
"force_cleanup",

Loading…
Cancel
Save