Merge pull request #425 from phracek/support_github_matrix

Support GitHub matrix
This commit is contained in:
phracek 2021-11-23 13:14:04 +00:00
commit f2fcbea918
11 changed files with 281 additions and 64 deletions

View file

@ -15,7 +15,7 @@ ENV NAME=postgresql \
ARCH=x86_64 \
\
POSTGRESQL_VERSION=12 \
POSTGRESQL_PREV_VERSION=11 \
POSTGRESQL_PREV_VERSION=10 \
HOME=/var/lib/pgsql \
PGUSER=postgres \
APP_DATA=/opt/app-root
@ -47,6 +47,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions
RUN INSTALL_PKGS="rsync tar gettext bind-utils postgresql-server postgresql-contrib nss_wrapper " && \
INSTALL_PKGS+="findutils xz" && \
INSTALL_PKGS+=" pgaudit" && \
dnf -y module enable postgresql:12 && \
dnf -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \
rpm -V $INSTALL_PKGS && \
dnf clean all && \

View file

@ -1,5 +1,27 @@
#!/bin/env python3
# MIT License
#
# Copyright (c) 2018-2019 Red Hat, Inc.
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import sys
import json
import logging

View file

@ -150,6 +150,16 @@ function ct_os_get_build_pod_status() {
| sort -u | awk '{print $2}' | tail -n 1
}
# ct_os_get_buildconfig_pod_name POD_PREFIX
# ----------------------------
# Returns status of the buildconfig pod specified by prefix [pod_prefix].
# Argument: pod_prefix - prefix
function ct_os_get_buildconfig_pod_name() {
local pod_prefix="${1}" ; shift
local query="custom-columns=NAME:.metadata.name"
oc get bc -o "$query" | grep -e "${pod_prefix}" | sort -u | tail -n 1
}
# ct_os_get_pod_name POD_PREFIX
# --------------------
# Returns the full name of pods specified by prefix [pod_prefix].
@ -169,6 +179,22 @@ function ct_os_get_pod_ip() {
oc get pod "$pod_name" --no-headers -o custom-columns=IP:status.podIP
}
# ct_os_get_sti_build_logs
# -----------------
# Return logs from sti_build
# Arguments: pod_name
function ct_os_get_sti_build_logs() {
local pod_prefix="${1}"
pod_name=$(ct_os_get_buildconfig_pod_name "${pod_prefix}")
# Print logs but do not failed. Just for traces
if [ x"${pod_name}" != "x" ]; then
oc logs "bc/$pod_name" || return 0
else
echo "Build config bc/$pod_name does not exist for some reason."
echo "Import probably failed."
fi
}
# ct_os_check_pod_readiness POD_PREFIX STATUS
# --------------------
# Checks whether the pod is ready.
@ -195,7 +221,12 @@ function ct_os_wait_pod_ready() {
echo -n "Waiting for ${pod_prefix} build pod to finish ..."
while ! [ "$(ct_os_get_build_pod_status "${pod_prefix}")" == "Succeeded" ] ; do
echo -n "."
[ "${SECONDS}" -gt "${timeout}0" ] && echo " FAIL" && return 1
if [ "${SECONDS}" -gt "${timeout}0" ]; then
echo " FAIL"
ct_os_print_logs || :
ct_os_get_sti_build_logs "${pod_prefix}" || :
return 1
fi
sleep 3
done
echo " DONE"
@ -204,7 +235,12 @@ function ct_os_wait_pod_ready() {
echo -n "Waiting for ${pod_prefix} pod becoming ready ..."
while ! ct_os_check_pod_readiness "${pod_prefix}" "true" ; do
echo -n "."
[ "${SECONDS}" -gt "${timeout}" ] && echo " FAIL" && return 1
if [ "${SECONDS}" -gt "${timeout}" ]; then
echo " FAIL";
ct_os_print_logs || :
ct_os_get_sti_build_logs "${pod_prefix}" || :
return 1
fi
sleep 3
done
echo " DONE"
@ -223,7 +259,12 @@ function ct_os_wait_rc_ready() {
while ! test "$( (oc get --no-headers statefulsets; oc get --no-headers rc) 2>/dev/null \
| grep "^${pod_prefix}" | awk '$2==$3 {print "ready"}')" == "ready" ; do
echo -n "."
[ "${SECONDS}" -gt "${timeout}" ] && echo " FAIL" && return 1
if [ "${SECONDS}" -gt "${timeout}" ]; then
echo " FAIL";
ct_os_print_logs || :
ct_os_get_sti_build_logs "${pod_prefix}" || :
return 1
fi
sleep 3
done
echo " DONE"
@ -331,7 +372,12 @@ function ct_os_delete_project() {
return
fi
local project_name="${1:-$(oc project -q)}" ; shift || :
oc delete project "${project_name}"
if oc delete project "${project_name}" ; then
echo "Project ${project_name} was deleted properly"
else
echo "Project ${project_name} was not delete properly. But it does not block CI."
fi
}
# ct_delete_all_objects
@ -617,20 +663,21 @@ function ct_os_test_s2i_app_func() {
ct_os_new_project
namespace=${CT_NAMESPACE:-"$(oc project -q)"}
local image_tagged="${image_name_no_namespace%:*}:${VERSION}"
if [ "${CT_EXTERNAL_REGISTRY:-false}" == 'true' ] ; then
ct_os_import_image_ocp4 "${image_name}" "${image_name_no_namespace}"
ct_os_import_image_ocp4 "${image_name}" "${image_tagged}"
else
# Create a specific imagestream tag for the image so that oc cannot use anything else
if [ "${CT_SKIP_UPLOAD_IMAGE:-false}" == 'true' ] ; then
echo "Importing image ${image_name} as ${namespace}/${image_name_no_namespace}"
echo "Importing image ${image_name} as ${namespace}/${image_tagged}"
# Use --reference-policy=local to pull remote image content to the cluster
# Works around the issue of builder pods not having access to registry.redhat.io
oc tag --source=docker "${image_name}" "${namespace}/${image_name_no_namespace}" --insecure=true --reference-policy=local
ct_os_wait_stream_ready "${image_name_no_namespace}" "${namespace}"
oc tag --source=docker "${image_name}" "${namespace}/${image_tagged}" --insecure=true --reference-policy=local
ct_os_wait_stream_ready "${image_tagged}" "${namespace}"
else
echo "Uploading image ${image_name} as ${image_name_no_namespace}"
ct_os_upload_image "${image_name}" "${image_name_no_namespace}"
echo "Uploading image ${image_name} as ${image_tagged}"
ct_os_upload_image "${image_name}" "${image_tagged}"
fi
fi
@ -642,7 +689,7 @@ function ct_os_test_s2i_app_func() {
fi
# shellcheck disable=SC2086
ct_os_deploy_s2i_image "${image_name_no_namespace}" "${app_param}" \
ct_os_deploy_s2i_image "${image_tagged}" "${app_param}" \
--context-dir="${context_dir}" \
--name "${service_name}" \
${oc_args}
@ -793,6 +840,8 @@ function ct_os_test_template_app_func() {
local local_template
local_template=$(ct_obtain_input "${template}" 2>/dev/null || echo "--template=${template}")
echo "Creating a new-app with name ${name_in_template} in namespace ${namespace} with args ${oc_args}."
# shellcheck disable=SC2086
oc new-app "${local_template}" \
--name "${name_in_template}" \
@ -928,7 +977,7 @@ ct_os_test_image_update() {
function ct_os_deploy_cmd_image() {
local image_name=${1}
oc get pod command-app &>/dev/null && echo "command POD already running" && return 0
echo "command POD not running yet, will start one called command-app"
echo "command POD not running yet, will start one called command-app ${image_name}"
oc create -f - <<EOF
apiVersion: v1
kind: Pod
@ -946,6 +995,8 @@ EOF
SECONDS=0
echo -n "Waiting for command POD ."
while [ $SECONDS -lt 180 ] ; do
# Let's show status of all pods. Not only command-container for tracking issues
oc get pods
# shellcheck disable=SC2016
sout="$(ct_os_cmd_image_run 'echo $((11*11))' 2>/dev/null)"
# shellcheck disable=SC2015
@ -992,7 +1043,7 @@ ct_os_test_response_internal() {
local status
local response_code
local response_file
local util_image_name='python:3.6'
local util_image_name='ubi7/ubi'
response_file=$(mktemp /tmp/ct_test_response_XXXXXX)
ct_os_deploy_cmd_image "${util_image_name}"
@ -1231,16 +1282,30 @@ function ct_os_test_image_stream_quickstart() {
local local_template_file
echo "Running image stream test for stream ${image_stream_file} and quickstart template ${template_file}"
echo "Image name is ${IMAGE_NAME}"
# shellcheck disable=SC2119
ct_os_new_project
local_image_stream_file=$(ct_obtain_input "${image_stream_file}")
local_template_file=$(ct_obtain_input "${template_file}")
oc create -f "${local_image_stream_file}"
# ct_os_test_template_app creates a new project, but we already need
# it before for the image stream import, so tell it to skip this time
namespace=${CT_NAMESPACE:-"$(oc project -q)"}
# Add namespace into openshift arguments
if [[ $oc_args != *"NAMESPACE"* ]]; then
oc_args="${oc_args} -p NAMESPACE=${namespace}"
fi
oc create -f "${local_image_stream_file}"
# In case we are testing on OpenShift 4 export variable for mirror image
# which means, that image is going to be mirrored from an internal registry into OpenShift 4
if [ "${CT_EXTERNAL_REGISTRY:-false}" == 'true' ]; then
export CT_TAG_IMAGE=true
fi
# ct_os_test_template_app creates a new project, but we already need
# it before for the image stream import, so tell it to skip this time
CT_SKIP_NEW_PROJECT=true \
ct_os_test_template_app "${image_name}" \
"${local_template_file}" \

View file

@ -27,6 +27,7 @@ EXPECTED_EXIT_CODE=0
function ct_cleanup() {
ct_show_resources
for cid_file in "$CID_FILE_DIR"/* ; do
[ -f "$cid_file" ] || continue
local container
container=$(cat "$cid_file")
@ -83,11 +84,12 @@ function ct_check_envs_set {
if [ -n "${filtered_envs##${env_format//VALUE/$value}}" ]; then
echo " Value $value is missing from variable $var_name"
echo "$filtered_envs"
IFS=$old_IFS
return 1
fi
done
IFS=$old_IFS
done <<< "$(echo "$loop_envs" | grep "$env_filter" | grep -v "^PWD=")"
IFS=$old_IFS
}
# ct_get_cid [name]
@ -341,7 +343,7 @@ function ct_binary_found_from_df() {
# Create Dockerfile that looks for the binary
cat <<EOF >"$tmpdir/Dockerfile"
FROM $IMAGE_NAME
RUN which $binary | grep "$binary_path"
RUN command -v $binary | grep "$binary_path"
EOF
# Build an image, looking for expected path in the output
if ! docker build -f "$tmpdir/Dockerfile" --no-cache "$tmpdir"; then
@ -559,7 +561,7 @@ ct_registry_from_os() {
registry=registry.redhat.io
;;
*)
registry=docker.io
registry=quay.io
;;
esac
echo "$registry"
@ -585,9 +587,9 @@ ct_get_public_image_name() {
elif [ "x$os" == "xrhel8" ]; then
public_image_name=$registry/rhel8/$base_image_name-${version//./}
elif [ "x$os" == "xcentos7" ]; then
public_image_name=$registry/centos/$base_image_name-${version//./}-centos7
public_image_name=$registry/centos7/$base_image_name-${version//./}-centos7
elif [ "x$os" == "xcentos8" ]; then
public_image_name=$registry/centos/$base_image_name-${version//./}-centos8
public_image_name=$registry/centos8/$base_image_name-${version//./}-centos8
fi
echo "$public_image_name"
@ -816,7 +818,7 @@ ct_show_resources()
echo "Memory:"
free -h
echo "Storage:"
df -h
df -h || :
echo "CPU"
lscpu
}
@ -825,7 +827,7 @@ ct_show_resources()
# -----------------------------
# Argument: dockerfile - path to a Dockerfile that will be used for building an image
# (must work with an application directory called 'app-src')
# Argument: app_url - git URI with a testing application
# Argument: app_url - git URI with a testing application, supports "@" to indicate a different branch
# Argument: body_regexp - PCRE regular expression that must match the response body
# Argument: app_dir - name of the application directory that is used in the Dockerfile
# Argument: port - Optional port number (default: 8080)
@ -863,7 +865,17 @@ ct_test_app_dockerfile() {
echo "Using this Dockerfile:"
cat Dockerfile
if ! git clone "${app_url}" "${app_dir}" ; then
# If app_url contains @, the string after @ is considered
# as a name of a branch to clone instead of the main/master branch
IFS='@' read -ra git_url_parts <<< "${app_url}"
if [ -n "${git_url_parts[1]}" ]; then
git_clone_cmd="git clone --branch ${git_url_parts[1]} ${git_url_parts[0]} ${app_dir}"
else
git_clone_cmd="git clone ${app_url} ${app_dir}"
fi
if ! $git_clone_cmd ; then
echo "ERROR: Git repository ${app_url} cannot be cloned into ${app_dir}."
echo "Terminating the Dockerfile build."
return 1

View file

@ -4,7 +4,7 @@ PostgreSQL 12 SQL Database Server container image
This container image includes PostgreSQL 12 SQL database server for OpenShift and general usage.
Users can choose between RHEL, CentOS and Fedora based images.
The RHEL images are available in the [Red Hat Container Catalog](https://access.redhat.com/containers/),
the CentOS images are available on [Docker Hub](https://hub.docker.com/r/centos/),
the CentOS images are available on [Quay.io](https://quay.io/organization/centos7),
and the Fedora images are available in [Fedora Registry](https://registry.fedoraproject.org/).
The resulting image can be run using [podman](https://github.com/containers/libpod).
@ -123,7 +123,7 @@ $ podman run <...> -v /your/data/dir:/var/lib/pgsql/data:Z <...>
Data migration
----------------------
--------------
PostgreSQL container supports migration of data from remote PostgreSQL server.
You can run it like:
@ -173,7 +173,7 @@ clusters is not encrypted by default, it is up to user to configure SSL on
remote cluster or ensure security via different means.
PostgreSQL auto-tuning
--------------------
----------------------
When the PostgreSQL image is run with the `--memory` parameter set and if there
are no values provided for `POSTGRESQL_SHARED_BUFFERS` and

View file

@ -29,11 +29,11 @@ get_image_id ()
image=registry.redhat.io/$ns/postgresql-${version}-rhel7
;;
centos7)
ns=centos
ns=centos7
if test "$version" -eq 92; then
ns=openshift
fi
local image=docker.io/$ns/postgresql-${1//\./}-centos7
local image=quay.io/$ns/postgresql-${1//\./}-centos7
;;
rhel8)
ns=rhel8

View file

@ -118,14 +118,13 @@ function check_postgresql_os_service_connection() {
function test_postgresql_pure_image() {
local image_name=$1
local image_name_no_namespace=${image_name##*/}
local service_name=${image_name_no_namespace}
local service_name="${image_name_no_namespace%%:*}-testing"
ct_os_new_project
ct_os_upload_image "${image_name}"
# Create a specific imagestream tag for the image so that oc cannot use anything else
ct_os_upload_image "${image_name}" "$image_name_no_namespace:testing"
ct_os_upload_image "${image_name}" "$image_name_no_namespace"
ct_os_deploy_pure_image "$image_name_no_namespace:testing" \
ct_os_deploy_pure_image "$image_name_no_namespace" \
--name "${service_name}" \
--env POSTGRESQL_ADMIN_PASSWORD=test
@ -139,7 +138,7 @@ function test_postgresql_template() {
local image_name=$1; shift
local template=$1
local image_name_no_namespace=${image_name##*/}
local service_name=${image_name_no_namespace}
local service_name="${image_name_no_namespace%%:*}-testing"
ct_os_new_project
ct_os_upload_image "${image_name}" "postgresql:$VERSION"
@ -161,8 +160,8 @@ function test_postgresql_template() {
function test_postgresql_update() {
local image_name=$1; shift
local template=$1
local image_name_no_registry=${image_name#*/}
local service_name=${image_name_no_registry#*/}
local image_name_no_registry=${image_name##*/}
local service_name="${image_name_no_registry%%:*}-testing"
local user="testu" pass="testp" db="testdb"
local registry="" old_image="" pod_ip=""
local version released=:
@ -219,8 +218,8 @@ function test_postgresql_update() {
function test_postgresql_replication() {
local image_name=$1
local image_name_no_namespace=${image_name##*/}
local master_service_name=${image_name_no_namespace}-master
local slave_service_name=${image_name_no_namespace}-slave
local master_service_name="${image_name_no_namespace%%:*}-master"
local slave_service_name="${image_name_no_namespace%%:*}-slave"
local istag="postgresql:$VERSION"
local user="testu" pass="testp" db="testdb"
local master_name="" master_ip="" slave_name="" slave_ip=""
@ -289,7 +288,7 @@ function test_postgresql_persistent_redeploy() {
local image_name=$1; shift
local template=$1
local image_name_no_namespace=${image_name##*/}
local service_name=$image_name_no_namespace
local service_name="${image_name_no_namespace%%:*}-testing"
local user="testu" pass="testp" db="testdb"
local registry="" old_image="" pod_ip=""
@ -327,7 +326,7 @@ function test_postgresql_ephemeral_redeploy() {
local image_name=$1; shift
local template=$1
local image_name_no_namespace=${image_name##*/}
local service_name=$image_name_no_namespace
local service_name="${image_name_no_namespace%%:*}-testing"
local user="testu" pass="testp" db="testdb"
local registry="" old_image="" pod_ip=""
@ -365,7 +364,7 @@ function test_postgresql_configmap_start() {
local image_name=$1; shift
local template="$TEMPLATES/postgresql-ephemeral-template.json"
local image_name_no_namespace=${image_name##*/}
local service_name=$image_name_no_namespace
local service_name="${image_name_no_namespace%%:*}-testing"
local user="testu" pass="testp" db="testdb"
local registry="" old_image="" pod_ip="" tmpdir=""
local test_string=""
@ -448,6 +447,19 @@ fi
echo "Running test_mariadb_imagestream"
test_postgresql_imagestream
function run_latest_imagestreams_test() {
local result=1
# Switch to root directory of a container
echo "Testing the latest version in imagestreams"
pushd "${THISDIR}/.." >/dev/null || return 1
ct_check_latest_imagestreams
result=$?
popd >/dev/null || return 1
return $result
}
run_latest_imagestreams_test
OS_TESTSUITE_RESULT=0
ct_os_cluster_down

View file

@ -16,13 +16,14 @@ set -eo nounset
trap ct_os_cleanup EXIT SIGINT
ct_os_set_ocp4
ct_os_check_compulsory_vars
oc status || false "It looks like oc is not properly logged in."
export CT_SKIP_NEW_PROJECT=true
export CT_SKIP_UPLOAD_IMAGE=true
export CT_NAMESPACE=openshift
# For testing on OpenShift 4 we use external registry
export CT_EXTERNAL_REGISTRY=true
# Check the template
test_postgresql_integration "${IMAGE_NAME}"

View file

@ -29,7 +29,6 @@ run_s2i_enable_ssl_test
run_upgrade_test
run_migration_test
run_pgaudit_test
run_latest_imagestreams_test
"
test $# -eq 1 -a "${1-}" == --list && echo "$TEST_LIST" && exit 0
@ -655,7 +654,7 @@ run_upgrade_test ()
# is fixed for non-SCL use cases
{ [ "${OS}" == "fedora" ] || [ "${OS}" == "rhel8" ]; } && return 0
local upgrade_path="none 9.2 9.4 9.5 9.6 10 12 none" prev= act=
local upgrade_path="none 9.2 9.4 9.5 9.6 10 12 13 none" prev= act=
for act in $upgrade_path; do
if test "$act" = $VERSION; then
break
@ -677,9 +676,9 @@ run_migration_test ()
local from_version
# Only test a subset of the migration path on non-intel hosts
if [ "$(uname -i)" == "x86_64" ]; then
local upgrade_path="9.2 9.4 9.5 9.6 10 12"
local upgrade_path="9.2 9.4 9.5 9.6 10 12 13"
else
local upgrade_path="10 12"
local upgrade_path="10 12 13"
fi
for from_version in $upgrade_path; do
@ -700,8 +699,8 @@ run_doc_test() {
for f in help.1 ; do
docker run --rm ${IMAGE_NAME} /bin/bash -c "cat /${f}" >${tmpdir}/$(basename ${f})
# Check whether the files include some important information
for term in "POSTGRESQL\_ADMIN\_PASSWORD" volume 5432 ; do
if ! cat ${tmpdir}/$(basename ${f}) | grep -F -q -e "${term}" ; then
for term in 'POSTGRESQL\\?_ADMIN\\?_PASSWORD' volume 5432 ; do
if ! cat ${tmpdir}/$(basename ${f}) | grep -E -q -e "${term}" ; then
echo "ERROR: File /${f} does not include '${term}'."
return 1
fi
@ -899,17 +898,6 @@ EOSQL"
grep -E 'AUDIT: SESSION,.*,.*,READ,SELECT,,,SELECT' "${data_dir}"/userdata/log/postgresql-*.log
}
function run_latest_imagestreams_test() {
local result=1
# Switch to root directory of a container
echo "Testing the latest version in imagestreams"
pushd "${test_dir}/.." >/dev/null || return 1
ct_check_latest_imagestreams
result=$?
popd >/dev/null || return 1
return $result
}
function run_all_tests() {
for test_case in $TEST_LIST; do
: "Running test $test_case"

View file

@ -8,8 +8,9 @@
THISDIR=$(dirname ${BASH_SOURCE[0]})
source ${THISDIR}/test-lib.sh
source ${THISDIR}/test-lib-openshift.sh
source "${THISDIR}"/test-lib.sh
source "${THISDIR}"/test-lib-openshift.sh
source "${THISDIR}"/test-lib-remote-openshift.sh
function test_postgresql_integration() {
local image_name=$1
@ -32,8 +33,11 @@ function test_postgresql_imagestream() {
rhel7|centos7) ;;
*) echo "Imagestream testing not supported for $OS environment." ; return 0 ;;
esac
ct_os_test_image_stream_template "${THISDIR}/../imagestreams/postgresql-${OS%[0-9]*}.json" "${THISDIR}/../examples/postgresql-ephemeral-template.json" postgresql "-p POSTGRESQL_VERSION=${VERSION}"
local tag="-el7"
if [ "${OS}" == "rhel8" ]; then
tag="-el8"
fi
ct_os_test_image_stream_template "${THISDIR}/../imagestreams/postgresql-${OS%[0-9]*}.json" "${THISDIR}/../examples/postgresql-ephemeral-template.json" postgresql "-p POSTGRESQL_VERSION=${VERSION}${tag}"
}
# vim: set tabstop=2:shiftwidth=2:expandtab:

View file

@ -0,0 +1,112 @@
# shellcheck shell=bash
# some functions are used from test-lib.sh, that is usually in the same dir
# shellcheck source=/dev/null
source "$(dirname "${BASH_SOURCE[0]}")"/test-lib.sh
# Set of functions for testing docker images in OpenShift using 'oc' command
# A variable containing the overall test result; must be changed to 0 in the end
# of the testing script:
# OS_TESTSUITE_RESULT=0
# And the following trap must be set, in the beginning of the test script:
# trap ct_os_cleanup EXIT SIGINT
# ct_os_set_path_oc_4 OC_VERSION
# --------------------
# This is a trick that helps using correct version 4 of the `oc`:
# The input is version of the openshift in format 4.4 etc.
# If the currently available version of oc is not of this version,
# it first takes a look into /usr/local/oc-<ver>/bin directory,
# Arguments: oc_version - X.Y part of the version of OSE (e.g. 3.9)
function ct_os_set_path_oc_4() {
echo "Setting OCP4 client"
local oc_version=$1
local installed_oc_path="/usr/local/oc-v${oc_version}/bin"
echo "PATH ${installed_oc_path}"
if [ -x "${installed_oc_path}/oc" ] ; then
oc_path="${installed_oc_path}"
echo "Binary oc found in ${installed_oc_path}" >&2
else
echo "OCP4 not found"
return 1
fi
export PATH="${oc_path}:${PATH}"
oc version
if ! oc version | grep -q "Client Version: ${oc_version}." ; then
echo "ERROR: something went wrong, oc located at ${oc_path}, but oc of version ${oc_version} not found in PATH ($PATH)" >&1
return 1
else
echo "PATH set correctly, binary oc found in version ${oc_version}: $(command -v oc)"
fi
}
# ct_os_prepare_ocp4
# ------------------
# Prepares environment for testing images in OpenShift 4 environment
#
#
function ct_os_set_ocp4() {
local login
OS_OC_CLIENT_VERSION=${OS_OC_CLIENT_VERSION:-4.4}
ct_os_set_path_oc_4 "${OS_OC_CLIENT_VERSION}"
oc version
login=$(cat "$KUBEPASSWORD")
oc login -u kubeadmin -p "$login"
echo "Login to OpenShift ${OS_OC_CLIENT_VERSION} is DONE"
# let openshift cluster to sync to avoid some race condition errors
sleep 3
}
function ct_os_upload_image_external_registry() {
local input_name="${1}" ; shift
local image_name=${input_name##*/}
local imagestream=${1:-$image_name:latest}
local output_name
ct_os_login_external_registry
output_name="${INTERNAL_DOCKER_REGISTRY}/rhscl-ci-testing/$imagestream"
docker images
docker tag "${input_name}" "${output_name}"
docker push "${output_name}"
}
function ct_os_login_external_registry() {
local docker_token
# docker login fails with "404 page not found" error sometimes, just try it more times
# shellcheck disable=SC2034
echo "loging"
[ -z "${INTERNAL_DOCKER_REGISTRY:-}" ] && "INTERNAL_DOCKER_REGISTRY has to be set for working with Internal registry" && return 1
# shellcheck disable=SC2034
for i in $(seq 12) ; do
# shellcheck disable=SC2015
docker_token=$(cat "$DOCKER_UPSHIFT_TOKEN")
# shellcheck disable=SC2015
docker login -u rhscl-ci-testing -p "$docker_token" "${INTERNAL_DOCKER_REGISTRY}" && return 0 || :
sleep 5
done
return 1
}
function ct_os_import_image_ocp4() {
local image_name="${1}"; shift
local imagestream=${1:-$image_name:latest}
local namespace
namespace=${CT_NAMESPACE:-"$(oc project -q)"}
deploy_image_name="${INTERNAL_DOCKER_REGISTRY}/rhscl-ci-testing/${imagestream}"
echo "Uploading image ${image_name} as ${deploy_image_name} , ${imagestream} into external registry."
ct_os_upload_image_external_registry "${image_name}" "${imagestream}"
if [ "${CT_TAG_IMAGE:-false}" == 'true' ]; then
echo "Tag ${deploy_image_name} to ${namespace}/${imagestream}"
oc tag --source=docker "${deploy_image_name}" "${namespace}/${imagestream}" --insecure=true --reference-policy=local
else
echo "Import image into OpenShift 4 environment ${namespace}/${imagestream} from ${deploy_image_name}"
oc import-image "${namespace}/${imagestream}" --from="${deploy_image_name}" --confirm --reference-policy=local
fi
}