File tree Expand file tree Collapse file tree 3 files changed +17
-29
lines changed
controllers/topology/cluster/scope Expand file tree Collapse file tree 3 files changed +17
-29
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import (
23
23
24
24
runtimecatalog "sigs.k8s.io/cluster-api/exp/runtime/catalog"
25
25
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
26
+ "sigs.k8s.io/cluster-api/util"
26
27
)
27
28
28
29
// HookResponseTracker is a helper to capture the responses of the various lifecycle hooks.
@@ -48,7 +49,7 @@ func (h *HookResponseTracker) AggregateRetryAfter() time.Duration {
48
49
res := int32 (0 )
49
50
for _ , resp := range h .responses {
50
51
if retryResponse , ok := resp .(runtimehooksv1.RetryResponseObject ); ok {
51
- res = lowestNonZeroRetryAfterSeconds (res , retryResponse .GetRetryAfterSeconds ())
52
+ res = util . LowestNonZeroInt32 (res , retryResponse .GetRetryAfterSeconds ())
52
53
}
53
54
}
54
55
return time .Duration (res ) * time .Second
@@ -74,16 +75,3 @@ func (h *HookResponseTracker) AggregateMessage() string {
74
75
}
75
76
return strings .Join (hookAndMessages , "; " )
76
77
}
77
-
78
- func lowestNonZeroRetryAfterSeconds (i , j int32 ) int32 {
79
- if i == 0 {
80
- return j
81
- }
82
- if j == 0 {
83
- return i
84
- }
85
- if i < j {
86
- return i
87
- }
88
- return j
89
- }
Original file line number Diff line number Diff line change @@ -263,7 +263,7 @@ func aggregateSuccessfulResponses(aggregatedResponse runtimehooksv1.ResponseObje
263
263
for _ , resp := range responses {
264
264
aggregatedRetryResponse , ok := aggregatedResponse .(runtimehooksv1.RetryResponseObject )
265
265
if ok {
266
- aggregatedRetryResponse .SetRetryAfterSeconds (lowestNonZeroRetryAfterSeconds (
266
+ aggregatedRetryResponse .SetRetryAfterSeconds (util . LowestNonZeroInt32 (
267
267
aggregatedRetryResponse .GetRetryAfterSeconds (),
268
268
resp .(runtimehooksv1.RetryResponseObject ).GetRetryAfterSeconds (),
269
269
))
@@ -275,20 +275,6 @@ func aggregateSuccessfulResponses(aggregatedResponse runtimehooksv1.ResponseObje
275
275
aggregatedResponse .SetMessage (strings .Join (messages , ", " ))
276
276
}
277
277
278
- // lowestNonZeroRetryAfterSeconds returns the lowest non-zero value of the two provided values.
279
- func lowestNonZeroRetryAfterSeconds (i , j int32 ) int32 {
280
- if i == 0 {
281
- return j
282
- }
283
- if j == 0 {
284
- return i
285
- }
286
- if i < j {
287
- return i
288
- }
289
- return j
290
- }
291
-
292
278
// CallExtension makes the call to the extension with the given name.
293
279
// The response object passed will be updated with the response of the call.
294
280
// An error is returned if the extension is not compatible with the hook.
Original file line number Diff line number Diff line change @@ -593,6 +593,20 @@ func LowestNonZeroResult(i, j ctrl.Result) ctrl.Result {
593
593
}
594
594
}
595
595
596
+ // LowestNonZeroInt32 returns the lowest non-zero value of the two provided values.
597
+ func LowestNonZeroInt32 (i , j int32 ) int32 {
598
+ if i == 0 {
599
+ return j
600
+ }
601
+ if j == 0 {
602
+ return i
603
+ }
604
+ if i < j {
605
+ return i
606
+ }
607
+ return j
608
+ }
609
+
596
610
// IsNil returns an error if the passed interface is equal to nil or if it has an interface value of nil.
597
611
func IsNil (i interface {}) bool {
598
612
if i == nil {
You can’t perform that action at this time.
0 commit comments