Skip to content

Commit c137356

Browse files
authored
Merge pull request #606 from Shunpoco/implement-downloader-retry
Implement retry logic on downloader
2 parents c673712 + e71016b commit c137356

5 files changed

Lines changed: 58 additions & 2 deletions

File tree

.github/workflows/helm-chart-smoketest.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ jobs:
151151
--set rcm.nodeInstallerImage.tag=chart-test \
152152
--set rcm.shimDownloaderImage.repository=shim-downloader \
153153
--set rcm.shimDownloaderImage.tag=chart-test \
154+
--set rcm.shimDownloaderConfig.configMapName=configmap-test \
155+
--set rcm.shimDownloaderConfig.content.numRetry=5 \
156+
--set rcm.shimDownloaderConfig.content.sleepDuration=3 \
154157
deploy/helm
155158
156159
- name: apply Spin shim
@@ -174,6 +177,10 @@ jobs:
174177
run: |
175178
timeout 60s bash -c 'until [[ "$(kubectl -n rcm get $(kubectl get pods -n rcm --no-headers -o name | grep install | head -n1) -o jsonpath="{.status.phase}" 2>/dev/null)" == "Succeeded" ]]; do sleep 2; done'
176179
180+
- name: verify configMap for shim-downloader is added
181+
run: |
182+
timeout 60s bash -c 'until [[ $(kubectl -n rcm get $(kubectl get pods -n rcm --no-headers -o name | grep install | head -n1) -o jsonpath="{.spec.initContainers[0].envFrom[0].configMapRef.name}" 2>/dev/null) == "configmap-test" ]]; do sleep 2; done'
183+
177184
- name: run Spin App
178185
run: |
179186
kubectl apply -f testdata/apps/spin-app.yaml

deploy/helm/templates/deployment.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ spec:
4949
value: "{{ .Values.rcm.nodeInstallerImage.repository }}:{{ .Values.rcm.nodeInstallerImage.tag | default .Chart.AppVersion }}"
5050
- name: SHIM_NODE_INSTALLER_JOB_TTL
5151
value: "{{ .Values.rcm.nodeInstallerJob.ttl | default 0 }}"
52+
{{- if .Values.rcm.shimDownloaderConfig }}
53+
- name: SHIM_DOWNLOADER_CONFIG_MAP
54+
value: "{{ .Values.rcm.shimDownloaderConfig.configMapName }}"
55+
{{- end }}
5256
ports:
5357
- name: http
5458
containerPort: {{ .Values.service.port }}
@@ -79,3 +83,13 @@ spec:
7983
tolerations:
8084
{{- toYaml . | nindent 8 }}
8185
{{- end }}
86+
{{- if .Values.rcm.shimDownloaderConfig }}
87+
---
88+
apiVersion: v1
89+
kind: ConfigMap
90+
metadata:
91+
name: {{ .Values.rcm.shimDownloaderConfig.configMapName }}
92+
data:
93+
NUM_RETRY: "{{ .Values.rcm.shimDownloaderConfig.content.numRetry | default 3 }}"
94+
SLEEP_DURATION: "{{ .Values.rcm.shimDownloaderConfig.content.sleepDuration | default 2 }}"
95+
{{- end }}

deploy/helm/values.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ rcm:
2020
nodeInstallerJob:
2121
ttl: 0
2222
leaderElectEnabled: false
23+
# shimDownloaderConfig generates a ConfigMap which sets a downloader container's variables. Since those variables have defaults, you don't need to enable it unless you want to customize them.
24+
# shimDownloaderConfig:
25+
# configMapName: shim-downloader-config
26+
# content:
27+
# numRetry: 3
28+
# sleepDuration: 2
2329

2430
imagePullSecrets: []
2531
nameOverride: ""

images/downloader/download_shim.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,27 @@ log "start downloading shim from ${SHIM_LOCATION}..." "INFO"
2323

2424
mkdir -p /assets
2525

26+
num_retry=${NUM_RETRY:-3}
27+
sleep_duration=${SLEEP_DURATION:-2}
28+
29+
for (( i=0; i < $num_retry+1; i++ ))
30+
do
31+
if curl -sLo "containerd-shim-${SHIM_NAME}" "${SHIM_LOCATION}"
32+
then
33+
ls -lah "containerd-shim-${SHIM_NAME}"
34+
break
35+
elif [ $i -eq $num_retry ]
36+
then
37+
log "number of failed downloads reached max retry ${num_retry}" "ERROR"
38+
exit 1
39+
else
40+
log "download failed. retry after sleep... (${i}/${num_retry})" "ERROR"
41+
sleep $sleep_duration
42+
fi
43+
done
44+
2645
# overwrite default name of shim binary; use the name of shim resource instead
2746
# to enable installing multiple versions of the same shim
28-
curl -sLo "containerd-shim-${SHIM_NAME}" "${SHIM_LOCATION}"
29-
ls -lah "containerd-shim-${SHIM_NAME}"
3047

3148
log "$(curl --version)" "INFO"
3249
log "$(tar --version)" "INFO"

internal/controller/shim_controller.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,18 @@ func (sr *ShimReconciler) setOperationConfiguration(shim *rcmv1.Shim, opConfig *
434434
},
435435
},
436436
}}
437+
if configMapName := os.Getenv("SHIM_DOWNLOADER_CONFIG_MAP"); configMapName != "" {
438+
opConfig.initContainer[0].EnvFrom = []corev1.EnvFromSource{
439+
{
440+
ConfigMapRef: &corev1.ConfigMapEnvSource{
441+
LocalObjectReference: corev1.LocalObjectReference{
442+
Name: configMapName,
443+
},
444+
},
445+
},
446+
}
447+
}
448+
437449
opConfig.args = []string{
438450
"install",
439451
"-H",

0 commit comments

Comments
 (0)