|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# "Fork" the local chart into a separate location and build the container images and the plugin binary |
| 4 | +# with a given TAG (or figures out the tag using $SCRIPT_DIR/build-upgrade-images.sh). |
| 5 | +# This is used by the upgrade test |
| 6 | + |
| 7 | +SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]:-"$0"}")")" |
| 8 | +ROOT_DIR="$SCRIPT_DIR/../.." |
| 9 | + |
| 10 | +# Imports |
| 11 | +source "$ROOT_DIR"/scripts/utils/log.sh |
| 12 | + |
| 13 | +set -euo pipefail |
| 14 | + |
| 15 | +TAG= |
| 16 | +CHART_VNEXT= |
| 17 | +CHART="$ROOT_DIR/chart" |
| 18 | +CHART_FORK="false" |
| 19 | +IMAGE_BUILD="false" |
| 20 | +IMAGE_LOAD="false" |
| 21 | + |
| 22 | +# Print usage options for this script. |
| 23 | +print_help() { |
| 24 | + cat <<EOF |
| 25 | +Usage: $(basename "${0}") [OPTIONS] |
| 26 | +
|
| 27 | +Options: |
| 28 | + -h, --help Display this text. |
| 29 | + --tag <tag> The tag for the vnext chart. |
| 30 | + Default: Automatically figured out. |
| 31 | + --chart <path> The path where the chart will be copied to and modified for the vnext tag. |
| 32 | + Default: \$workspace_root/tests/python/chart_vnext. |
| 33 | + --fork Forks the vnext chart from "$CHART" into CHART_VNEXT. |
| 34 | + --build Builds the container images and the plugin binary. |
| 35 | + --load Loads the images into the kind cluster. |
| 36 | +
|
| 37 | +Examples: |
| 38 | + $(basename "${0}") --fork |
| 39 | +
|
| 40 | +The kubectl-mayastor binary will be built at CHART_VNEXT/kubectl-plugin/bin/kubectl-mayastor |
| 41 | +EOF |
| 42 | +} |
| 43 | + |
| 44 | +# Parse args. |
| 45 | +while test $# -gt 0; do |
| 46 | + arg="$1" |
| 47 | + case "$arg" in |
| 48 | + --tag) |
| 49 | + TAG="$1" |
| 50 | + ;; |
| 51 | + --chart) |
| 52 | + CHART_VNEXT="$1" |
| 53 | + ;; |
| 54 | + --fork) |
| 55 | + CHART_FORK="true" |
| 56 | + ;; |
| 57 | + --build) |
| 58 | + IMAGE_BUILD="true" |
| 59 | + ;; |
| 60 | + --load) |
| 61 | + IMAGE_LOAD="true" |
| 62 | + ;; |
| 63 | + -h* | --help*) |
| 64 | + print_help |
| 65 | + exit 0 |
| 66 | + ;; |
| 67 | + *) |
| 68 | + print_help |
| 69 | + log_fatal "unexpected argument '$arg'" 1 |
| 70 | + ;; |
| 71 | + esac |
| 72 | + shift |
| 73 | +done |
| 74 | + |
| 75 | +if [ "$(kubectl config current-context)" != "kind-kind" ]; then |
| 76 | + log_fatal "Only Supported on Kind Clusters!" |
| 77 | +fi |
| 78 | + |
| 79 | +if [ -z "$TAG" ]; then |
| 80 | + TAG="$("$SCRIPT_DIR"/generate-test-tag.sh)" |
| 81 | +fi |
| 82 | + |
| 83 | +if [ -z "$CHART_VNEXT" ]; then |
| 84 | + CHART_VNEXT="$ROOT_DIR/tests/bdd/chart-vnext" |
| 85 | +fi |
| 86 | +KUBECTL_MAYASTOR="$CHART_VNEXT/kubectl-plugin/bin/kubectl-mayastor" |
| 87 | + |
| 88 | +# Ensure the chart vnext is created, copied from the original |
| 89 | +if [ "$CHART_FORK" = "true" ]; then |
| 90 | + mkdir -p "$CHART_VNEXT" |
| 91 | + rm -r "${CHART_VNEXT:?}"/* |
| 92 | + cp -r "$CHART/." "${CHART_VNEXT:?}" |
| 93 | + |
| 94 | + # Tag the vnext chart |
| 95 | + CHART_DIR="$CHART_VNEXT" "$SCRIPT_DIR"/tag-chart.sh "$TAG" |
| 96 | +fi |
| 97 | + |
| 98 | +# Build the vnext images and kubectl-binary (in debug mode) |
| 99 | +if [ "$IMAGE_BUILD" = "true" ]; then |
| 100 | + RUSTFLAGS="-C debuginfo=0 -C strip=debuginfo" "$ROOT_DIR"/scripts/release.sh --tag "$TAG" --build-binary-out "$CHART_VNEXT" --no-static-linking --skip-publish --debug |
| 101 | + |
| 102 | + # Ensure binary is on the correct version |
| 103 | + PLUGIN_VERSION="$($KUBECTL_MAYASTOR --version)" |
| 104 | + if [[ ! "$PLUGIN_VERSION" =~ ^Kubectl\ Plugin\ \(kubectl-mayastor\).*\($TAG\+0\)$ ]]; then |
| 105 | + log_fatal "The built kubectl-plugin reports version $PLUGIN_VERSION but we want $TAG" |
| 106 | + fi |
| 107 | +fi |
| 108 | + |
| 109 | +# Load the images into the kind cluster |
| 110 | +if [ "$IMAGE_LOAD" = "true" ]; then |
| 111 | + "$ROOT_DIR"/scripts/k8s/load-images-to-kind.sh --tag "$TAG" --trim-debug-suffix |
| 112 | +fi |
0 commit comments