-
Notifications
You must be signed in to change notification settings - Fork 53
/
requeue.go
65 lines (55 loc) · 1006 Bytes
/
requeue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package util
import (
"time"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)
type RequeueOp struct {
res ctrl.Result
err error
}
func LoadResult(result *reconcile.Result, err error) RequeueOp {
if err != nil {
return RequeueErr(err)
}
if result != nil {
return RequeueOp{
res: *result,
}
}
return RequeueOp{}
}
func DoNotRequeue() RequeueOp {
return RequeueOp{
res: ctrl.Result{
Requeue: false,
},
}
}
func Requeue() RequeueOp {
return RequeueOp{
res: reconcile.Result{
Requeue: true,
},
}
}
func RequeueAfter(d time.Duration) RequeueOp {
return RequeueOp{
res: reconcile.Result{
Requeue: true,
RequeueAfter: d,
},
}
}
func RequeueErr(err error) RequeueOp {
return RequeueOp{
res: reconcile.Result{},
err: err,
}
}
func (r RequeueOp) ShouldRequeue() bool {
return r.res.Requeue || r.res.RequeueAfter > 0 || r.err != nil
}
func (r RequeueOp) Result() (ctrl.Result, error) {
return r.res, r.err
}