Skip to content

Commit 571d66a

Browse files
Merge pull request #5990 from ggiguash/retry-observability-image-pull
USHIFT-6431: Retry Loki and Prometheus image pull
2 parents 20c1b77 + 49dbc2e commit 571d66a

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

scripts/pull_retry.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
#!/bin/bash
2-
set -xuo pipefail
2+
set -euo pipefail
3+
set -x
34
#
45
# Use this script to avoid image pull getting stuck once MicroShift tries to
56
# do so in runtime.
67
#
8+
PULL_CMD=${PULL_CMD:-"sudo crictl pull"}
79

810
function pull_image() {
911
local -r image=$1
1012
local rc=0
1113
for _ in $(seq 3); do
12-
timeout 5m sudo crictl pull "${image}" && return
14+
# shellcheck disable=SC2086
15+
timeout 5m ${PULL_CMD} "${image}" && return
1316
rc=$?
1417
sleep 1
1518
done

test/bin/manage_loki.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
99
# shellcheck source=test/bin/common.sh
1010
source "${SCRIPTDIR}/common.sh"
1111

12+
LOKI_IMAGE="docker.io/grafana/loki"
1213
DEFAULT_HOST_PORT="3100"
1314

1415
usage() {
@@ -38,14 +39,17 @@ action_start() {
3839
local host_port="${1:-${DEFAULT_HOST_PORT}}"
3940
local container_name="loki"
4041

42+
# Prefetch the image with retries
43+
PULL_CMD="podman pull" "${SCRIPTDIR}/../../scripts/pull_retry.sh" "${LOKI_IMAGE}"
44+
4145
echo "Stopping previous instance of Loki container ${container_name} (if any)"
4246
action_stop "${host_port}"
4347

4448
echo "Starting Loki container ${container_name} on host port ${host_port}"
4549
podman run -d --rm --name "${container_name}" \
4650
-p "${host_port}:3100" \
4751
--user root \
48-
docker.io/grafana/loki > /dev/null
52+
"${LOKI_IMAGE}" > /dev/null
4953
}
5054

5155
if [ $# -eq 0 ]; then

test/bin/manage_prometheus.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1010
source "${SCRIPTDIR}/common.sh"
1111

1212
PROMETHEUS_DIR="${IMAGEDIR}/prometheus"
13+
PROMETHEUS_IMAGE="quay.io/prometheus/prometheus"
1314
DEFAULT_HOST_PORT="9091"
1415

1516
usage() {
@@ -40,6 +41,9 @@ action_start() {
4041
local host_port="${1:-${DEFAULT_HOST_PORT}}"
4142
local container_name="prometheus"
4243

44+
# Prefetch the image with retries
45+
PULL_CMD="podman pull" "${SCRIPTDIR}/../../scripts/pull_retry.sh" "${PROMETHEUS_IMAGE}"
46+
4347
mkdir -p "${PROMETHEUS_DIR}"
4448
PROM_CONFIG="${PROMETHEUS_DIR}/prometheus.yml"
4549
# Empty configuration file will take all defaults.
@@ -54,7 +58,7 @@ action_start() {
5458
podman run -d --rm --name "${container_name}" \
5559
-p "${host_port}:9090" \
5660
-v "${PROMETHEUS_DIR}:/etc/prometheus:Z" \
57-
quay.io/prometheus/prometheus \
61+
"${PROMETHEUS_IMAGE}" \
5862
--config.file=/etc/prometheus/prometheus.yml \
5963
--web.enable-remote-write-receiver > /dev/null
6064
}

0 commit comments

Comments
 (0)