|
| 1 | +#!/usr/bin/env bash |
| 2 | +# This script is used to test the embed capability of helmvm. It will pull the memcached helm chart and |
| 3 | +# embed it into the binary, issuing then a single node install. This script waits for the memcached pod |
| 4 | +# to be ready. |
| 5 | +set -euo pipefail |
| 6 | + |
| 7 | +wait_for_healthy_node() { |
| 8 | + ready=$(kubectl get nodes | grep -v NotReady | grep -c Ready || true) |
| 9 | + counter=0 |
| 10 | + while [ -z "$ready" ] || [ "$ready" -lt "1" ]; do |
| 11 | + if [ "$counter" -gt 36 ]; then |
| 12 | + return 1 |
| 13 | + fi |
| 14 | + sleep 5 |
| 15 | + counter=$((counter+1)) |
| 16 | + echo "Waiting for node to be ready" |
| 17 | + ready=$(kubectl get nodes | grep -v NotReady | grep -c Ready || true) |
| 18 | + kubectl get nodes || true |
| 19 | + done |
| 20 | + return 0 |
| 21 | +} |
| 22 | + |
| 23 | +install_helm() { |
| 24 | + apt update -y |
| 25 | + if ! apt install -y curl ; then |
| 26 | + return 1 |
| 27 | + fi |
| 28 | + if ! curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 ; then |
| 29 | + return 1 |
| 30 | + fi |
| 31 | + chmod 700 get_helm.sh |
| 32 | + if ! ./get_helm.sh ; then |
| 33 | + return 1 |
| 34 | + fi |
| 35 | + return 0 |
| 36 | +} |
| 37 | + |
| 38 | +pull_helm_chart() { |
| 39 | + mkdir chart |
| 40 | + if ! helm pull oci://registry-1.docker.io/bitnamicharts/memcached --destination chart; then |
| 41 | + return 1 |
| 42 | + fi |
| 43 | + return 0 |
| 44 | +} |
| 45 | + |
| 46 | +embed_helm_chart() { |
| 47 | + fpath=$(ls -d chart/*) |
| 48 | + if ! helmvm embed --chart "$fpath" --output helmvm; then |
| 49 | + return 1 |
| 50 | + fi |
| 51 | + mv helmvm /usr/local/bin |
| 52 | + return 0 |
| 53 | +} |
| 54 | + |
| 55 | +wait_for_memcached_pods() { |
| 56 | + ready=$(kubectl get pods -n helmvm | grep -v NotReady | grep Ready | grep -c memcached || true) |
| 57 | + counter=0 |
| 58 | + while [ -z "$ready" ] || [ "$ready" -lt "1" ]; do |
| 59 | + if [ "$counter" -gt 36 ]; then |
| 60 | + return 1 |
| 61 | + fi |
| 62 | + sleep 5 |
| 63 | + counter=$((counter+1)) |
| 64 | + echo "Waiting for memcached pods to be ready" |
| 65 | + ready=$(kubectl get pods -n helmvm | grep Running | grep -c memcached || true) |
| 66 | + kubectl get pods -n helmvm 2>&1 || true |
| 67 | + echo "$ready" |
| 68 | + done |
| 69 | + return 0 |
| 70 | +} |
| 71 | + |
| 72 | +main() { |
| 73 | + if ! install_helm ; then |
| 74 | + echo "Failed to install helm" |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | + if ! pull_helm_chart ; then |
| 78 | + echo "Failed to pull helm chart" |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | + if ! embed_helm_chart ; then |
| 82 | + echo "Failed to embed helm chart" |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | + if ! helmvm install --no-prompt --addons-only 2>&1 | tee /tmp/log ; then |
| 86 | + echo "Failed to install addons" |
| 87 | + exit 1 |
| 88 | + fi |
| 89 | + if ! grep -q "You can now access your cluster" /tmp/log; then |
| 90 | + echo "Failed to install helmvm" |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | + echo "waiting for nodes" >> /tmp/log |
| 94 | + if ! wait_for_healthy_node; then |
| 95 | + echo "Nodes not reporting healthy" |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | + echo "waiting for memcached " >> /tmp/log |
| 99 | + if ! wait_for_memcached_pods; then |
| 100 | + echo "Memcached pods not reporting healthy" |
| 101 | + exit 1 |
| 102 | + fi |
| 103 | +} |
| 104 | + |
| 105 | +export KUBECONFIG=/root/.helmvm/etc/kubeconfig |
| 106 | +export PATH="$PATH:/root/.helmvm/bin" |
| 107 | +main |
0 commit comments