|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -o errexit |
| 4 | +set -o nounset |
| 5 | +set -o pipefail |
| 6 | + |
| 7 | +################################################## |
| 8 | +# You shouldn't need to change anything below here |
| 9 | +################################################## |
| 10 | + |
| 11 | +# Know where the repo root is so we can reference things relative to it |
| 12 | +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" |
| 13 | + |
| 14 | +# Source bingo so we can use kustomize and yq |
| 15 | +. "${REPO_ROOT}/openshift/.bingo/variables.env" |
| 16 | + |
| 17 | +# This function generates the manifests |
| 18 | +generate () { |
| 19 | + values=() |
| 20 | + OUTPUT_DIR="" |
| 21 | + local OPTIND |
| 22 | + while getopts "v:o:n:c:i:" arg; do |
| 23 | + case ${arg} in |
| 24 | + v) |
| 25 | + values+=(${OPTARG}) |
| 26 | + ;; |
| 27 | + o) |
| 28 | + OUTPUT_DIR=${OPTARG} |
| 29 | + ;; |
| 30 | + *) |
| 31 | + echo "bad argument ${arg}" |
| 32 | + exit 1 |
| 33 | + ;; |
| 34 | + esac |
| 35 | + done |
| 36 | + |
| 37 | + DOWNSTREAM="${REPO_ROOT}/openshift/helm" |
| 38 | + |
| 39 | + VALUES="" |
| 40 | + for i in "${values[@]}"; do |
| 41 | + VALUES="${VALUES} --values ${DOWNSTREAM}/${i}" |
| 42 | + done |
| 43 | + |
| 44 | + # We're going to do file manipulation, so let's work in a temp dir |
| 45 | + TMP_ROOT="$(mktemp -p . -d 2>/dev/null || mktemp -d ./tmpdir.XXXXXXX)" |
| 46 | + # Make sure to delete the temp dir when we exit |
| 47 | + trap 'rm -rf $TMP_ROOT' EXIT |
| 48 | + |
| 49 | + # Copy upstream chart to temp |
| 50 | + cp -a "${REPO_ROOT}/helm" "${TMP_ROOT}/helm" |
| 51 | + |
| 52 | + # Create a temp dir for manifests |
| 53 | + TMP_MANIFEST_DIR="${TMP_ROOT}/manifests" |
| 54 | + mkdir -p "$TMP_MANIFEST_DIR" |
| 55 | + |
| 56 | + # Run helm template, which emits a single yaml file |
| 57 | + TMP_HELM_OUTPUT="${TMP_MANIFEST_DIR}/temp.yaml" |
| 58 | + ${HELM} template olmv1 "${TMP_ROOT}/helm/olmv1" ${VALUES} > "${TMP_HELM_OUTPUT}" |
| 59 | + |
| 60 | + # Use yq to split the single yaml file into 1 per document. |
| 61 | + # Naming convention: $index-$kind-$namespace-$name. If $namespace is empty, just use the empty string. |
| 62 | + ( |
| 63 | + cd "$TMP_MANIFEST_DIR" |
| 64 | + |
| 65 | + # shellcheck disable=SC2016 |
| 66 | + ${YQ} -s '$index +"-"+ (.kind|downcase) +"-"+ (.metadata.namespace // "") +"-"+ .metadata.name' temp.yaml |
| 67 | + ) |
| 68 | + |
| 69 | + # Delete the single yaml file |
| 70 | + rm "${TMP_HELM_OUTPUT}" |
| 71 | + |
| 72 | + # Delete and recreate the actual manifests directory |
| 73 | + MANIFEST_DIR="${REPO_ROOT}/openshift/${OUTPUT_DIR}" |
| 74 | + rm -rf "${MANIFEST_DIR}" |
| 75 | + mkdir -p "${MANIFEST_DIR}" |
| 76 | + |
| 77 | + # Copy everything we just generated and split into the actual manifests directory |
| 78 | + cp "$TMP_MANIFEST_DIR"/* "$MANIFEST_DIR"/ |
| 79 | + |
| 80 | + # Update file names to be in the format nn-$kind-$namespace-$name |
| 81 | + ( |
| 82 | + cd "$MANIFEST_DIR" |
| 83 | + |
| 84 | + for f in *; do |
| 85 | + # Get the numeric prefix from the filename |
| 86 | + index=$(echo "$f" | cut -d '-' -f 1) |
| 87 | + # Keep track of the full file name without the leading number and dash |
| 88 | + name_without_index=${f#$index-} |
| 89 | + # Fix the double dash in cluster-scoped names |
| 90 | + name_without_index=${name_without_index//--/-} |
| 91 | + # Reformat the name so the leading number is always padded to 2 digits |
| 92 | + new_name=$(printf "%02d" "$index")-$name_without_index |
| 93 | + # Some file names (namely CRDs) don't end in .yml - make them |
| 94 | + if ! [[ "$new_name" =~ yml$ ]]; then |
| 95 | + new_name="${new_name}".yml |
| 96 | + fi |
| 97 | + if [[ "$f" != "$new_name" ]]; then |
| 98 | + # Rename |
| 99 | + mv "$f" "${new_name}" |
| 100 | + fi |
| 101 | + done |
| 102 | + ) |
| 103 | + rm -rf "$TMP_ROOT" |
| 104 | +} |
| 105 | + |
| 106 | +#Generate the manifests |
| 107 | +generate -v operator-controller.yaml -o operator-controller/manifests |
| 108 | +generate -v operator-controller.yaml -v experimental.yaml -o operator-controller/manifests-experimental |
| 109 | +generate -v catalogd.yaml -o catalogd/manifests |
| 110 | +generate -v catalogd.yaml -v experimental.yaml -o catalogd/manifests-experimental |
0 commit comments