Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add RELATED_IMAGES environment variables to operator.yaml on re…
Browse files Browse the repository at this point in the history
…lease

Signed-off-by: Anatolii Bazko <[email protected]>
tolusha committed Jul 8, 2021

Verified

This commit was signed with the committer’s verified signature.
primeos Michael Weiss
1 parent fc2b559 commit de1fa43
Showing 3 changed files with 45 additions and 28 deletions.
60 changes: 33 additions & 27 deletions olm/addDigests.sh
Original file line number Diff line number Diff line change
@@ -28,8 +28,8 @@ fi
command -v yq >/dev/null 2>&1 || { echo "yq is not installed. Aborting."; exit 1; }

usage () {
echo "Usage: $0 [-w WORKDIR] [-s CSV_FILE_PATH] -t [IMAGE_TAG] "
echo "Example: ./olm/addDigests.sh -w . -s 'deploy/olm-catalog/stable/eclipse-che-preview-openshift/manifests/che-operator.clusterserviceversion.yaml' -t 7.21.1"
echo "Usage: $0 [-w WORKDIR] [-s CSV_FILE_PATH] [-o OPERATOR_DEPLOYMENT_FILE_PATH] [-t IMAGE_TAG] "
echo "Example: ./olm/addDigests.sh -w . -s deploy/olm-catalog/stable/eclipse-che-preview-openshift/manifests/che-operator.clusterserviceversion.yaml -o deploy/operator.yaml -t 7.32.0"
}

if [[ $# -lt 1 ]]; then usage; exit; fi
@@ -38,35 +38,44 @@ while [[ "$#" -gt 0 ]]; do
case $1 in
'-w') BASE_DIR="$2"; shift 1;;
'-s') CSV_FILE="$2"; shift 1;;
'-o') OPERATOR_FILE="$2"; shift 1;;
'-t') IMAGE_TAG="$2"; shift 1;;
'-q') QUIET="-q"; shift 0;;
'--help'|'-h') usage; exit;;
esac
shift 1
done

if [[ ! ${CSV_FILE} ]] || [[ ! $IMAGE_TAG ]]; then usage; exit 1; fi
if [[ ! $IMAGE_TAG ]]; then usage; exit 1; fi

echo "CSV file: ${CSV_FILE}"
RELATED_IMAGE_PREFIX="RELATED_IMAGE_"

rm -Rf "${BASE_DIR}/generated/csv"
mkdir -p "${BASE_DIR}/generated/csv"

if [ -f "${CSV_FILE}" ];then
cp -pR "${CSV_FILE}" "${BASE_DIR}/generated/csv"
if [[ ${CSV_FILE} ]]; then
if [ ! -f "${CSV_FILE}" ]; then
echo "[ERROR] ${CSV_FILE} was not found"
exit 1
else
echo "[INFO] CSV file: ${CSV_FILE}"
fi
else
echo "[ERROR] ${CSV_FILE} was not found"
usage
exit 1
fi

if [[ ${OPERATOR_FILE} ]]; then
if [ ! -f "${OPERATOR_FILE}" ]; then
echo "[ERROR] ${OPERATOR_FILE} was not found"
exit 1
else
echo "[INFO] Operator deployment file: ${OPERATOR_FILE}"
fi
fi

RELATED_IMAGE_PREFIX="RELATED_IMAGE_"

# shellcheck source=buildDigestMap.sh
source "${SCRIPTS_DIR}/buildDigestMap.sh" -w "${BASE_DIR}" -t "${IMAGE_TAG}" -c "${CSV_FILE}" ${QUIET}

if [[ ! "${QUIET}" ]]; then cat "${BASE_DIR}"/generated/digests-mapping.txt; fi

CSV_FILE_COPY=${BASE_DIR}/generated/csv/$(basename ${CSV_FILE})

echo "[INFO] Generate digest update for CSV file ${CSV_FILE}"
RELATED_IMAGES=""
RELATED_IMAGES_ENV=""
@@ -107,21 +116,18 @@ do
RELATED_IMAGES="${RELATED_IMAGES}, ${RELATED_IMAGE}"
fi

sed -i -e "s;${source};${dest};" "${CSV_FILE_COPY}"
sed -i -e "s;${source};${dest};" "${CSV_FILE}"
done

mv "${CSV_FILE_COPY}" "${CSV_FILE_COPY}.old"
yq -rY "
( .spec.relatedImages ) += [${RELATED_IMAGES}] |
( .spec.install.spec.deployments[0].spec.template.spec.containers[0].env ) += [${RELATED_IMAGES_ENV}]
" "${CSV_FILE_COPY}.old" > "${CSV_FILE_COPY}"
sed -i "${CSV_FILE_COPY}" -r -e "s|tag: |# tag: |"
rm -f "${CSV_FILE_COPY}.old"
yq -riY "( .spec.relatedImages ) += [${RELATED_IMAGES}]" ${CSV_FILE}
yq -riY "( .spec.install.spec.deployments[0].spec.template.spec.containers[0].env ) += [${RELATED_IMAGES_ENV}]" ${CSV_FILE}
sed -i "${CSV_FILE}" -r -e "s|tag: |# tag: |"
echo -e "$(cat ${SCRIPTS_DIR}/license.txt)\n$(cat ${CSV_FILE})" > ${CSV_FILE}

# update original file with generated changes
mv "${CSV_FILE_COPY}" "${CSV_FILE}"
echo "[INFO] CSV updated: ${CSV_FILE}"


# cleanup
rm -fr "${BASE_DIR}/generated"
if [[ ${OPERATOR_FILE} ]]; then
yq -riY "( .spec.template.spec.containers[0].env ) += [${RELATED_IMAGES_ENV}]" ${OPERATOR_FILE}
echo -e "$(cat ${SCRIPTS_DIR}/license.txt)\n$(cat ${OPERATOR_FILE})" > ${OPERATOR_FILE}
echo "[INFO] Operator deployment file updated: ${OPERATOR_FILE}"
fi
10 changes: 10 additions & 0 deletions olm/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Copyright (c) 2019-2021 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
3 changes: 2 additions & 1 deletion olm/release-olm-files.sh
Original file line number Diff line number Diff line change
@@ -122,7 +122,8 @@ do

source ${BASE_DIR}/addDigests.sh -w ${BASE_DIR} \
-t "${RELEASE}" \
-s "${STABLE_BUNDLE_PATH}/manifests/che-operator.clusterserviceversion.yaml"
-s "${STABLE_BUNDLE_PATH}/manifests/che-operator.clusterserviceversion.yaml" \
-o "${OPERATOR_DIR}/deploy/operator.yaml"

popd || true

0 comments on commit de1fa43

Please sign in to comment.