Skip to content

Commit

Permalink
Increase wait for Deployment timeout, support insecure Helm repos
Browse files Browse the repository at this point in the history
* Print help when incorrect options are given.
* Check for 'jq' and fail-fast if not installed.

Signed-off-by: Kyle Squizzato <[email protected]>
  • Loading branch information
squizzi committed Nov 5, 2024
1 parent 12ff062 commit e1cdd25
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
61 changes: 39 additions & 22 deletions scripts/airgap-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ HELP=""
EXTENSION_TARBALL_PREFIX="hmc-extension-images"
WORK_DIR="$(pwd)/hmc-airgap"

# Print the help message
function print_help() {
echo "Usage:"
echo " airgap-push.sh [OPTIONS]"
echo "Ensure repositories are logged into via 'helm' and 'docker' before running this script."
echo "Options:"
echo " -h, --help"
echo " Print this help message"
echo " -r, --image-repo (required)"
echo " The image repo to push the images to"
echo " -c, --chart-repo (required)"
echo " The repository to push the Helm charts to, for OCI prefix use oci://"
echo " -i, --insecure-registry"
echo " Use insecure registry for pushing Helm charts"
echo " -a, --airgap-bundle (required)"
echo " The path to the airgap bundle"
}

function ctrl_c() {
echo "Caught CTRL-C, exiting..."
exit 1
}

trap ctrl_c INT

# Parse the options
Expand All @@ -45,38 +68,23 @@ while [[ $# -gt 0 ]]; do
shift
shift
;;
-i|--insecure-registry)
INSECURE_REGISTRY="true"
shift
;;
-a|--airgap-bundle)
AIRGAP_BUNDLE="$2"
shift
shift
;;
*)
echo "Unknown option: $1"
print_help
exit 1
;;
esac
done

# Print the help message
function print_help() {
echo "Usage:"
echo " airgap-push.sh [OPTIONS]"
echo "Ensure repositories are logged into via 'helm' and 'docker' before running this script."
echo "Options:"
echo " -h, --help"
echo " Print this help message"
echo " -r, --image-repo (required)"
echo " The image repo to push the images to"
echo " -c, --chart-repo (required)"
echo " The repository to push the Helm charts to, for OCI prefix use oci://"
echo " -a, --airgap-bundle (required)"
echo " The path to the airgap bundle"
}

function ctrl_c() {
echo "Caught CTRL-C, exiting..."
exit 1
}

if [ ! -z "$HELP" ]; then
print_help
Expand Down Expand Up @@ -106,6 +114,11 @@ else
fi
fi

if [ ! $(command -v jq) ]; then
echo "'jq' could not be found, install 'jq' to continue"
exit 1
fi

mkdir -p ${WORK_DIR}

# Extract extension images from the airgap bundle.
Expand Down Expand Up @@ -157,7 +170,7 @@ for image in $(cat ${WORK_DIR}/repositories | jq -r 'to_entries[] | .key'); do
done

# Extract all of the Helm charts from the airgap bundle.
echo "Extracting Helm charts from the airgap bundle..."
echo "Extracting Helm charts from airgap bundle: ${AIRGAP_BUNDLE}..."
tar -C ${WORK_DIR} -xf ${AIRGAP_BUNDLE} "charts"
if [ $? -ne 0 ]; then
echo "Failed to extract Helm charts from the airgap bundle"
Expand All @@ -166,8 +179,12 @@ fi

# Next, use Helm to push the charts to the given chart repository.
echo "Pushing Helm charts to ${CHART_REPO}..."
if [ ! -z "$INSECURE_REGISTRY" ]; then
insecure_registry_flag="--insecure-skip-tls-verify"
fi

for chart in $(find ${WORK_DIR}/charts -name "*.tgz"); do
helm push ${chart} ${CHART_REPO}
helm push ${insecure_registry_flag} ${chart} ${CHART_REPO}
if [ $? -ne 0 ]; then
echo "Failed to push Helm chart: ${chart}"
exit 1
Expand Down
4 changes: 2 additions & 2 deletions scripts/bundle-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ do

wait_for_deploy_exist "$LABEL_KEY=$label_value"

${KUBECTL} wait --for condition=available --timeout=2m deploy -l ${LABEL_KEY}=${label_value} -n ${NAMESPACE}
${KUBECTL} wait --for condition=available --timeout=10m deploy -l ${LABEL_KEY}=${label_value} -n ${NAMESPACE}
if [[ $? -ne 0 ]]; then
echo "Error: Cannot wait for Deployment: Deployment with ${LABEL_KEY}=${label_value} label not found"
echo "Error: Timed out waiting for available Deployment with ${LABEL_KEY}=${label_value} label"
exit 1
fi
done
Expand Down

0 comments on commit e1cdd25

Please sign in to comment.