Skip to content

Commit 5768d5f

Browse files
glyngharley
authored andcommitted
Introduce retry in function create
* Allow top level error to be recalculated after any changes to lower level conditions * This fixes projectriff#922
1 parent b47f880 commit 5768d5f

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

pkg/core/function.go

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,11 @@ func streamLogs(log io.Writer, controller kail.Controller, stopChan <-chan struc
290290
func (c *client) waitForSuccessOrFailure(namespace string, name string, gen int64, stopChan chan<- struct{}, errChan <-chan error, verbose bool) error {
291291
defer close(stopChan)
292292

293-
const sleepDuration = 500 * time.Millisecond
293+
const sleepDuration = time.Second
294294
const timeout = time.Minute
295295

296296
sleepTime := time.Duration(0)
297+
retry := true
297298
for i := 0; ; i++ {
298299
select {
299300
case err := <-errChan:
@@ -303,19 +304,27 @@ func (c *client) waitForSuccessOrFailure(namespace string, name string, gen int6
303304

304305
transientError, err := checkService(c, namespace, name, gen)
305306
if err != nil {
306-
return err
307-
}
308-
309-
if transientError == nil {
310-
return nil
311-
}
307+
/*
308+
A hard error appears to have been detected. This may be because the top level condition has not been
309+
recalculated since a lower level condition has cleared. Try again in case the hard error disappears.
310+
*/
311+
if retry {
312+
retry = false
313+
} else {
314+
return err
315+
}
316+
} else {
317+
if transientError == nil {
318+
return nil
319+
}
312320

313-
if verbose && i%4 == 0 {
314-
fmt.Printf("Waiting on function creation: %v\n", transientError)
315-
}
321+
if verbose && i%2 == 0 {
322+
fmt.Printf("Waiting on function creation: %v\n", transientError)
323+
}
316324

317-
if sleepTime > timeout {
318-
return transientError
325+
if sleepTime > timeout {
326+
return transientError
327+
}
319328
}
320329

321330
time.Sleep(sleepDuration)
@@ -349,15 +358,15 @@ func checkService(c *client, namespace string, name string, gen int64) (transien
349358
case corev1.ConditionTrue:
350359
return nil, nil
351360
case corev1.ConditionFalse:
352-
conds, message, err := c.serviceConditionsWithMessage(serviceStatusOptions, cond)
353-
if err == nil {
361+
conds, message := c.serviceConditionsWithMessage(serviceStatusOptions, cond)
362+
if conds != nil {
354363
if s := fetchTransientError(cond, conds); s != "" {
355364
return fmt.Errorf("%s: %s: %s", s, cond.Reason, message), nil
356365
}
357366
}
358367
return nil, fmt.Errorf("function creation failed: %s: %s", cond.Reason, message)
359368
default:
360-
_, message, _ := c.serviceConditionsWithMessage(serviceStatusOptions, cond)
369+
_, message := c.serviceConditionsWithMessage(serviceStatusOptions, cond)
361370
return fmt.Errorf("function creation incomplete: service status unknown: %s: %s", cond.Reason, message), nil
362371
}
363372
}
@@ -374,7 +383,7 @@ func fetchTransientError(cond *v1alpha1.ServiceCondition, conds []v1alpha1.Servi
374383
return ""
375384
}
376385

377-
func (c *client) serviceConditionsWithMessage(options ServiceStatusOptions, cond *v1alpha1.ServiceCondition) ([]v1alpha1.ServiceCondition, string, error) {
386+
func (c *client) serviceConditionsWithMessage(options ServiceStatusOptions, cond *v1alpha1.ServiceCondition) ([]v1alpha1.ServiceCondition, string) {
378387
conds, err := c.ServiceConditions(options)
379388
var message string
380389
if err != nil {
@@ -384,7 +393,7 @@ func (c *client) serviceConditionsWithMessage(options ServiceStatusOptions, cond
384393
message = serviceConditionsMessage(conds, cond.Message)
385394
}
386395

387-
return conds, message, err
396+
return conds, message
388397
}
389398

390399
func serviceConditionsMessage(conds []v1alpha1.ServiceCondition, primaryMessage string) string {

0 commit comments

Comments
 (0)