Merge pull request #525 from sclorg/use_internal_openshift_registry

Use internal openshift registry
This commit is contained in:
phracek 2022-06-14 09:37:22 +00:00
commit 3e1d82ec39
12 changed files with 471 additions and 242 deletions

View file

@ -5,22 +5,23 @@ 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
# A variable containing the overall test result
# TESTSUITE_RESULT=0
# And the following trap must be set, in the beginning of the test script:
# trap ct_os_cleanup EXIT SIGINT
OS_TESTSUITE_RESULT=1
TESTSUITE_RESULT=0
OS_CLUSTER_STARTED_BY_TEST=0
function ct_os_cleanup() {
echo "${test_short_summary:-}"
if [ $OS_TESTSUITE_RESULT -eq 0 ] ; then
echo "${TEST_SUMMARY:-}"
if [ $TESTSUITE_RESULT -eq 0 ] ; then
# shellcheck disable=SC2153
echo "OpenShift tests for ${IMAGE_NAME} succeeded."
exit 0
else
# shellcheck disable=SC2153
echo "OpenShift tests for ${IMAGE_NAME} failed."
exit 1
fi
}
@ -45,6 +46,7 @@ function ct_os_check_compulsory_vars() {
function ct_os_get_status() {
oc get all
oc status
oc status --suggest
}
# ct_os_print_logs
@ -398,13 +400,13 @@ function ct_delete_all_objects() {
sleep 10
}
# ct_os_docker_login
# ct_os_docker_login_v3
# --------------------
# Logs in into docker daemon
# Uses global REGISRTY_ADDRESS environment variable for arbitrary registry address.
# Does not do anything if REGISTRY_ADDRESS is set.
function ct_os_docker_login() {
[ -n "${REGISTRY_ADDRESS:-}" ] && "REGISTRY_ADDRESS set, not trying to docker login." && return 0
function ct_os_docker_login_v3() {
[ -n "${REGISTRY_ADDRESS:-}" ] && echo "REGISTRY_ADDRESS set, not trying to docker login." && return 0
# docker login fails with "404 page not found" error sometimes, just try it more times
# shellcheck disable=SC2034
for i in $(seq 12) ; do
@ -415,6 +417,26 @@ function ct_os_docker_login() {
return 1
}
# ct_os_docker_login_v4
# --------------------
# Logs in into docker daemon
# Uses global REGISRTY_ADDRESS environment variable for arbitrary registry address.
# Does not do anything if REGISTRY_ADDRESS is set.
function ct_os_docker_login_v4() {
OCP4_REGISTER=$(oc get route default-route -n openshift-image-registry --template='{{ .spec.host }}')
echo "OCP4 loging address is $OCP4_REGISTER."
if [ -z "${OCP4_REGISTER}" ]; then
echo "!!!OpenShift 4 registry address not found. This is an error. Check OpenShift 4 cluster!!!"
return 1
fi
if docker login -u kubeadmin -p "$(oc whoami -t)" "${OCP4_REGISTER}"; then
echo "Login to $OCP4_REGISTER was successfully."
return 0
fi
return 1
}
# ct_os_upload_image IMAGE [IMAGESTREAM]
# --------------------
# Uploads image from local registry to the OpenShift internal registry.
@ -423,15 +445,35 @@ function ct_os_docker_login() {
# In the format of name:tag ($image_name:latest by default)
# Uses global REGISRTY_ADDRESS environment variable for arbitrary registry address.
function ct_os_upload_image() {
local os_version="${1}" ; shift
local input_name="${1}" ; shift
local image_name=${input_name##*/}
local imagestream=${1:-$image_name:latest}
local image_name=${1}
local output_name
local source_name
output_name="${REGISRTY_ADDRESS:-172.30.1.1:5000}/$(oc project -q)/$imagestream"
if [ "${os_version}" != "v3" ] && [ "${os_version}" != "v4" ]; then
echo "You have to specify OpenShift version to upload an image."
echo "Either 'v3' or 'v4' is allowed"
return 1
fi
ct_os_docker_login
docker tag "${input_name}" "${output_name}"
source_name="${input_name}"
if [ "${os_version}" == "v3" ]; then
output_name="${REGISRTY_ADDRESS:-172.30.1.1:5000}/$(oc project -q)/$image_name"
if ! ct_os_docker_login_v3; then
return 1
fi
fi
if [ "${os_version}" == "v4" ]; then
# Variable OCP4_REGISTER is set in function ct_os_docker_login_v4
if ! ct_os_docker_login_v4; then
return 1
fi
output_name="$OCP4_REGISTER/$namespace/$image_name"
fi
docker tag "${source_name}" "${output_name}"
docker push "${output_name}"
}
@ -673,8 +715,9 @@ function ct_os_test_s2i_app_func() {
local image_tagged="${image_name_no_namespace%:*}:${VERSION}"
if [ "${CVP:-0}" -eq "0" ]; then
if [ "${CT_EXTERNAL_REGISTRY:-false}" == 'true' ] ; then
ct_os_import_image_ocp4 "${image_name}" "${image_tagged}"
if [ "${CT_OCP4_TEST:-false}" == 'true' ] ; then
echo "Uploading image ${image_name} as ${image_tagged} into OpenShift internal registry."
ct_os_upload_image "v4" "${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
@ -685,7 +728,7 @@ function ct_os_test_s2i_app_func() {
ct_os_wait_stream_ready "${image_tagged}" "${namespace}"
else
echo "Uploading image ${image_name} as ${image_tagged}"
ct_os_upload_image "${image_name}" "${image_tagged}"
ct_os_upload_image "v3" "${image_name}" "${image_tagged}"
fi
fi
else
@ -817,8 +860,9 @@ function ct_os_test_template_app_func() {
# Upload main image is already done by CVP pipeline. No need to do it twice.
if [ "${CVP:-0}" -eq "0" ]; then
# Create a specific imagestream tag for the image so that oc cannot use anything else
if [ "${CT_EXTERNAL_REGISTRY:-false}" == 'true' ] ; then
ct_os_import_image_ocp4 "${image_name}" "${image_tagged}"
if [ "${CT_OCP4_TEST:-false}" == 'true' ] ; then
echo "Uploading image ${image_name} as ${image_tagged} into OpenShift internal registry."
ct_os_upload_image "v4" "${image_name}" "${image_tagged}"
else
if [ "${CT_SKIP_UPLOAD_IMAGE:-false}" == 'true' ] ; then
echo "Importing image ${image_name} as ${image_tagged}"
@ -828,7 +872,7 @@ function ct_os_test_template_app_func() {
ct_os_wait_stream_ready "${image_tagged}" "${namespace}"
else
echo "Uploading image ${image_name} as ${image_tagged}"
ct_os_upload_image "${image_name}" "${image_tagged}"
ct_os_upload_image "v3" "${image_name}" "${image_tagged}"
fi
fi
else
@ -850,10 +894,11 @@ function ct_os_test_template_app_func() {
exit 1
fi
if [ "${CT_EXTERNAL_REGISTRY:-false}" == 'true' ] ; then
ct_os_import_image_ocp4 "${image_tag_a[0]}" "${image_tag_a[1]}"
if [ "${CT_OCP4_TEST:-false}" == 'true' ] ; then
echo "Uploading image ${image_tag_a[0]} as ${image_tag_a[1]} into OpenShift internal registry."
ct_os_upload_image "v4" "${image_tag_a[0]}" "${image_tag_a[1]}"
else
ct_os_upload_image "${image_tag_a[0]}" "${image_tag_a[1]}"
ct_os_upload_image "v3" "${image_tag_a[0]}" "${image_tag_a[1]}"
fi
done
fi
@ -968,7 +1013,7 @@ ct_os_test_image_update() {
# Get current image from repository and create an imagestream
docker pull "$old_image:latest" 2>/dev/null
ct_os_upload_image "$old_image" "$istag"
ct_os_upload_image "v3" "$old_image" "$istag"
# Setup example application with curent image
oc new-app "$@" --name "$service_name"
@ -980,7 +1025,7 @@ ct_os_test_image_update() {
ct_assert_cmd_success "$check_command_exp"
# Tag built image into the imagestream and wait for rebuild
ct_os_upload_image "$image_name" "$istag"
ct_os_upload_image "v3" "$image_name" "$istag"
ct_os_wait_pod_ready "${service_name}-2" 60
# Check application output