Skip to content

Commit

Permalink
Extend catalog test script to run test for different platforms
Browse files Browse the repository at this point in the history
PLATFORM env variable is introduced. This variable allows to run
tests for specific platform (for insance, "linux/s390x" or "linux/ppc64le").
If the environment variable is specified
- some tests are updated with different image values/other parameter
values, required for specific platform, using yq tool.
Custom values should be specified in the env file, separate for each
platform. In the current code env file for linux/s390x is proposed.

- only tasks, which have mention about corresponding platform support
in the annotation, will be tested.
If PLATFORM env variale is no specified, the behaviour of test scripts
will be similar to the one before the PR.

Signed-off-by: Yulia Gaponenko <yulia.gaponenko1@de.ibm.com>
  • Loading branch information
barthy1 committed Oct 14, 2021
1 parent a6e8e8f commit d3fb363
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
34 changes: 32 additions & 2 deletions test/e2e-common.sh
Expand Up @@ -33,6 +33,29 @@ if [ "${BASH_VERSINFO:-0}" -lt 4 ];then
exit 1
fi

# Default registry image value to use in this script
REGISTRY_IMAGE="registry"
if [[ -n ${PLATFORM} ]] && [[ -f "$(dirname $0)/$(echo ${PLATFORM}| tr / -).envs" ]]; then
# Load env variables specific to platform. File name should follow the pattern "os-arch.envs", for instance "linux-amd64.envs"
set -o allexport
source $(dirname $0)/$(echo ${PLATFORM}| tr / -).envs
set +o allexport
# Install yq
echo "Getting yq"
wget https://github.com/mikefarah/yq/releases/download/v4.11.2/yq_linux_amd64
chmod +x yq_linux_amd64
mv yq_linux_amd64 /bin/yq
# Add MAVEN_IMAGE parameter to the appropriate maven tests
echo "Add extra MAVEN_IMAGE parameter"
find task/*maven*/*/tests/run.yaml | xargs -I{} yq eval '(..|select(.kind?=="Pipeline")|select(.metadata.name?=="jib-maven-test-pipeline"|"maven-test-pipeline")|.spec.tasks[1].params) |= . +{"name": "MAVEN_IMAGE","value": env(MAVEN_IMAGE)}' -i {}
# Replace registry image to platform specific
echo "Change registry image value"
find task -name *registry*.yaml | xargs -I{} yq eval '(..|select(.kind?=="Deployment")|select(.metadata.name?=="registry")|.spec.template.spec.containers[0].image)|= env(REGISTRY_IMAGE)' -i {}
# change GOARCH parameter value to the platform specific one for golang-* tasks
echo "Change GOARCH parameter value"
find task/golang*/*/tests/run.yaml | xargs -I{} yq eval '(..|select(.kind?=="Pipeline")|.spec.tasks[1].params) |= . +{"name": "GOARCH","value": env(GOARCH)}' -i {}
fi

## Commands

function require_command() {
Expand Down Expand Up @@ -86,7 +109,7 @@ print(yaml.dump(data, default_flow_style=False))
# Add an internal registry as sidecar to a task so we can upload it directly
# from our tests withouth having to go to an external registry.
function add_sidecar_registry() {
add_sidecars ${1} '{"image":"registry", "name": "registry"}'
add_sidecars ${1} "{'image':${REGISTRY_IMAGE}, 'name': 'registry'}"
}

# Run a secure registry as a sidecar to allow the tasks to push to this registry using the certs.
Expand Down Expand Up @@ -166,6 +189,10 @@ function test_yaml_can_install() {
for ignore in ${TEST_YAML_IGNORES};do
[[ ${ignore} == "${testname}" ]] && skipit=True
done

# In case if PLATFORM env variable is specified, do the tests only for matching tasks
[[ -n ${PLATFORM} ]] && [[ $(grep "tekton.dev/platforms" ${runtest}) != *"${PLATFORM}"* ]] && skipit=True

[[ -n ${skipit} ]] && break
echo "Checking ${testname}"
${KUBECTL_CMD} -n ${ns} apply -f <(sed "s/namespace:.*/namespace: task-ns/" "${runtest}")
Expand Down Expand Up @@ -224,7 +251,10 @@ function test_task_creation() {

cat ${taskdir}/*.yaml | grep 'tekton.dev/deprecated: \"true\"' && skipit=True

[[ -n ${skipit} ]] && continue
# In case if PLATFORM env variable is specified, do the tests only for matching tasks
[[ -n ${PLATFORM} ]] && [[ $(grep "tekton.dev/platforms" ${taskdir}/*.yaml) != *"${PLATFORM}"* ]] && skipit=True

[[ -n ${skipit} ]] && continue

# In case of rerun it's fine to ignore this error
${KUBECTL_CMD} create namespace ${tns} >/dev/null 2>/dev/null || :
Expand Down
4 changes: 4 additions & 0 deletions test/linux-s390x.envs
@@ -0,0 +1,4 @@
REGISTRY_IMAGE=ibmcom/registry:2.6.2.5
MAVEN_IMAGE=maven:3.6.3-adoptopenjdk-11
GOARCH=s390x
TEST_TASKRUN_IGNORES="helm-upgrade-from-repo helm-upgrade-from-source golang-test kaniko"

0 comments on commit d3fb363

Please sign in to comment.