Skip to content

Commit cf3eaea

Browse files
committed
Retry on pruner failures
1 parent 3495738 commit cf3eaea

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

pkg/resource/prunercronjob.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,18 @@ func (gcj *generatorPrunerCronJob) expected() (runtime.Object, error) {
8282
return nil, err
8383
}
8484

85+
script := `set -eu
86+
"$@" && exit
87+
for i in 1 2 3 4 5; do
88+
echo "attempt #$i has failed (exit code $?), going to make another attempt..." >&2
89+
sleep $(($i * 30))
90+
"$@" && break # this is the last command of the script, so its last failure will be exit code of the script
91+
done
92+
`
93+
8594
args := []string{
95+
"arg0", // value of $0, unused
96+
"oc",
8697
"adm",
8798
"prune",
8899
"images",
@@ -145,8 +156,8 @@ func (gcj *generatorPrunerCronJob) expected() (runtime.Object, error) {
145156
Resources: gcj.getResourceRequirements(cr),
146157
TerminationMessagePolicy: kcorev1.TerminationMessageFallbackToLogsOnError,
147158
Name: gcj.GetName(),
148-
Command: []string{"oc"},
149-
Args: args,
159+
Command: []string{"/bin/sh"},
160+
Args: append([]string{"-c", script}, args...),
150161
VolumeMounts: []kcorev1.VolumeMount{
151162
{
152163
Name: "serviceca",

0 commit comments

Comments
 (0)